From 1b34449242d0b5b8d3e54c6193a53f2678f39199 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Thu, 7 May 2020 17:26:20 +0200 Subject: [PATCH 1/2] Add a preference to use a single instance for loading files Contributes to #7664 --- cura/CuraApplication.py | 17 ++++++++++++++++- resources/qml/Preferences/GeneralPage.qml | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 67a9451282..e4b6d003bb 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -304,6 +304,7 @@ class CuraApplication(QtApplication): super().initialize() + self._checkEarlyPreferences() self.__sendCommandToSingleInstance() self._initializeSettingDefinitions() self._initializeSettingFunctions() @@ -314,6 +315,20 @@ class CuraApplication(QtApplication): self._machine_action_manager = MachineActionManager.MachineActionManager(self) self._machine_action_manager.initialize() + def _checkEarlyPreferences(self) -> None: + # Check for specific preferences early in the bootstrap process, without spinning up the full Preference singleton yet + if self._use_single_instance: + return + + preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(self.getApplicationName())) + if not os.path.exists(preferences_file): + return + + with open(preferences_file) as preferences: + if "single_instance = True" in preferences.read(): + Logger.log("i", "Preference to use a single instance detected") + self._use_single_instance = True + def __sendCommandToSingleInstance(self): self._single_instance = SingleInstance(self, self._files_to_open) @@ -508,7 +523,7 @@ class CuraApplication(QtApplication): preferences.setValue("metadata/setting_version", self.SettingVersion) #Don't make it equal to the default so that the setting version always gets written to the file. preferences.addPreference("cura/active_mode", "simple") - + preferences.addPreference("cura/single_instance", False) preferences.addPreference("cura/categories_expanded", "") preferences.addPreference("cura/jobname_prefix", True) preferences.addPreference("cura/select_models_on_load", False) diff --git a/resources/qml/Preferences/GeneralPage.qml b/resources/qml/Preferences/GeneralPage.qml index 404c961a90..59827f3f29 100644 --- a/resources/qml/Preferences/GeneralPage.qml +++ b/resources/qml/Preferences/GeneralPage.qml @@ -72,6 +72,9 @@ UM.PreferencesPage var defaultTheme = UM.Preferences.getValue("general/theme") setDefaultTheme(defaultTheme) + UM.Preferences.resetPreference("cura/single_instance") + scaleToFitCheckbox.checked = boolCheck(UM.Preferences.getValue("cura/single_instance")) + UM.Preferences.resetPreference("physics/automatic_push_free") pushFreeCheckbox.checked = boolCheck(UM.Preferences.getValue("physics/automatic_push_free")) UM.Preferences.resetPreference("physics/automatic_drop_down") @@ -560,6 +563,21 @@ UM.PreferencesPage text: catalog.i18nc("@label","Opening and saving files") } + UM.TooltipArea + { + width: childrenRect.width + height: childrenRect.height + text: catalog.i18nc("@info:tooltip","Should opening files from the desktop or external applications open in the same instance of Cura?") + + CheckBox + { + id: singleInstanceCheckbox + text: catalog.i18nc("@option:check","Use a single instance of Cura") + checked: boolCheck(UM.Preferences.getValue("cura/single_instance")) + onCheckedChanged: UM.Preferences.setValue("cura/single_instance", checked) + } + } + UM.TooltipArea { width: childrenRect.width From cdc5c8948cfef2a9fc6efc3c976bb7691890c543 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Thu, 7 May 2020 18:13:23 +0200 Subject: [PATCH 2/2] Simplify single instance preference The Preferences have already been initialized in QTApplication.initialize to get the language to use in the splashscreen. --- cura/CuraApplication.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index e4b6d003bb..7b60e0eb83 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -304,7 +304,9 @@ class CuraApplication(QtApplication): super().initialize() - self._checkEarlyPreferences() + self._preferences.addPreference("cura/single_instance", False) + self._use_single_instance = self._preferences.getValue("cura/single_instance") + self.__sendCommandToSingleInstance() self._initializeSettingDefinitions() self._initializeSettingFunctions() @@ -315,20 +317,6 @@ class CuraApplication(QtApplication): self._machine_action_manager = MachineActionManager.MachineActionManager(self) self._machine_action_manager.initialize() - def _checkEarlyPreferences(self) -> None: - # Check for specific preferences early in the bootstrap process, without spinning up the full Preference singleton yet - if self._use_single_instance: - return - - preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(self.getApplicationName())) - if not os.path.exists(preferences_file): - return - - with open(preferences_file) as preferences: - if "single_instance = True" in preferences.read(): - Logger.log("i", "Preference to use a single instance detected") - self._use_single_instance = True - def __sendCommandToSingleInstance(self): self._single_instance = SingleInstance(self, self._files_to_open) @@ -523,7 +511,7 @@ class CuraApplication(QtApplication): preferences.setValue("metadata/setting_version", self.SettingVersion) #Don't make it equal to the default so that the setting version always gets written to the file. preferences.addPreference("cura/active_mode", "simple") - preferences.addPreference("cura/single_instance", False) + preferences.addPreference("cura/categories_expanded", "") preferences.addPreference("cura/jobname_prefix", True) preferences.addPreference("cura/select_models_on_load", False)