Add use_gui flag in application, don't use theme functions when not using gui

This commit is contained in:
ChrisTerBeke 2018-01-12 17:38:47 +01:00
parent 1a05fd5989
commit bd1bf2caaf
2 changed files with 19 additions and 2 deletions

View file

@ -142,6 +142,7 @@ class CuraApplication(QtApplication):
if not hasattr(sys, "frozen"): if not hasattr(sys, "frozen"):
Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources")) Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources"))
self._use_gui = True
self._open_file_queue = [] # Files to open when plug-ins are loaded. self._open_file_queue = [] # Files to open when plug-ins are loaded.
# Need to do this before ContainerRegistry tries to load the machines # Need to do this before ContainerRegistry tries to load the machines
@ -451,7 +452,7 @@ class CuraApplication(QtApplication):
elif choice == "always_keep": elif choice == "always_keep":
# don't show dialog and KEEP the profile # don't show dialog and KEEP the profile
self.discardOrKeepProfileChangesClosed("keep") self.discardOrKeepProfileChangesClosed("keep")
else: elif self._use_gui:
# ALWAYS ask whether to keep or discard the profile # ALWAYS ask whether to keep or discard the profile
self.showDiscardOrKeepProfileChanges.emit() self.showDiscardOrKeepProfileChanges.emit()
has_user_interaction = True has_user_interaction = True
@ -676,10 +677,13 @@ class CuraApplication(QtApplication):
## Run Cura without GUI elements and interaction (server mode). ## Run Cura without GUI elements and interaction (server mode).
def runWithoutGUI(self): def runWithoutGUI(self):
self._use_gui = False
self.closeSplash() self.closeSplash()
## Run Cura with GUI (desktop mode). ## Run Cura with GUI (desktop mode).
def runWithGUI(self): def runWithGUI(self):
self._use_gui = True
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Setting up scene...")) self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Setting up scene..."))
controller = self.getController() controller = self.getController()
@ -732,6 +736,9 @@ class CuraApplication(QtApplication):
# Hide the splash screen # Hide the splash screen
self.closeSplash() self.closeSplash()
def hasGui(self):
return self._use_gui
def getMachineManager(self, *args) -> MachineManager: def getMachineManager(self, *args) -> MachineManager:
if self._machine_manager is None: if self._machine_manager is None:
self._machine_manager = MachineManager.createMachineManager() self._machine_manager = MachineManager.createMachineManager()
@ -1344,6 +1351,7 @@ class CuraApplication(QtApplication):
pass pass
fileLoaded = pyqtSignal(str) fileLoaded = pyqtSignal(str)
fileCompleted = pyqtSignal(str)
def _reloadMeshFinished(self, job): def _reloadMeshFinished(self, job):
# TODO; This needs to be fixed properly. We now make the assumption that we only load a single mesh! # TODO; This needs to be fixed properly. We now make the assumption that we only load a single mesh!
@ -1353,6 +1361,10 @@ class CuraApplication(QtApplication):
else: else:
Logger.log("w", "Could not find a mesh in reloaded node.") Logger.log("w", "Could not find a mesh in reloaded node.")
## Import a file from disk
def openFile(self, filename):
self._openFile(filename)
def _openFile(self, filename): def _openFile(self, filename):
self.readLocalFile(QUrl.fromLocalFile(filename)) self.readLocalFile(QUrl.fromLocalFile(filename))
@ -1514,6 +1526,8 @@ class CuraApplication(QtApplication):
op.push() op.push()
scene.sceneChanged.emit(node) scene.sceneChanged.emit(node)
self.fileCompleted.emit(filename)
def addNonSliceableExtension(self, extension): def addNonSliceableExtension(self, extension):
self._non_sliceable_extensions.append(extension) self._non_sliceable_extensions.append(extension)

View file

@ -24,7 +24,10 @@ class ConvexHullNode(SceneNode):
self._original_parent = parent self._original_parent = parent
# Color of the drawn convex hull # Color of the drawn convex hull
if Application.getInstance().hasGui():
self._color = Color(*Application.getInstance().getTheme().getColor("convex_hull").getRgb()) self._color = Color(*Application.getInstance().getTheme().getColor("convex_hull").getRgb())
else:
self._color = Color(0, 0, 0)
# The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting. # The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting.
self._mesh_height = 0.1 self._mesh_height = 0.1