From 6d190479ac27fa9cc4aefeef1ad78d6b6d56583a Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 14:56:09 +0100 Subject: [PATCH 01/37] Getting logs earlier! Have currently the issue here, that when running Cura as a COM service, that the Cura.exe is popping up for (feels like) 1s or less and crashes. --- cura_app.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/cura_app.py b/cura_app.py index 7583dd054e..cae0821825 100755 --- a/cura_app.py +++ b/cura_app.py @@ -2,13 +2,28 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. + import os import sys +from UM.Platform import Platform + +def get_cura_dir_path(): + if Platform.isWindows(): + return os.path.expanduser("~/AppData/Local/cura/") + elif Platform.isLinux(): + return os.path.expanduser("~/.local/share/cura") + elif Platform.isOSX(): + return os.path.expanduser("~/Library/Logs/cura") + +if hasattr(sys, "frozen"): + dirpath = get_cura_dir_path() + os.makedirs(dirpath, exist_ok = True) + sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w") + sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w") + import platform import faulthandler -from UM.Platform import Platform - #WORKAROUND: GITHUB-88 GITHUB-385 GITHUB-612 if Platform.isLinux(): # Needed for platform.linux_distribution, which is not available on Windows and OSX # For Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826 @@ -47,7 +62,6 @@ def exceptHook(hook_type, value, traceback): _crash_handler = CrashHandler(hook_type, value, traceback) _crash_handler.show() - sys.excepthook = exceptHook # Workaround for a race condition on certain systems where there @@ -58,21 +72,6 @@ import Arcus #@UnusedImport import cura.CuraApplication import cura.Settings.CuraContainerRegistry -def get_cura_dir_path(): - if Platform.isWindows(): - return os.path.expanduser("~/AppData/Local/cura/") - elif Platform.isLinux(): - return os.path.expanduser("~/.local/share/cura") - elif Platform.isOSX(): - return os.path.expanduser("~/Library/Logs/cura") - - -if hasattr(sys, "frozen"): - dirpath = get_cura_dir_path() - os.makedirs(dirpath, exist_ok = True) - sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w") - sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w") - faulthandler.enable() # Force an instance of CuraContainerRegistry to be created and reused later. From e5096f731c06f94ba18fb336883d803471bf101c Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 14:58:24 +0100 Subject: [PATCH 02/37] cura_app: We store logs now at "Roaming" --- cura_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura_app.py b/cura_app.py index cae0821825..fd36aa5a24 100755 --- a/cura_app.py +++ b/cura_app.py @@ -9,7 +9,7 @@ from UM.Platform import Platform def get_cura_dir_path(): if Platform.isWindows(): - return os.path.expanduser("~/AppData/Local/cura/") + return os.path.expanduser("~/AppData/Roaming/cura/") elif Platform.isLinux(): return os.path.expanduser("~/.local/share/cura") elif Platform.isOSX(): From 00a77da9d449244f62dc61a4f8a554893be17b3f Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 15:19:28 +0100 Subject: [PATCH 03/37] COM: Adding missing argument for DCOM --- cura/CuraApplication.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index a5ae286b1e..e02c44d205 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -570,6 +570,7 @@ class CuraApplication(QtApplication): parser.add_argument("file", nargs="*", help="Files to load after starting the application.") parser.add_argument("--single-instance", action="store_true", default=False) parser.add_argument("--headless", action = "store_true", default=False) + parser.add_argument("-Embedding", action="store_true", default=False) # Commandline option set my DCOM (Windows Automation) # Set up a local socket server which listener which coordinates single instances Curas and accepts commands. def _setUpSingleInstanceServer(self): From 83d8c693bc0280019830f84d589872fbc32b866c Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 15:23:35 +0100 Subject: [PATCH 04/37] CuraApplication: Removing superflous check Imagine that there was no "single_instance" in parsed_command_line, then the second half of the if-clause would automatically crash. Also we defined single_instance to be False, whenever not set. Therefore it is always there. Also since no issues ever happened here, let's remove this check. --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index e02c44d205..45ed6b8260 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -630,7 +630,7 @@ class CuraApplication(QtApplication): CuraApplication.addCommandLineOptions(parser) parsed_command_line = vars(parser.parse_args()) - if "single_instance" in parsed_command_line and parsed_command_line["single_instance"]: + if parsed_command_line["single_instance"]: Logger.log("i", "Checking for the presence of an ready running Cura instance.") single_instance_socket = QLocalSocket() Logger.log("d", "preStartUp(): full server name: " + single_instance_socket.fullServerName()) From 11cf642a6e3c881a6a7918c6c8d5377c346403a6 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 15:43:28 +0100 Subject: [PATCH 05/37] COM: Prevent splash screen, when Embedding is set. So when dispatching our service we won't see any splash screen. Just like we want for headless applications. --- cura/CuraApplication.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 45ed6b8260..a6a54ad832 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -660,6 +660,8 @@ class CuraApplication(QtApplication): single_instance_socket.flush() single_instance_socket.waitForDisconnected() return False + if parsed_command_line["Embedding"]: + self._splash_prevent = True return True def run(self): From b22981d08973e8d08c3ae3f0c5cbf1cf45ab2f26 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 16:12:56 +0100 Subject: [PATCH 06/37] It is cls not self! --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index a6a54ad832..30ce730562 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -661,7 +661,7 @@ class CuraApplication(QtApplication): single_instance_socket.waitForDisconnected() return False if parsed_command_line["Embedding"]: - self._splash_prevent = True + cls._splash_prevent = True return True def run(self): From abc2cdb7010bd06d3cbb46f89d7287b3d6d9c169 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 20:18:11 +0100 Subject: [PATCH 07/37] CuraApplication: Adding important note about the argparser --- cura/CuraApplication.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 30ce730562..1c610eebb6 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -628,6 +628,8 @@ class CuraApplication(QtApplication): # Peek the arguments and look for the 'single-instance' flag. parser = argparse.ArgumentParser(prog="cura") # pylint: disable=bad-whitespace CuraApplication.addCommandLineOptions(parser) + # Important: It is important to keep this line here! + # In Uranium we allow to pass unknown arguments to the final executable or script. parsed_command_line = vars(parser.parse_args()) if parsed_command_line["single_instance"]: From 8c74092f48d3b9322dbca3b9abf1c7bdbaf816a2 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 20:18:38 +0100 Subject: [PATCH 08/37] CuraApplication: Getting argparser from Uranium --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 1c610eebb6..f897c19f0b 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -626,7 +626,7 @@ class CuraApplication(QtApplication): @classmethod def preStartUp(cls): # Peek the arguments and look for the 'single-instance' flag. - parser = argparse.ArgumentParser(prog="cura") # pylint: disable=bad-whitespace + parser = cls.getCommandlineParser() CuraApplication.addCommandLineOptions(parser) # Important: It is important to keep this line here! # In Uranium we allow to pass unknown arguments to the final executable or script. From 315efae53b68c9530bc2a2c15f46b876081cfd30 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 20:27:25 +0100 Subject: [PATCH 09/37] CuraApplication: Making use of Uranium commandline tools --- cura/CuraApplication.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f897c19f0b..5cced81260 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -628,11 +628,9 @@ class CuraApplication(QtApplication): # Peek the arguments and look for the 'single-instance' flag. parser = cls.getCommandlineParser() CuraApplication.addCommandLineOptions(parser) - # Important: It is important to keep this line here! - # In Uranium we allow to pass unknown arguments to the final executable or script. - parsed_command_line = vars(parser.parse_args()) + cls.parseCommandLine() - if parsed_command_line["single_instance"]: + if cls.getCommandLineOption("single_instance"): Logger.log("i", "Checking for the presence of an ready running Cura instance.") single_instance_socket = QLocalSocket() Logger.log("d", "preStartUp(): full server name: " + single_instance_socket.fullServerName()) @@ -651,8 +649,8 @@ class CuraApplication(QtApplication): payload = {"command": "focus"} single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ASCII")) - if len(parsed_command_line["file"]) != 0: - for filename in parsed_command_line["file"]: + if len(cls.getCommandLineOption("file")) != 0: + for filename in cls.getCommandLineOption("file"): payload = {"command": "open", "filePath": filename} single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ASCII")) @@ -662,7 +660,7 @@ class CuraApplication(QtApplication): single_instance_socket.flush() single_instance_socket.waitForDisconnected() return False - if parsed_command_line["Embedding"]: + if cls.getCommandLineOption("Embedding"): cls._splash_prevent = True return True From 0967651a491d644be9ad4b36051945f5dafa8032 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 20:28:46 +0100 Subject: [PATCH 10/37] CuraApplication: Adding last check for unknown arguments into _onEngineCreated So after everything is loaded, we can blame the user about wrong arguments. --- cura/CuraApplication.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 5cced81260..2d6254cc2e 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -385,6 +385,10 @@ class CuraApplication(QtApplication): self._plugin_registry.addSupportedPluginExtension("curaplugin", "Cura Plugin") def _onEngineCreated(self): + # Last check for unknown commandline arguments + parser = self.getCommandlineParser() + parser.parse_args() + self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider()) @pyqtProperty(bool) From 9210d38412598f413952614a45151f6ad7b95f74 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 21:31:41 +0100 Subject: [PATCH 11/37] Revert "CuraApplication: Getting argparser from Uranium" This reverts commit 8c74092f48d3b9322dbca3b9abf1c7bdbaf816a2. --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 2d6254cc2e..972074816b 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -630,7 +630,7 @@ class CuraApplication(QtApplication): @classmethod def preStartUp(cls): # Peek the arguments and look for the 'single-instance' flag. - parser = cls.getCommandlineParser() + parser = argparse.ArgumentParser(prog="cura") # pylint: disable=bad-whitespace CuraApplication.addCommandLineOptions(parser) cls.parseCommandLine() From 35ed042a72c5504a00973d10f47e904eb6163312 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 21:49:00 +0100 Subject: [PATCH 12/37] Revert "CuraApplication: Making use of Uranium commandline tools" This reverts commit 315efae53b68c9530bc2a2c15f46b876081cfd30. --- cura/CuraApplication.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 972074816b..4349ae792d 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -632,9 +632,11 @@ class CuraApplication(QtApplication): # Peek the arguments and look for the 'single-instance' flag. parser = argparse.ArgumentParser(prog="cura") # pylint: disable=bad-whitespace CuraApplication.addCommandLineOptions(parser) - cls.parseCommandLine() + # Important: It is important to keep this line here! + # In Uranium we allow to pass unknown arguments to the final executable or script. + parsed_command_line = vars(parser.parse_args()) - if cls.getCommandLineOption("single_instance"): + if parsed_command_line["single_instance"]: Logger.log("i", "Checking for the presence of an ready running Cura instance.") single_instance_socket = QLocalSocket() Logger.log("d", "preStartUp(): full server name: " + single_instance_socket.fullServerName()) @@ -653,8 +655,8 @@ class CuraApplication(QtApplication): payload = {"command": "focus"} single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ASCII")) - if len(cls.getCommandLineOption("file")) != 0: - for filename in cls.getCommandLineOption("file"): + if len(parsed_command_line["file"]) != 0: + for filename in parsed_command_line["file"]: payload = {"command": "open", "filePath": filename} single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ASCII")) @@ -664,7 +666,7 @@ class CuraApplication(QtApplication): single_instance_socket.flush() single_instance_socket.waitForDisconnected() return False - if cls.getCommandLineOption("Embedding"): + if parsed_command_line["Embedding"]: cls._splash_prevent = True return True From 044c538887acad4b4b5dbae37c2747df36a87d54 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 22:09:49 +0100 Subject: [PATCH 13/37] CuraApplication: Allow unknown arguments --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 4349ae792d..11ea6b3edb 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -634,7 +634,7 @@ class CuraApplication(QtApplication): CuraApplication.addCommandLineOptions(parser) # Important: It is important to keep this line here! # In Uranium we allow to pass unknown arguments to the final executable or script. - parsed_command_line = vars(parser.parse_args()) + parsed_command_line = vars(parser.known_args()[0]) if parsed_command_line["single_instance"]: Logger.log("i", "Checking for the presence of an ready running Cura instance.") From b098b167e51757294deddf3737bd1faf87a71caa Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 8 Dec 2017 22:31:04 +0100 Subject: [PATCH 14/37] Fixing name --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 11ea6b3edb..39da5868dd 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -634,7 +634,7 @@ class CuraApplication(QtApplication): CuraApplication.addCommandLineOptions(parser) # Important: It is important to keep this line here! # In Uranium we allow to pass unknown arguments to the final executable or script. - parsed_command_line = vars(parser.known_args()[0]) + parsed_command_line = vars(parser.parse_known_args()[0]) if parsed_command_line["single_instance"]: Logger.log("i", "Checking for the presence of an ready running Cura instance.") From 1a9c15204122073691744a58964bc8ed21fe966c Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 00:08:13 +0100 Subject: [PATCH 15/37] CuraApplication: Don't parse -h or --help before last check --- cura/CuraApplication.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 39da5868dd..069b80101b 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -386,7 +386,7 @@ class CuraApplication(QtApplication): def _onEngineCreated(self): # Last check for unknown commandline arguments - parser = self.getCommandlineParser() + parser = self.getCommandlineParser(with_help = True) parser.parse_args() self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider()) @@ -630,7 +630,8 @@ class CuraApplication(QtApplication): @classmethod def preStartUp(cls): # Peek the arguments and look for the 'single-instance' flag. - parser = argparse.ArgumentParser(prog="cura") # pylint: disable=bad-whitespace + parser = argparse.ArgumentParser(prog = "cura", + add_help = False) # pylint: disable=bad-whitespace CuraApplication.addCommandLineOptions(parser) # Important: It is important to keep this line here! # In Uranium we allow to pass unknown arguments to the final executable or script. From 61b6831e62598e8f91edd0365f8b373e2588422a Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 01:21:58 +0100 Subject: [PATCH 16/37] CuraApplication: Making it one line again Don't know why the pylint marker is here.. --- cura/CuraApplication.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 069b80101b..4af5e4f88a 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -630,8 +630,7 @@ class CuraApplication(QtApplication): @classmethod def preStartUp(cls): # Peek the arguments and look for the 'single-instance' flag. - parser = argparse.ArgumentParser(prog = "cura", - add_help = False) # pylint: disable=bad-whitespace + parser = argparse.ArgumentParser(prog = "cura", add_help = False) # pylint: disable=bad-whitespace CuraApplication.addCommandLineOptions(parser) # Important: It is important to keep this line here! # In Uranium we allow to pass unknown arguments to the final executable or script. From ab6508657da4482c74d65b10f7e0b95fd05927d2 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 02:13:31 +0100 Subject: [PATCH 17/37] Creating an argparser early and add a "debug" option Makes sure we don't log anything at the moment, when debug is passed. Otherwise early errors are not displayed and passed to log files. --- cura/CuraApplication.py | 7 ++++--- cura_app.py | 39 +++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 4af5e4f88a..040f601cfe 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -628,13 +628,14 @@ class CuraApplication(QtApplication): # This should be called directly before creating an instance of CuraApplication. # \returns \type{bool} True if the whole Cura app should continue running. @classmethod - def preStartUp(cls): + def preStartUp(cls, parser = None, parsed_command_line = {}): # Peek the arguments and look for the 'single-instance' flag. - parser = argparse.ArgumentParser(prog = "cura", add_help = False) # pylint: disable=bad-whitespace + if not parser: + parser = argparse.ArgumentParser(prog = "cura", add_help = False) # pylint: disable=bad-whitespace CuraApplication.addCommandLineOptions(parser) # Important: It is important to keep this line here! # In Uranium we allow to pass unknown arguments to the final executable or script. - parsed_command_line = vars(parser.parse_known_args()[0]) + parsed_command_line.update(vars(parser.parse_known_args()[0])) if parsed_command_line["single_instance"]: Logger.log("i", "Checking for the presence of an ready running Cura instance.") diff --git a/cura_app.py b/cura_app.py index fd36aa5a24..c719fe3e10 100755 --- a/cura_app.py +++ b/cura_app.py @@ -3,23 +3,34 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +import argparse import os import sys + from UM.Platform import Platform -def get_cura_dir_path(): - if Platform.isWindows(): - return os.path.expanduser("~/AppData/Roaming/cura/") - elif Platform.isLinux(): - return os.path.expanduser("~/.local/share/cura") - elif Platform.isOSX(): - return os.path.expanduser("~/Library/Logs/cura") +parser = argparse.ArgumentParser() +parser.add_argument('--debug', + action='store_true', + default = False + ) +known_args, unknown_args = parser.parse_known_args() +known_args = vars(known_args) -if hasattr(sys, "frozen"): - dirpath = get_cura_dir_path() - os.makedirs(dirpath, exist_ok = True) - sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w") - sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w") +if known_args["debug"]: + def get_cura_dir_path(): + if Platform.isWindows(): + return os.path.expanduser("~/AppData/Roaming/cura/") + elif Platform.isLinux(): + return os.path.expanduser("~/.local/share/cura") + elif Platform.isOSX(): + return os.path.expanduser("~/Library/Logs/cura") + + if hasattr(sys, "frozen"): + dirpath = get_cura_dir_path() + os.makedirs(dirpath, exist_ok = True) + sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w") + sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w") import platform import faulthandler @@ -78,8 +89,8 @@ faulthandler.enable() cura.Settings.CuraContainerRegistry.CuraContainerRegistry.getInstance() # This pre-start up check is needed to determine if we should start the application at all. -if not cura.CuraApplication.CuraApplication.preStartUp(): +if not cura.CuraApplication.CuraApplication.preStartUp(parser = parser, parsed_command_line = known_args): sys.exit(0) -app = cura.CuraApplication.CuraApplication.getInstance() +app = cura.CuraApplication.CuraApplication.getInstance(parser = parser, parsed_command_line = known_args) app.run() From bc7cb1491d735f48041384d7fc61f676477c65a2 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 02:13:47 +0100 Subject: [PATCH 18/37] Removing "Embedding" option again --- cura/CuraApplication.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 040f601cfe..a5d55773d7 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -574,7 +574,6 @@ class CuraApplication(QtApplication): parser.add_argument("file", nargs="*", help="Files to load after starting the application.") parser.add_argument("--single-instance", action="store_true", default=False) parser.add_argument("--headless", action = "store_true", default=False) - parser.add_argument("-Embedding", action="store_true", default=False) # Commandline option set my DCOM (Windows Automation) # Set up a local socket server which listener which coordinates single instances Curas and accepts commands. def _setUpSingleInstanceServer(self): @@ -667,8 +666,6 @@ class CuraApplication(QtApplication): single_instance_socket.flush() single_instance_socket.waitForDisconnected() return False - if parsed_command_line["Embedding"]: - cls._splash_prevent = True return True def run(self): From 2614c8a623155ce3b257d22fc9d95d108b18a2d9 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 02:40:46 +0100 Subject: [PATCH 19/37] Don't hook to CrashHandler, if we are debugging Getting an early crash here. Hope that one helps. --- cura_app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cura_app.py b/cura_app.py index c719fe3e10..a09b5b07dc 100755 --- a/cura_app.py +++ b/cura_app.py @@ -73,7 +73,8 @@ def exceptHook(hook_type, value, traceback): _crash_handler = CrashHandler(hook_type, value, traceback) _crash_handler.show() -sys.excepthook = exceptHook +if not known_args["debug"]: + sys.excepthook = exceptHook # Workaround for a race condition on certain systems where there # is a race condition between Arcus and PyQt. Importing Arcus From 63acaed0a5439d05c46c43b6f6db1ac105d1805a Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 02:52:51 +0100 Subject: [PATCH 20/37] Correcting if clause We don't want logs, when debugging. --- cura_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura_app.py b/cura_app.py index a09b5b07dc..627583d384 100755 --- a/cura_app.py +++ b/cura_app.py @@ -17,7 +17,7 @@ parser.add_argument('--debug', known_args, unknown_args = parser.parse_known_args() known_args = vars(known_args) -if known_args["debug"]: +if not known_args["debug"]: def get_cura_dir_path(): if Platform.isWindows(): return os.path.expanduser("~/AppData/Roaming/cura/") From e578014a2eb6e82f5b9db0b0bb7c805c955b6ae9 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 11:25:01 +0100 Subject: [PATCH 21/37] Passing the already parsed args --- cura/CuraApplication.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index a5d55773d7..37e5e1f2da 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -569,8 +569,8 @@ class CuraApplication(QtApplication): self._plugins_loaded = True @classmethod - def addCommandLineOptions(self, parser): - super().addCommandLineOptions(parser) + def addCommandLineOptions(self, parser, parsed_command_line = {}): + super().addCommandLineOptions(parser, parsed_command_line = parsed_command_line) parser.add_argument("file", nargs="*", help="Files to load after starting the application.") parser.add_argument("--single-instance", action="store_true", default=False) parser.add_argument("--headless", action = "store_true", default=False) @@ -631,7 +631,7 @@ class CuraApplication(QtApplication): # Peek the arguments and look for the 'single-instance' flag. if not parser: parser = argparse.ArgumentParser(prog = "cura", add_help = False) # pylint: disable=bad-whitespace - CuraApplication.addCommandLineOptions(parser) + CuraApplication.addCommandLineOptions(parser, parsed_command_line = parsed_command_line) # Important: It is important to keep this line here! # In Uranium we allow to pass unknown arguments to the final executable or script. parsed_command_line.update(vars(parser.parse_known_args()[0])) From 74be22e68223e38dfdbda144d25ac69470f1704b Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 11:26:04 +0100 Subject: [PATCH 22/37] Adding the application name Maybe it is possible to set this value later. Eg. in Uranium, so we can get the name from .getApplicationName(). --- cura_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura_app.py b/cura_app.py index 627583d384..9167829754 100755 --- a/cura_app.py +++ b/cura_app.py @@ -9,7 +9,7 @@ import sys from UM.Platform import Platform -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser(prog = "cura") parser.add_argument('--debug', action='store_true', default = False From f9554475be1363d235b6a4c1e8d62b0b00179d64 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 11:47:23 +0100 Subject: [PATCH 23/37] CuraApplication: Allow getting kwargs and pass them to super().__init__() --- cura/CuraApplication.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 37e5e1f2da..72ba21edab 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -127,7 +127,7 @@ class CuraApplication(QtApplication): # Cura will always show the Add Machine Dialog upon start. stacksValidationFinished = pyqtSignal() # Emitted whenever a validation is finished - def __init__(self): + def __init__(self, **kwargs): # this list of dir names will be used by UM to detect an old cura directory for dir_name in ["extruders", "machine_instances", "materials", "plugins", "quality", "user", "variants"]: @@ -207,9 +207,12 @@ class CuraApplication(QtApplication): self._additional_components = {} # Components to add to certain areas in the interface - super().__init__(name = "cura", version = CuraVersion, buildtype = CuraBuildType, + super().__init__(name = "cura", + version = CuraVersion, + buildtype = CuraBuildType, is_debug_mode = CuraDebugMode, - tray_icon_name = "cura-icon-32.png") + tray_icon_name = "cura-icon-32.png" + **kwargs) self.default_theme = "cura-light" From 97196190d612699420f67a142bf33875adb2d854 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 12:04:53 +0100 Subject: [PATCH 24/37] cura_app: Adding help text for debug --- cura_app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cura_app.py b/cura_app.py index 9167829754..118ea97c30 100755 --- a/cura_app.py +++ b/cura_app.py @@ -12,7 +12,9 @@ from UM.Platform import Platform parser = argparse.ArgumentParser(prog = "cura") parser.add_argument('--debug', action='store_true', - default = False + default = False, + help="Turn on the debug mode by setting this option." + ) ) known_args, unknown_args = parser.parse_known_args() known_args = vars(known_args) From bae6f2cfb56bead58ea8c6117b0f9f42d3edea1b Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 12:43:41 +0100 Subject: [PATCH 25/37] Typo --- cura_app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cura_app.py b/cura_app.py index 118ea97c30..3e91235d96 100755 --- a/cura_app.py +++ b/cura_app.py @@ -15,7 +15,6 @@ parser.add_argument('--debug', default = False, help="Turn on the debug mode by setting this option." ) - ) known_args, unknown_args = parser.parse_known_args() known_args = vars(known_args) From 3e775f71fd17cabd11048acabaee720fe42997a5 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 13:00:41 +0100 Subject: [PATCH 26/37] Typo --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 72ba21edab..fb6c4b451b 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -211,7 +211,7 @@ class CuraApplication(QtApplication): version = CuraVersion, buildtype = CuraBuildType, is_debug_mode = CuraDebugMode, - tray_icon_name = "cura-icon-32.png" + tray_icon_name = "cura-icon-32.png", **kwargs) self.default_theme = "cura-light" From c62b04089fd1fcafba002a4e18d650ea12754f53 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 15:43:05 +0100 Subject: [PATCH 27/37] Moving setActiveStage("PrepareStage") to initializeEngine() in UM --- cura/CuraApplication.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index fb6c4b451b..f43c10ebe4 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -729,7 +729,6 @@ class CuraApplication(QtApplication): run_headless = self.getCommandLineOption("headless", False) if not run_headless: self.initializeEngine() - controller.setActiveStage("PrepareStage") if run_headless or self._engine.rootObjects: self.closeSplash() From 4b8d05092d4cb0eca43bbe9d9402e893f2e2f040 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 15:56:06 +0100 Subject: [PATCH 28/37] Adding preRun and move last commandline argument check to it. --- cura/CuraApplication.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f43c10ebe4..db03d7440a 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -388,10 +388,6 @@ class CuraApplication(QtApplication): self._plugin_registry.addSupportedPluginExtension("curaplugin", "Cura Plugin") def _onEngineCreated(self): - # Last check for unknown commandline arguments - parser = self.getCommandlineParser(with_help = True) - parser.parse_args() - self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider()) @pyqtProperty(bool) @@ -671,7 +667,14 @@ class CuraApplication(QtApplication): return False return True + def preRun(self): + # Last check for unknown commandline arguments + parser = self.getCommandlineParser(with_help = True) + parser.parse_args() + def run(self): + self.preRun() + self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Setting up scene...")) self._setUpSingleInstanceServer() From 37cf78487ef8a433239ff2ade03f9ea97ecbf2ea Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 15:56:52 +0100 Subject: [PATCH 29/37] headless+invidible: It is all about being hidden So don't show any gui. --- cura/CuraApplication.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index db03d7440a..f0bdcff3e3 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -729,11 +729,11 @@ class CuraApplication(QtApplication): self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml")) self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles)) - run_headless = self.getCommandLineOption("headless", False) - if not run_headless: + run_without_gui = self.getCommandLineOption("headless", False) or self.getCommandLineOption("headless", False) + if not run_without_gui: self.initializeEngine() - if run_headless or self._engine.rootObjects: + if run_without_gui or self._engine.rootObjects: self.closeSplash() for file_name in self.getCommandLineOption("file", []): From 904f7c53ccd9edf98c4a929c97a1a6e1599c904e Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 16:00:34 +0100 Subject: [PATCH 30/37] Code style --- cura_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura_app.py b/cura_app.py index 3e91235d96..af4e1f2a48 100755 --- a/cura_app.py +++ b/cura_app.py @@ -13,7 +13,7 @@ parser = argparse.ArgumentParser(prog = "cura") parser.add_argument('--debug', action='store_true', default = False, - help="Turn on the debug mode by setting this option." + help = "Turn on the debug mode by setting this option." ) known_args, unknown_args = parser.parse_known_args() known_args = vars(known_args) From 7e7303a7e3a37c71a94728c7dd7c5f27dd223d96 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 16:00:56 +0100 Subject: [PATCH 31/37] Code style --- cura/CuraApplication.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f0bdcff3e3..03429fb690 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -1431,7 +1431,8 @@ class CuraApplication(QtApplication): # If a model is to small then it will not contain any points if offset_shape_arr is None and hull_shape_arr is None: Message(self._i18n_catalog.i18nc("@info:status", "The selected model was too small to load."), - title=self._i18n_catalog.i18nc("@info:title", "Warning")).show() + title=self._i18n_catalog.i18nc("@info:title", "Warning") + ).show() return # Step is for skipping tests to make it a lot faster. it also makes the outcome somewhat rougher From 8e89c1b36144d4861f58093de15b6f2a480964c8 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 17:40:06 +0100 Subject: [PATCH 32/37] No comment on this.. --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 03429fb690..d6b8d416cd 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -729,7 +729,7 @@ class CuraApplication(QtApplication): self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml")) self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles)) - run_without_gui = self.getCommandLineOption("headless", False) or self.getCommandLineOption("headless", False) + run_without_gui = self.getCommandLineOption("headless", False) or self.getCommandLineOption("invisible", False) if not run_without_gui: self.initializeEngine() From bcc31fb19b378eb2f024ef194b4324a0a0d2baa3 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 22:26:52 +0100 Subject: [PATCH 33/37] Tell early parser not to add help --- cura_app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cura_app.py b/cura_app.py index af4e1f2a48..56ae51aaa3 100755 --- a/cura_app.py +++ b/cura_app.py @@ -9,7 +9,8 @@ import sys from UM.Platform import Platform -parser = argparse.ArgumentParser(prog = "cura") +parser = argparse.ArgumentParser(prog = "cura", + add_help = False) parser.add_argument('--debug', action='store_true', default = False, From b4aed1da22de53306ef7fa812a3380503b2f18a7 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 22:27:15 +0100 Subject: [PATCH 34/37] Simplify getting known args --- cura_app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cura_app.py b/cura_app.py index 56ae51aaa3..b5844055ab 100755 --- a/cura_app.py +++ b/cura_app.py @@ -16,8 +16,7 @@ parser.add_argument('--debug', default = False, help = "Turn on the debug mode by setting this option." ) -known_args, unknown_args = parser.parse_known_args() -known_args = vars(known_args) +known_args = vars(parser.parse_known_args()[0]) if not known_args["debug"]: def get_cura_dir_path(): From f1d5bc38dcf07802827ca426cf05614239601a29 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sat, 9 Dec 2017 23:01:26 +0100 Subject: [PATCH 35/37] Adding help arguments manually .. and also print and exit as it normally does, when enabled. --- cura/CuraApplication.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index d6b8d416cd..7b067f452c 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -669,8 +669,16 @@ class CuraApplication(QtApplication): def preRun(self): # Last check for unknown commandline arguments - parser = self.getCommandlineParser(with_help = True) - parser.parse_args() + parser = self.getCommandlineParser() + parser.add_argument("--help", "-h", + action='store_true', + default = False, + help = "Show this help message and exit." + ) + parsed_args = vars(parser.parse_args()) # This won't allow unknown arguments + if parsed_args["help"]: + parser.print_help() + sys.exit(0) def run(self): self.preRun() From 1cd107965c320a4d3f6cd88a960b0a7a5124b635 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sun, 10 Dec 2017 00:39:20 +0100 Subject: [PATCH 36/37] Close all windows, if there is no main window --- cura/CuraApplication.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 7b067f452c..fc675e549b 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -401,7 +401,11 @@ class CuraApplication(QtApplication): @pyqtSlot() def closeApplication(self): Logger.log("i", "Close application") - self._main_window.close() + main_window = self.getMainWindow() + if main_window is not None: + main_window.close() + else: + self.closeAllWindows() ## A reusable dialogbox # From 79cb1a1293f4e6874f596288e611e91d5814c153 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sun, 10 Dec 2017 01:08:06 +0100 Subject: [PATCH 37/37] closeAllWindows seems to take no effect - use exit instead Looks like it does not work, because there was never a window or any other window on top of QApplication. .exit() should let us out of the main loop. --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index fc675e549b..abe1ddf374 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -405,7 +405,7 @@ class CuraApplication(QtApplication): if main_window is not None: main_window.close() else: - self.closeAllWindows() + self.exit(0) ## A reusable dialogbox #