mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Codestyle
This commit is contained in:
parent
2cf82d1b0b
commit
9f13338c17
3 changed files with 26 additions and 22 deletions
|
@ -3,6 +3,7 @@ from UM.Application import Application
|
||||||
|
|
||||||
import LayerView
|
import LayerView
|
||||||
|
|
||||||
|
|
||||||
class LayerViewProxy(QObject):
|
class LayerViewProxy(QObject):
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
# Copyright (c) 2015 Ultimaker B.V.
|
# Copyright (c) 2015 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the AGPLv3 or higher.
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
import configparser #For reading the legacy profile INI files.
|
import configparser # For reading the legacy profile INI files.
|
||||||
import json #For reading the Dictionary of Doom.
|
import json # For reading the Dictionary of Doom.
|
||||||
import math #For mathematical operations included in the Dictionary of Doom.
|
import math # For mathematical operations included in the Dictionary of Doom.
|
||||||
import os.path #For concatenating the path to the plugin and the relative path to the Dictionary of Doom.
|
import os.path # For concatenating the path to the plugin and the relative path to the Dictionary of Doom.
|
||||||
|
|
||||||
|
from UM.Application import Application # To get the machine manager to create the new profile in.
|
||||||
|
from UM.Logger import Logger # Logging errors.
|
||||||
|
from UM.PluginRegistry import PluginRegistry # For getting the path to this plugin's directory.
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer # The new profile to make.
|
||||||
|
from cura.ProfileReader import ProfileReader # The plug-in type to implement.
|
||||||
|
|
||||||
from UM.Application import Application #To get the machine manager to create the new profile in.
|
|
||||||
from UM.Logger import Logger #Logging errors.
|
|
||||||
from UM.PluginRegistry import PluginRegistry #For getting the path to this plugin's directory.
|
|
||||||
from UM.Settings.DefinitionContainer import DefinitionContainer #For getting the current machine's defaults.
|
|
||||||
from UM.Settings.InstanceContainer import InstanceContainer #The new profile to make.
|
|
||||||
from cura.ProfileReader import ProfileReader #The plug-in type to implement.
|
|
||||||
|
|
||||||
## A plugin that reads profile data from legacy Cura versions.
|
## A plugin that reads profile data from legacy Cura versions.
|
||||||
#
|
#
|
||||||
|
@ -33,7 +33,7 @@ class LegacyProfileReader(ProfileReader):
|
||||||
# \return A dictionary of the default values of the legacy Cura version.
|
# \return A dictionary of the default values of the legacy Cura version.
|
||||||
def prepareDefaults(self, json):
|
def prepareDefaults(self, json):
|
||||||
defaults = {}
|
defaults = {}
|
||||||
for key in json["defaults"]: #We have to copy over all defaults from the JSON handle to a normal dict.
|
for key in json["defaults"]: # We have to copy over all defaults from the JSON handle to a normal dict.
|
||||||
defaults[key] = json["defaults"][key]
|
defaults[key] = json["defaults"][key]
|
||||||
return defaults
|
return defaults
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class LegacyProfileReader(ProfileReader):
|
||||||
# \return A set of local variables, one for each setting in the legacy
|
# \return A set of local variables, one for each setting in the legacy
|
||||||
# profile.
|
# profile.
|
||||||
def prepareLocals(self, config_parser, config_section, defaults):
|
def prepareLocals(self, config_parser, config_section, defaults):
|
||||||
copied_locals = defaults.copy() #Don't edit the original!
|
copied_locals = defaults.copy() # Don't edit the original!
|
||||||
for option in config_parser.options(config_section):
|
for option in config_parser.options(config_section):
|
||||||
copied_locals[option] = config_parser.get(config_section, option)
|
copied_locals[option] = config_parser.get(config_section, option)
|
||||||
return copied_locals
|
return copied_locals
|
||||||
|
@ -76,29 +76,29 @@ class LegacyProfileReader(ProfileReader):
|
||||||
raise Exception("Unable to import legacy profile. Multi extrusion is not supported")
|
raise Exception("Unable to import legacy profile. Multi extrusion is not supported")
|
||||||
|
|
||||||
Logger.log("i", "Importing legacy profile from file " + file_name + ".")
|
Logger.log("i", "Importing legacy profile from file " + file_name + ".")
|
||||||
profile = InstanceContainer("Imported Legacy Profile") # Create an empty profile.
|
profile = InstanceContainer("Imported Legacy Profile") # Create an empty profile.
|
||||||
|
|
||||||
parser = configparser.ConfigParser(interpolation = None)
|
parser = configparser.ConfigParser(interpolation = None)
|
||||||
try:
|
try:
|
||||||
with open(file_name) as f:
|
with open(file_name) as f:
|
||||||
parser.readfp(f) #Parse the INI file.
|
parser.readfp(f) # Parse the INI file.
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Logger.log("e", "Unable to open legacy profile %s: %s", file_name, str(e))
|
Logger.log("e", "Unable to open legacy profile %s: %s", file_name, str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#Legacy Cura saved the profile under the section "profile_N" where N is the ID of a machine, except when you export in which case it saves it in the section "profile".
|
# Legacy Cura saved the profile under the section "profile_N" where N is the ID of a machine, except when you export in which case it saves it in the section "profile".
|
||||||
#Since importing multiple machine profiles is out of scope, just import the first section we find.
|
# Since importing multiple machine profiles is out of scope, just import the first section we find.
|
||||||
section = ""
|
section = ""
|
||||||
for found_section in parser.sections():
|
for found_section in parser.sections():
|
||||||
if found_section.startswith("profile"):
|
if found_section.startswith("profile"):
|
||||||
section = found_section
|
section = found_section
|
||||||
break
|
break
|
||||||
if not section: #No section starting with "profile" was found. Probably not a proper INI file.
|
if not section: # No section starting with "profile" was found. Probably not a proper INI file.
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(PluginRegistry.getInstance().getPluginPath("LegacyProfileReader"), "DictionaryOfDoom.json"), "r", -1, "utf-8") as f:
|
with open(os.path.join(PluginRegistry.getInstance().getPluginPath("LegacyProfileReader"), "DictionaryOfDoom.json"), "r", -1, "utf-8") as f:
|
||||||
dict_of_doom = json.load(f) #Parse the Dictionary of Doom.
|
dict_of_doom = json.load(f) # Parse the Dictionary of Doom.
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
Logger.log("e", "Could not open DictionaryOfDoom.json for reading: %s", str(e))
|
Logger.log("e", "Could not open DictionaryOfDoom.json for reading: %s", str(e))
|
||||||
return None
|
return None
|
||||||
|
@ -122,13 +122,13 @@ class LegacyProfileReader(ProfileReader):
|
||||||
return None
|
return None
|
||||||
current_printer_definition = global_container_stack.getBottom()
|
current_printer_definition = global_container_stack.getBottom()
|
||||||
profile.setDefinition(current_printer_definition)
|
profile.setDefinition(current_printer_definition)
|
||||||
for new_setting in dict_of_doom["translation"]: #Evaluate all new settings that would get a value from the translations.
|
for new_setting in dict_of_doom["translation"]: # Evaluate all new settings that would get a value from the translations.
|
||||||
old_setting_expression = dict_of_doom["translation"][new_setting]
|
old_setting_expression = dict_of_doom["translation"][new_setting]
|
||||||
compiled = compile(old_setting_expression, new_setting, "eval")
|
compiled = compile(old_setting_expression, new_setting, "eval")
|
||||||
try:
|
try:
|
||||||
new_value = eval(compiled, {"math": math}, legacy_settings) #Pass the legacy settings as local variables to allow access to in the evaluation.
|
new_value = eval(compiled, {"math": math}, legacy_settings) # Pass the legacy settings as local variables to allow access to in the evaluation.
|
||||||
value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default.
|
value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default.
|
||||||
except Exception: #Probably some setting name that was missing or something else that went wrong in the ini file.
|
except Exception: # Probably some setting name that was missing or something else that went wrong in the ini file.
|
||||||
Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.")
|
Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.")
|
||||||
continue
|
continue
|
||||||
definitions = current_printer_definition.findDefinitions(key = new_setting)
|
definitions = current_printer_definition.findDefinitions(key = new_setting)
|
||||||
|
|
|
@ -14,6 +14,9 @@ import UM.Logger
|
||||||
import UM.i18n
|
import UM.i18n
|
||||||
catalog = UM.i18n.i18nCatalog("cura")
|
catalog = UM.i18n.i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
|
## This action allows for certain settings that are "machine only") to be modified.
|
||||||
|
# It automatically detects machine definitions that it knows how to change and attaches itself to those.
|
||||||
class MachineSettingsAction(MachineAction):
|
class MachineSettingsAction(MachineAction):
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue