diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 996e621c7a..9dba5f6335 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -150,9 +150,6 @@ class CuraApplication(QtApplication): parser.add_argument("--debug", dest="debug-mode", action="store_true", default=False, help="Enable detailed crash reports.") def run(self): - if "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" not in os.environ or os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] != "cpp": - Logger.log("w", "Using Python implementation of Protobuf, expect bad performance!") - self._i18n_catalog = i18nCatalog("cura"); i18nCatalog.setTagReplacements({ diff --git a/cura_app.py b/cura_app.py index 831582687c..e19147c5e5 100755 --- a/cura_app.py +++ b/cura_app.py @@ -12,15 +12,12 @@ def exceptHook(type, value, traceback): sys.excepthook = exceptHook -try: - from google.protobuf.pyext import _message -except ImportError: - pass -else: - os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "cpp" - -if True: # To make the code style checker stop complaining - import cura.CuraApplication +# Workaround for a race condition on certain systems where there +# is a race condition between Arcus and PyQt. Importing Arcus +# first seems to prevent Sip from going into a state where it +# tries to create PyQt objects on a non-main thread. +import Arcus +import cura.CuraApplication if sys.platform == "win32" and hasattr(sys, "frozen"): import os diff --git a/plugins/AutoSave/AutoSave.py b/plugins/AutoSave/AutoSave.py index b6251addcd..79d91e75b2 100644 --- a/plugins/AutoSave/AutoSave.py +++ b/plugins/AutoSave/AutoSave.py @@ -13,17 +13,17 @@ class AutoSave(Extension): def __init__(self): super().__init__() - Preferences.getInstance().preferenceChanged.connect(self._onPreferenceChanged) + #Preferences.getInstance().preferenceChanged.connect(self._onPreferenceChanged) + Preferences.getInstance().preferenceChanged.connect(self._triggerTimer) machine_manager = Application.getInstance().getMachineManager() self._profile = None machine_manager.activeProfileChanged.connect(self._onActiveProfileChanged) - machine_manager.profileNameChanged.connect(self._onProfileNameChanged) - machine_manager.profilesChanged.connect(self._onProfilesChanged) - machine_manager.machineInstanceNameChanged.connect(self._onInstanceNameChanged) - machine_manager.machineInstancesChanged.connect(self._onInstancesChanged) - Application + machine_manager.profileNameChanged.connect(self._triggerTimer) + machine_manager.profilesChanged.connect(self._triggerTimer) + machine_manager.machineInstanceNameChanged.connect(self._triggerTimer) + machine_manager.machineInstancesChanged.connect(self._triggerTimer) self._onActiveProfileChanged() Preferences.getInstance().addPreference("cura/autosave_delay", 1000 * 10) @@ -33,53 +33,27 @@ class AutoSave(Extension): self._change_timer.setSingleShot(True) self._change_timer.timeout.connect(self._onTimeout) - self._save_preferences = False - self._save_profiles = False - self._save_instances = False + self._saving = False - def _onPreferenceChanged(self, preference): - self._save_preferences = True - self._change_timer.start() - - def _onSettingValueChanged(self, setting): - self._save_profiles = True - self._change_timer.start() + def _triggerTimer(self, *args): + if not self._saving: + self._change_timer.start() def _onActiveProfileChanged(self): if self._profile: - self._profile.settingValueChanged.disconnect(self._onSettingValueChanged) + self._profile.settingValueChanged.disconnect(self._triggerTimer) self._profile = Application.getInstance().getMachineManager().getWorkingProfile() if self._profile: - self._profile.settingValueChanged.connect(self._onSettingValueChanged) - - def _onProfileNameChanged(self, name): - self._onProfilesChanged() - - def _onProfilesChanged(self): - self._save_profiles = True - self._change_timer.start() - - def _onInstanceNameChanged(self, name): - self._onInstancesChanged() - - def _onInstancesChanged(self): - self._save_instances = True - self._change_timer.start() + self._profile.settingValueChanged.connect(self._triggerTimer) def _onTimeout(self): + self._saving = True # To prevent the save process from triggering another autosave. Logger.log("d", "Autosaving preferences, instances and profiles") - if self._save_preferences: - Preferences.getInstance().writeToFile(Resources.getStoragePath(Resources.Preferences, Application.getInstance().getApplicationName() + ".cfg")) + Preferences.getInstance().writeToFile(Resources.getStoragePath(Resources.Preferences, Application.getInstance().getApplicationName() + ".cfg")) + Application.getInstance().getMachineManager().saveMachineInstances() + Application.getInstance().getMachineManager().saveProfiles() - if self._save_instances: - Application.getInstance().getMachineManager().saveMachineInstances() - - if self._save_profiles: - Application.getInstance().getMachineManager().saveProfiles() - - self._save_preferences = False - self._save_instances = False - self._save_profiles = False + self._saving = False diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 27ead0f681..321233e4bf 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -249,7 +249,6 @@ class CuraEngineBackend(Backend): def _onToolOperationStopped(self, tool): self._enabled = True # Tool stop, start listening for changes again. - self._onChanged() def _onActiveViewChanged(self): if Application.getInstance().getController().getActiveView(): diff --git a/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py b/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py index b18df75bc9..f73ba46c85 100644 --- a/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py +++ b/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py @@ -25,20 +25,19 @@ class RemovableDriveOutputDevice(OutputDevice): self._writing = False - def requestWrite(self, node, file_name = None): + def requestWrite(self, node, file_name = None, filter_by_machine = False): if self._writing: raise OutputDeviceError.DeviceBusyError() file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite() #Formats supported by this application. - machine_file_formats = Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getFileFormats() - for file_format in file_formats: - if file_format["mime_type"] in machine_file_formats: - writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_format["mime_type"]) - extension = file_format["extension"] - break #We have a valid mesh writer, supported by the machine. Just pick the first one. - else: - Logger.log("e", "None of the file formats supported by this machine are supported by the application!") + if filter_by_machine: + machine_file_formats = Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getFileFormats() + file_formats = list(filter(lambda file_format: file_format["mime_type"] in machine_file_formats, file_formats)) #Take the intersection between file_formats and machine_file_formats. + if len(file_formats) == 0: + Logger.log("e", "There are no file formats available to write with!") raise OutputDeviceError.WriteRequestFailedError() + writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"]) #Just take the first file format available. + extension = file_formats[0]["extension"] if file_name == None: for n in BreadthFirstIterator(node): diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index d8f2b4d4ad..a1e1ce4909 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -92,7 +92,7 @@ UM.MainWindow text: catalog.i18nc("@action:inmenu menubar:file", "&Save Selection to File"); enabled: UM.Selection.hasSelection; iconName: "document-save-as"; - onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", Printer.jobName); + onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", Printer.jobName, false); } Menu { @@ -108,7 +108,7 @@ UM.MainWindow MenuItem { text: model.description; - onTriggered: UM.OutputDeviceManager.requestWriteToDevice(model.id, Printer.jobName); + onTriggered: UM.OutputDeviceManager.requestWriteToDevice(model.id, Printer.jobName, false); } onObjectAdded: saveAllMenu.insertItem(index, object) onObjectRemoved: saveAllMenu.removeItem(object) diff --git a/resources/qml/SaveButton.qml b/resources/qml/SaveButton.qml index ce726afc04..4a29325007 100644 --- a/resources/qml/SaveButton.qml +++ b/resources/qml/SaveButton.qml @@ -84,7 +84,7 @@ Rectangle { text: UM.OutputDeviceManager.activeDeviceShortDescription onClicked: { - UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, Printer.jobName) + UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, Printer.jobName, true) } style: ButtonStyle {