mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-13 09:47:50 -06:00
Codestyle & typing fixes
This commit is contained in:
parent
22e0c80b3d
commit
b36d3c759f
1 changed files with 24 additions and 24 deletions
|
@ -4,12 +4,13 @@
|
||||||
import collections
|
import collections
|
||||||
import time
|
import time
|
||||||
#Type hinting.
|
#Type hinting.
|
||||||
from typing import Union, List, Dict
|
from typing import Union, List, Dict, TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
||||||
from UM.Signal import Signal
|
from UM.Signal import Signal
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QTimer
|
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QTimer
|
||||||
|
import UM.FlameProfiler
|
||||||
from UM.FlameProfiler import pyqtSlot
|
from UM.FlameProfiler import pyqtSlot
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
from UM import Util
|
from UM import Util
|
||||||
|
@ -25,7 +26,7 @@ from UM.Settings.ContainerStack import ContainerStack
|
||||||
from UM.Settings.InstanceContainer import InstanceContainer
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
from UM.Settings.SettingFunction import SettingFunction
|
from UM.Settings.SettingFunction import SettingFunction
|
||||||
from UM.Signal import postponeSignals, CompressTechnique
|
from UM.Signal import postponeSignals, CompressTechnique
|
||||||
import UM.FlameProfiler
|
|
||||||
|
|
||||||
from cura.QualityManager import QualityManager
|
from cura.QualityManager import QualityManager
|
||||||
from cura.PrinterOutputDevice import PrinterOutputDevice
|
from cura.PrinterOutputDevice import PrinterOutputDevice
|
||||||
|
@ -37,7 +38,6 @@ from UM.i18n import i18nCatalog
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
from cura.Settings.ProfilesModel import ProfilesModel
|
from cura.Settings.ProfilesModel import ProfilesModel
|
||||||
from typing import TYPE_CHECKING, Optional
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||||
|
@ -55,10 +55,10 @@ class MachineManager(QObject):
|
||||||
self.machine_extruder_material_update_dict = collections.defaultdict(list)
|
self.machine_extruder_material_update_dict = collections.defaultdict(list)
|
||||||
|
|
||||||
# Used to store the new containers until after confirming the dialog
|
# Used to store the new containers until after confirming the dialog
|
||||||
self._new_variant_container = None
|
self._new_variant_container = None # type: Optional[InstanceContainer]
|
||||||
self._new_buildplate_container = None
|
self._new_buildplate_container = None # type: Optional[InstanceContainer]
|
||||||
self._new_material_container = None
|
self._new_material_container = None # type: Optional[InstanceContainer]
|
||||||
self._new_quality_containers = []
|
self._new_quality_containers = [] # type: List[Dict]
|
||||||
|
|
||||||
self._error_check_timer = QTimer()
|
self._error_check_timer = QTimer()
|
||||||
self._error_check_timer.setInterval(250)
|
self._error_check_timer.setInterval(250)
|
||||||
|
@ -79,7 +79,7 @@ class MachineManager(QObject):
|
||||||
self.globalContainerChanged.connect(self.activeVariantChanged)
|
self.globalContainerChanged.connect(self.activeVariantChanged)
|
||||||
self.globalContainerChanged.connect(self.activeQualityChanged)
|
self.globalContainerChanged.connect(self.activeQualityChanged)
|
||||||
|
|
||||||
self._stacks_have_errors = None
|
self._stacks_have_errors = None # type:Optional[bool]
|
||||||
|
|
||||||
self._empty_definition_changes_container = ContainerRegistry.getInstance().findContainers(id = "empty_definition_changes")[0]
|
self._empty_definition_changes_container = ContainerRegistry.getInstance().findContainers(id = "empty_definition_changes")[0]
|
||||||
self._empty_variant_container = ContainerRegistry.getInstance().findContainers(id = "empty_variant")[0]
|
self._empty_variant_container = ContainerRegistry.getInstance().findContainers(id = "empty_variant")[0]
|
||||||
|
@ -181,7 +181,7 @@ class MachineManager(QObject):
|
||||||
def totalNumberOfSettings(self) -> int:
|
def totalNumberOfSettings(self) -> int:
|
||||||
return len(ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0].getAllKeys())
|
return len(ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0].getAllKeys())
|
||||||
|
|
||||||
def _onHotendIdChanged(self):
|
def _onHotendIdChanged(self) -> None:
|
||||||
if not self._global_container_stack or not self._printer_output_devices:
|
if not self._global_container_stack or not self._printer_output_devices:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ class MachineManager(QObject):
|
||||||
# A change was found, let the output device handle this.
|
# A change was found, let the output device handle this.
|
||||||
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||||
|
|
||||||
def _onMaterialIdChanged(self):
|
def _onMaterialIdChanged(self) -> None:
|
||||||
if not self._global_container_stack or not self._printer_output_devices:
|
if not self._global_container_stack or not self._printer_output_devices:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ class MachineManager(QObject):
|
||||||
# A change was found, let the output device handle this.
|
# A change was found, let the output device handle this.
|
||||||
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||||
|
|
||||||
def _materialHotendChangedCallback(self, button):
|
def _materialHotendChangedCallback(self, button) -> None:
|
||||||
if button == QMessageBox.No:
|
if button == QMessageBox.No:
|
||||||
self._auto_materials_changed = {}
|
self._auto_materials_changed = {}
|
||||||
self._auto_hotends_changed = {}
|
self._auto_hotends_changed = {}
|
||||||
|
@ -254,7 +254,7 @@ class MachineManager(QObject):
|
||||||
self._autoUpdateMaterials()
|
self._autoUpdateMaterials()
|
||||||
self._autoUpdateHotends()
|
self._autoUpdateHotends()
|
||||||
|
|
||||||
def _autoUpdateMaterials(self):
|
def _autoUpdateMaterials(self) -> None:
|
||||||
extruder_manager = ExtruderManager.getInstance()
|
extruder_manager = ExtruderManager.getInstance()
|
||||||
for position in self._auto_materials_changed:
|
for position in self._auto_materials_changed:
|
||||||
material_id = self._auto_materials_changed[position]
|
material_id = self._auto_materials_changed[position]
|
||||||
|
@ -270,9 +270,9 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
if old_index is not None:
|
if old_index is not None:
|
||||||
extruder_manager.setActiveExtruderIndex(old_index)
|
extruder_manager.setActiveExtruderIndex(old_index)
|
||||||
self._auto_materials_changed = {} #Processed all of them now.
|
self._auto_materials_changed = {} # Processed all of them now.
|
||||||
|
|
||||||
def _autoUpdateHotends(self):
|
def _autoUpdateHotends(self) -> None:
|
||||||
extruder_manager = ExtruderManager.getInstance()
|
extruder_manager = ExtruderManager.getInstance()
|
||||||
for position in self._auto_hotends_changed:
|
for position in self._auto_hotends_changed:
|
||||||
hotend_id = self._auto_hotends_changed[position]
|
hotend_id = self._auto_hotends_changed[position]
|
||||||
|
@ -289,7 +289,7 @@ class MachineManager(QObject):
|
||||||
extruder_manager.setActiveExtruderIndex(old_index)
|
extruder_manager.setActiveExtruderIndex(old_index)
|
||||||
self._auto_hotends_changed = {} # Processed all of them now.
|
self._auto_hotends_changed = {} # Processed all of them now.
|
||||||
|
|
||||||
def _onGlobalContainerChanged(self):
|
def _onGlobalContainerChanged(self) -> None:
|
||||||
if self._global_container_stack:
|
if self._global_container_stack:
|
||||||
try:
|
try:
|
||||||
self._global_container_stack.nameChanged.disconnect(self._onMachineNameChanged)
|
self._global_container_stack.nameChanged.disconnect(self._onMachineNameChanged)
|
||||||
|
@ -308,7 +308,7 @@ class MachineManager(QObject):
|
||||||
extruder_stack.propertyChanged.disconnect(self._onPropertyChanged)
|
extruder_stack.propertyChanged.disconnect(self._onPropertyChanged)
|
||||||
extruder_stack.containersChanged.disconnect(self._onInstanceContainersChanged)
|
extruder_stack.containersChanged.disconnect(self._onInstanceContainersChanged)
|
||||||
|
|
||||||
# update the local global container stack reference
|
# Update the local global container stack reference
|
||||||
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
|
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
|
|
||||||
self.globalContainerChanged.emit()
|
self.globalContainerChanged.emit()
|
||||||
|
@ -345,14 +345,14 @@ class MachineManager(QObject):
|
||||||
self._error_check_timer.start()
|
self._error_check_timer.start()
|
||||||
|
|
||||||
## Update self._stacks_valid according to _checkStacksForErrors and emit if change.
|
## Update self._stacks_valid according to _checkStacksForErrors and emit if change.
|
||||||
def _updateStacksHaveErrors(self):
|
def _updateStacksHaveErrors(self) -> None:
|
||||||
old_stacks_have_errors = self._stacks_have_errors
|
old_stacks_have_errors = self._stacks_have_errors
|
||||||
self._stacks_have_errors = self._checkStacksHaveErrors()
|
self._stacks_have_errors = self._checkStacksHaveErrors()
|
||||||
if old_stacks_have_errors != self._stacks_have_errors:
|
if old_stacks_have_errors != self._stacks_have_errors:
|
||||||
self.stacksValidationChanged.emit()
|
self.stacksValidationChanged.emit()
|
||||||
Application.getInstance().stacksValidationFinished.emit()
|
Application.getInstance().stacksValidationFinished.emit()
|
||||||
|
|
||||||
def _onActiveExtruderStackChanged(self):
|
def _onActiveExtruderStackChanged(self) -> None:
|
||||||
self.blurSettings.emit() # Ensure no-one has focus.
|
self.blurSettings.emit() # Ensure no-one has focus.
|
||||||
old_active_container_stack = self._active_container_stack
|
old_active_container_stack = self._active_container_stack
|
||||||
|
|
||||||
|
@ -365,16 +365,16 @@ class MachineManager(QObject):
|
||||||
# on _active_container_stack. If it changes, then the properties change.
|
# on _active_container_stack. If it changes, then the properties change.
|
||||||
self.activeQualityChanged.emit()
|
self.activeQualityChanged.emit()
|
||||||
|
|
||||||
def __emitChangedSignals(self):
|
def __emitChangedSignals(self) -> None:
|
||||||
self.activeQualityChanged.emit()
|
self.activeQualityChanged.emit()
|
||||||
self.activeVariantChanged.emit()
|
self.activeVariantChanged.emit()
|
||||||
self.activeMaterialChanged.emit()
|
self.activeMaterialChanged.emit()
|
||||||
self._error_check_timer.start()
|
self._error_check_timer.start()
|
||||||
|
|
||||||
def _onProfilesModelChanged(self, *args):
|
def _onProfilesModelChanged(self, *args) -> None:
|
||||||
self.__emitChangedSignals()
|
self.__emitChangedSignals()
|
||||||
|
|
||||||
def _onInstanceContainersChanged(self, container):
|
def _onInstanceContainersChanged(self, container) -> None:
|
||||||
# This should not trigger the ProfilesModel to be created, or there will be an infinite recursion
|
# This should not trigger the ProfilesModel to be created, or there will be an infinite recursion
|
||||||
if not self._connected_to_profiles_model and ProfilesModel.hasInstance():
|
if not self._connected_to_profiles_model and ProfilesModel.hasInstance():
|
||||||
# This triggers updating the qualityModel in SidebarSimple whenever ProfilesModel is updated
|
# This triggers updating the qualityModel in SidebarSimple whenever ProfilesModel is updated
|
||||||
|
@ -384,7 +384,7 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
self._instance_container_timer.start()
|
self._instance_container_timer.start()
|
||||||
|
|
||||||
def _onPropertyChanged(self, key: str, property_name: str):
|
def _onPropertyChanged(self, key: str, property_name: str) -> None:
|
||||||
if property_name == "value":
|
if property_name == "value":
|
||||||
# Notify UI items, such as the "changed" star in profile pull down menu.
|
# Notify UI items, such as the "changed" star in profile pull down menu.
|
||||||
self.activeStackValueChanged.emit()
|
self.activeStackValueChanged.emit()
|
||||||
|
@ -441,7 +441,7 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
## Remove all instances from the top instanceContainer (effectively removing all user-changed settings)
|
## Remove all instances from the top instanceContainer (effectively removing all user-changed settings)
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def clearUserSettings(self):
|
def clearUserSettings(self) -> None:
|
||||||
if not self._active_container_stack:
|
if not self._active_container_stack:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -479,7 +479,7 @@ class MachineManager(QObject):
|
||||||
## Delete a user setting from the global stack and all extruder stacks.
|
## Delete a user setting from the global stack and all extruder stacks.
|
||||||
# \param key \type{str} the name of the key to delete
|
# \param key \type{str} the name of the key to delete
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def clearUserSettingAllCurrentStacks(self, key: str):
|
def clearUserSettingAllCurrentStacks(self, key: str) -> None:
|
||||||
if not self._global_container_stack:
|
if not self._global_container_stack:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue