mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Pass application
This commit is contained in:
parent
3ad79a5888
commit
f4d0e39788
3 changed files with 19 additions and 14 deletions
|
@ -1,12 +1,15 @@
|
||||||
# Copyright (c) 2019 Ultimaker B.V.
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Optional, Dict, Any
|
from typing import Optional, Dict, Any, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, Qt, pyqtProperty, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import QObject, Qt, pyqtProperty, pyqtSignal, pyqtSlot
|
||||||
|
|
||||||
from UM.Qt.ListModel import ListModel
|
from UM.Qt.ListModel import ListModel
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# This model holds all first-start machine actions for the currently active machine. It has 2 roles:
|
# This model holds all first-start machine actions for the currently active machine. It has 2 roles:
|
||||||
|
@ -20,7 +23,7 @@ class FirstStartMachineActionsModel(ListModel):
|
||||||
ContentRole = Qt.UserRole + 2
|
ContentRole = Qt.UserRole + 2
|
||||||
ActionRole = Qt.UserRole + 3
|
ActionRole = Qt.UserRole + 3
|
||||||
|
|
||||||
def __init__(self, parent: Optional[QObject] = None) -> None:
|
def __init__(self, application: "CuraApplication", parent: Optional[QObject] = None) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self.addRoleName(self.TitleRole, "title")
|
self.addRoleName(self.TitleRole, "title")
|
||||||
|
@ -29,9 +32,7 @@ class FirstStartMachineActionsModel(ListModel):
|
||||||
|
|
||||||
self._current_action_index = 0
|
self._current_action_index = 0
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
self._application = application
|
||||||
self._application = CuraApplication.getInstance()
|
|
||||||
|
|
||||||
self._application.initializationFinished.connect(self._initialize)
|
self._application.initializationFinished.connect(self._initialize)
|
||||||
|
|
||||||
def _initialize(self) -> None:
|
def _initialize(self) -> None:
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
# Copyright (c) 2019 Ultimaker B.V.
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSlot
|
from PyQt5.QtCore import QObject, pyqtSlot
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# This manager provides (convenience) functions to the Machine Settings Dialog QML to update certain machine settings.
|
# This manager provides (convenience) functions to the Machine Settings Dialog QML to update certain machine settings.
|
||||||
#
|
#
|
||||||
class MachineSettingsManager(QObject):
|
class MachineSettingsManager(QObject):
|
||||||
|
|
||||||
def __init__(self, parent: Optional["QObject"] = None) -> None:
|
def __init__(self, application: "CuraApplication", parent: Optional["QObject"] = None) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._i18n_catalog = i18nCatalog("cura")
|
self._i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
self._application = application
|
||||||
self._application = CuraApplication.getInstance()
|
|
||||||
|
|
||||||
# Force rebuilding the build volume by reloading the global container stack. This is a bit of a hack, but it seems
|
# Force rebuilding the build volume by reloading the global container stack. This is a bit of a hack, but it seems
|
||||||
# quite enough.
|
# quite enough.
|
||||||
|
|
|
@ -12,6 +12,8 @@ from UM.Resources import Resources
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from PyQt5.QtCore import QObject
|
from PyQt5.QtCore import QObject
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# This is the Qt ListModel that contains all welcome pages data. Each page is a page that can be shown as a step in the
|
# This is the Qt ListModel that contains all welcome pages data. Each page is a page that can be shown as a step in the
|
||||||
|
@ -33,13 +35,15 @@ class WelcomePagesModel(ListModel):
|
||||||
PageUrlRole = Qt.UserRole + 2 # URL to the page's QML file
|
PageUrlRole = Qt.UserRole + 2 # URL to the page's QML file
|
||||||
NextPageIdRole = Qt.UserRole + 3 # The next page ID it should go to
|
NextPageIdRole = Qt.UserRole + 3 # The next page ID it should go to
|
||||||
|
|
||||||
def __init__(self, parent: Optional["QObject"] = None) -> None:
|
def __init__(self, application: "CuraApplication", parent: Optional["QObject"] = None) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self.addRoleName(self.IdRole, "id")
|
self.addRoleName(self.IdRole, "id")
|
||||||
self.addRoleName(self.PageUrlRole, "page_url")
|
self.addRoleName(self.PageUrlRole, "page_url")
|
||||||
self.addRoleName(self.NextPageIdRole, "next_page_id")
|
self.addRoleName(self.NextPageIdRole, "next_page_id")
|
||||||
|
|
||||||
|
self._application = application
|
||||||
|
|
||||||
self._pages = [] # type: List[Dict[str, Any]]
|
self._pages = [] # type: List[Dict[str, Any]]
|
||||||
|
|
||||||
self._current_page_index = 0
|
self._current_page_index = 0
|
||||||
|
@ -206,14 +210,12 @@ class WelcomePagesModel(ListModel):
|
||||||
# Indicates if the machine action panel should be shown by checking if there's any first start machine actions
|
# Indicates if the machine action panel should be shown by checking if there's any first start machine actions
|
||||||
# available.
|
# available.
|
||||||
def shouldShowMachineActions(self) -> bool:
|
def shouldShowMachineActions(self) -> bool:
|
||||||
from cura.CuraApplication import CuraApplication
|
global_stack = self._application.getMachineManager().activeMachine
|
||||||
application = CuraApplication.getInstance()
|
|
||||||
global_stack = application.getMachineManager().activeMachine
|
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
definition_id = global_stack.definition.getId()
|
definition_id = global_stack.definition.getId()
|
||||||
first_start_actions = application.getMachineActionManager().getFirstStartActions(definition_id)
|
first_start_actions = self._application.getMachineActionManager().getFirstStartActions(definition_id)
|
||||||
return len(first_start_actions) > 0
|
return len(first_start_actions) > 0
|
||||||
|
|
||||||
def addPage(self) -> None:
|
def addPage(self) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue