CURA-5164 The Preferences is not a singleton class anymore since in some point

several instances need to be created.

- In the ThreeMFWorkspaceReader we need to create some temporal
instances of Preferences that makes it not singleton anymore.

- The current preferences are kept in the Application class and so all
the calls to the preferences are changed to get the preferences from
Application.

- The method getInstance in Preferences is kept as deprecated since some
external plugins.
This commit is contained in:
Diego Prado Gesto 2018-05-11 08:42:03 +02:00
parent 42ecb12614
commit 43657010ba
22 changed files with 102 additions and 119 deletions

View file

@ -16,7 +16,6 @@ from UM.FlameProfiler import pyqtSlot
from UM import Util
from UM.Application import Application
from UM.Preferences import Preferences
from UM.Logger import Logger
from UM.Message import Message
@ -97,12 +96,12 @@ class MachineManager(QObject):
ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeStackChanged)
self.activeStackChanged.connect(self.activeStackValueChanged)
Preferences.getInstance().addPreference("cura/active_machine", "")
self._application.getPreferences().addPreference("cura/active_machine", "")
self._global_event_keys = set()
self._printer_output_devices = [] # type: List[PrinterOutputDevice]
Application.getInstance().getOutputDeviceManager().outputDevicesChanged.connect(self._onOutputDevicesChanged)
self._application.getOutputDeviceManager().outputDevicesChanged.connect(self._onOutputDevicesChanged)
# There might already be some output devices by the time the signal is connected
self._onOutputDevicesChanged()
@ -163,7 +162,7 @@ class MachineManager(QObject):
rootMaterialChanged = pyqtSignal()
def setInitialActiveMachine(self) -> None:
active_machine_id = Preferences.getInstance().getValue("cura/active_machine")
active_machine_id = self._application.getPreferences().getValue("cura/active_machine")
if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacksMetadata(id = active_machine_id):
# An active machine was saved, so restore it.
self.setActiveMachine(active_machine_id)
@ -172,7 +171,7 @@ class MachineManager(QObject):
def _onOutputDevicesChanged(self) -> None:
self._printer_output_devices = []
for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices():
for printer_output_device in self._application.getOutputDeviceManager().getOutputDevices():
if isinstance(printer_output_device, PrinterOutputDevice):
self._printer_output_devices.append(printer_output_device)
@ -239,7 +238,7 @@ class MachineManager(QObject):
extruder_stack.containersChanged.disconnect(self._onContainersChanged)
# Update the local global container stack reference
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
self._global_container_stack = self._application.getGlobalContainerStack()
if self._global_container_stack:
self.updateDefaultExtruder()
self.updateNumberExtrudersEnabled()
@ -247,7 +246,7 @@ class MachineManager(QObject):
# after switching the global stack we reconnect all the signals and set the variant and material references
if self._global_container_stack:
Preferences.getInstance().setValue("cura/active_machine", self._global_container_stack.getId())
self._application.getPreferences().setValue("cura/active_machine", self._global_container_stack.getId())
self._global_container_stack.nameChanged.connect(self._onMachineNameChanged)
self._global_container_stack.containersChanged.connect(self._onContainersChanged)
@ -271,7 +270,7 @@ class MachineManager(QObject):
if self._global_container_stack.getId() in self.machine_extruder_material_update_dict:
for func in self.machine_extruder_material_update_dict[self._global_container_stack.getId()]:
Application.getInstance().callLater(func)
self._application.callLater(func)
del self.machine_extruder_material_update_dict[self._global_container_stack.getId()]
self.activeQualityGroupChanged.emit()
@ -361,7 +360,7 @@ class MachineManager(QObject):
global_stack = containers[0]
ExtruderManager.getInstance().setActiveExtruderIndex(0) # Switch to first extruder
self._global_container_stack = global_stack
Application.getInstance().setGlobalContainerStack(global_stack)
self._application.setGlobalContainerStack(global_stack)
ExtruderManager.getInstance()._globalContainerStackChanged()
self._initMachineState(containers[0])
self._onGlobalContainerChanged()
@ -835,7 +834,7 @@ class MachineManager(QObject):
## Set the amount of extruders on the active machine (global stack)
# \param extruder_count int the number of extruders to set
def setActiveMachineExtruderCount(self, extruder_count: int) -> None:
extruder_manager = Application.getInstance().getExtruderManager()
extruder_manager = self._application.getExtruderManager()
definition_changes_container = self._global_container_stack.definitionChanges
if not self._global_container_stack or definition_changes_container == self._empty_definition_changes_container:
@ -852,7 +851,7 @@ class MachineManager(QObject):
self.correctExtruderSettings()
# Check to see if any objects are set to print with an extruder that will no longer exist
root_node = Application.getInstance().getController().getScene().getRoot()
root_node = self._application.getController().getScene().getRoot()
for node in DepthFirstIterator(root_node):
if node.getMeshData():
extruder_nr = node.callDecoration("getActiveExtruderPosition")
@ -885,7 +884,7 @@ class MachineManager(QObject):
global_user_container.removeInstance(setting_key)
# Signal that the global stack has changed
Application.getInstance().globalContainerStackChanged.emit()
self._application.globalContainerStackChanged.emit()
self.forceUpdateAllSettings()
@pyqtSlot(int, result = QObject)
@ -1117,7 +1116,7 @@ class MachineManager(QObject):
def _setGlobalVariant(self, container_node):
self._global_container_stack.variant = container_node.getContainer()
if not self._global_container_stack.variant:
self._global_container_stack.variant = Application.getInstance().empty_variant_container
self._global_container_stack.variant = self._application.empty_variant_container
def _setMaterial(self, position, container_node = None):
if container_node and container_node.getContainer():
@ -1359,7 +1358,7 @@ class MachineManager(QObject):
self._setQualityGroup(quality_group)
# See if we need to show the Discard or Keep changes screen
if not no_dialog and self.hasUserSettings and Preferences.getInstance().getValue("cura/active_mode") == 1:
if not no_dialog and self.hasUserSettings and self._application.getPreferences().getValue("cura/active_mode") == 1:
self._application.discardOrKeepProfileChanges()
@pyqtProperty(QObject, fset = setQualityGroup, notify = activeQualityGroupChanged)
@ -1373,7 +1372,7 @@ class MachineManager(QObject):
self._setQualityChangesGroup(quality_changes_group)
# See if we need to show the Discard or Keep changes screen
if not no_dialog and self.hasUserSettings and Preferences.getInstance().getValue("cura/active_mode") == 1:
if not no_dialog and self.hasUserSettings and self._application.getPreferences().getValue("cura/active_mode") == 1:
self._application.discardOrKeepProfileChanges()
@pyqtSlot()