Added isValidGlobalStack property to MachineManager

CURA-1585
This commit is contained in:
Jaime van Kessel 2016-06-03 10:29:19 +02:00
parent 171adde6be
commit 113da81db5
2 changed files with 18 additions and 2 deletions

View file

@ -7,6 +7,7 @@ from UM.Preferences import Preferences
from UM.Logger import Logger from UM.Logger import Logger
import UM.Settings import UM.Settings
from UM.Settings.Validator import ValidatorState
class MachineManagerModel(QObject): class MachineManagerModel(QObject):
@ -167,6 +168,17 @@ class MachineManagerModel(QObject):
return unique_name return unique_name
## Convenience function to check if a stack has errors.
def _checkStackForErrors(self, stack):
if stack is None:
return False
for key in stack.getAllKeys():
validation_state = stack.getProperty(key, "validationState")
if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
return True
return False
@pyqtSlot() @pyqtSlot()
def clearUserSettings(self): def clearUserSettings(self):
if not self._global_container_stack: if not self._global_container_stack:
@ -182,6 +194,10 @@ class MachineManagerModel(QObject):
user_settings = self._global_container_stack.getTop().findInstances(**{}) user_settings = self._global_container_stack.getTop().findInstances(**{})
return len(user_settings) != 0 return len(user_settings) != 0
@pyqtProperty(bool, notify = globalPropertyChanged)
def isGlobalStackValid(self):
return not self._checkStackForErrors(self._global_container_stack)
@pyqtProperty(str, notify = globalContainerChanged) @pyqtProperty(str, notify = globalContainerChanged)
def activeMachineName(self): def activeMachineName(self):
if self._global_container_stack: if self._global_container_stack:

View file

@ -110,7 +110,7 @@ Item
Action Action
{ {
id: updateProfileAction; id: updateProfileAction;
enabled: UM.ActiveProfile.valid && !UM.ActiveProfile.readOnly && UM.ActiveProfile.hasCustomisedValues enabled: Cura.MachineManager.isGlobalStackValid && !UM.ActiveProfile.readOnly && Cura.MachineManager.hasUserSettings
text: catalog.i18nc("@action:inmenu menubar:profile","&Update Current Profile"); text: catalog.i18nc("@action:inmenu menubar:profile","&Update Current Profile");
onTriggered: UM.ActiveProfile.updateProfile(); onTriggered: UM.ActiveProfile.updateProfile();
} }
@ -126,7 +126,7 @@ Item
Action Action
{ {
id: addProfileAction; id: addProfileAction;
enabled: UM.ActiveProfile.valid enabled: Cura.MachineManager.isGlobalStackValid
text: catalog.i18nc("@action:inmenu menubar:profile","&Create New Profile..."); text: catalog.i18nc("@action:inmenu menubar:profile","&Create New Profile...");
} }