mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-13 09:47:50 -06:00
Show machine actions page optionally
This commit is contained in:
parent
56a3b2dfa7
commit
6dbae6f088
3 changed files with 136 additions and 54 deletions
|
@ -1,9 +1,9 @@
|
|||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from typing import Optional
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
from PyQt5.QtCore import QObject, Qt
|
||||
from PyQt5.QtCore import QObject, Qt, pyqtProperty, pyqtSignal, pyqtSlot
|
||||
|
||||
from UM.Qt.ListModel import ListModel
|
||||
|
||||
|
@ -27,6 +27,8 @@ class FirstStartMachineActionsModel(ListModel):
|
|||
self.addRoleName(self.ContentRole, "content")
|
||||
self.addRoleName(self.ActionRole, "action")
|
||||
|
||||
self._current_action_index = 0
|
||||
|
||||
from cura.CuraApplication import CuraApplication
|
||||
self._application = CuraApplication.getInstance()
|
||||
|
||||
|
@ -36,6 +38,47 @@ class FirstStartMachineActionsModel(ListModel):
|
|||
self._application.getMachineManager().globalContainerChanged.connect(self._update)
|
||||
self._update()
|
||||
|
||||
currentActionIndexChanged = pyqtSignal()
|
||||
allFinished = pyqtSignal() # Emitted when all actions have been finished.
|
||||
|
||||
@pyqtProperty(int, notify = currentActionIndexChanged)
|
||||
def currentActionIndex(self) -> int:
|
||||
return self._current_action_index
|
||||
|
||||
@pyqtProperty("QVariantMap", notify = currentActionIndexChanged)
|
||||
def currentItem(self) -> Optional[Dict[str, Any]]:
|
||||
if self._current_action_index >= self.count:
|
||||
return dict()
|
||||
else:
|
||||
return self.getItem(self._current_action_index)
|
||||
|
||||
@pyqtProperty(bool, notify = currentActionIndexChanged)
|
||||
def hasMoreActions(self) -> bool:
|
||||
return self._current_action_index < self.count - 1
|
||||
|
||||
@pyqtSlot()
|
||||
def goToNextAction(self) -> None:
|
||||
# finish the current item
|
||||
if "action" in self.currentItem:
|
||||
self.currentItem["action"].setFinished()
|
||||
|
||||
if not self.hasMoreActions:
|
||||
self.allFinished.emit()
|
||||
self.reset()
|
||||
return
|
||||
|
||||
self._current_action_index += 1
|
||||
self.currentActionIndexChanged.emit()
|
||||
|
||||
# Resets the current action index to 0 so the wizard panel can show actions from the beginning.
|
||||
@pyqtSlot()
|
||||
def reset(self) -> None:
|
||||
self._current_action_index = 0
|
||||
self.currentActionIndexChanged.emit()
|
||||
|
||||
if self.count == 0:
|
||||
self.allFinished.emit()
|
||||
|
||||
def _update(self) -> None:
|
||||
global_stack = self._application.getMachineManager().activeMachine
|
||||
if global_stack is None:
|
||||
|
@ -53,6 +96,7 @@ class FirstStartMachineActionsModel(ListModel):
|
|||
})
|
||||
|
||||
self.setItems(item_list)
|
||||
self.reset()
|
||||
|
||||
|
||||
__all__ = ["FirstStartMachineActionsModel"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue