Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGhostkeeper <ghost_keeper+github@hotmail.com>2015-12-15 14:48:41 +0300
committerGhostkeeper <ghost_keeper+github@hotmail.com>2015-12-17 15:35:16 +0300
commit065b954cad4227049f3becb0cd77a68799c94133 (patch)
tree801ee5c4ffcf267fb5145e8b9713338f7284b23e /plugins/GCodeProfileReader
parent1f35c25b80f79ccd2aa515f8892914934ee93e48 (diff)
GCodeProfileReader plugin properly returns a profile
Instead of setting the profile as the current profile, return the resulting profile. Contributes to issue CURA-34.
Diffstat (limited to 'plugins/GCodeProfileReader')
-rw-r--r--plugins/GCodeProfileReader/GCodeProfileReader.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py
index fd6a7152eb..507ceabc2a 100644
--- a/plugins/GCodeProfileReader/GCodeProfileReader.py
+++ b/plugins/GCodeProfileReader/GCodeProfileReader.py
@@ -2,6 +2,7 @@
# Cura is released under the terms of the AGPLv3 or higher.
from UM.Application import Application #To get the current profile that should be updated with the settings from the g-code.
+from UM.Settings.Profile import Profile
from UM.Settings.ProfileReader import ProfileReader
import re #Regular expressions for parsing escape characters in the settings.
@@ -29,6 +30,7 @@ class GCodeProfileReader(ProfileReader):
serialised += line[len(prefix):-1] #Remove the prefix and the newline from the line, and add it to the rest.
except IOError as e:
Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
+ return None
#Unescape the serialised profile.
escape_characters = { #Which special characters (keys) are replaced by what escape character (values).
@@ -42,5 +44,9 @@ class GCodeProfileReader(ProfileReader):
serialised = pattern.sub(lambda m: escape_characters[re.escape(m.group(0))], serialised) #Perform the replacement with a regular expression.
#Apply the changes to the current profile.
- profile = Application.getInstance().getMachineManager().getActiveProfile()
- profile.unserialise(serialised) \ No newline at end of file
+ profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False)
+ try:
+ profile.unserialise(serialised)
+ except Exception as e: #Not a valid g-code file.
+ return None
+ return profile \ No newline at end of file