From 6e6c9b98f773e0eb86d6c24e46e83d6a7209bec2 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 13 Feb 2020 00:36:30 +0100 Subject: [PATCH] Additional unparsed command line options are assumed to be a project path to open --- nw/__init__.py | 7 ++++++- nw/config.py | 3 ++- nw/guimain.py | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nw/__init__.py b/nw/__init__.py index 245b9043..02b62656 100644 --- a/nw/__init__.py +++ b/nw/__init__.py @@ -126,14 +126,18 @@ def main(sysArgs=None): confPath = None testMode = False qtStyle = "Fusion" + cmdOpen = None # Parse Options try: - inOpts, inArgs = getopt.getopt(sysArgs,shortOpt,longOpt) + inOpts, inRemain = getopt.getopt(sysArgs,shortOpt,longOpt) except getopt.GetoptError: print(helpMsg) sys.exit(2) + if len(inRemain) > 0: + cmdOpen = inRemain[0] + for inOpt, inArg in inOpts: if inOpt in ("-h","--help"): print(helpMsg) @@ -165,6 +169,7 @@ def main(sysArgs=None): # Set Config Options CONFIG.showGUI = not testMode CONFIG.debugInfo = debugLevel < logging.INFO + CONFIG.cmdOpen = cmdOpen # Set Logging if showTime: debugStr = timeStr+debugStr diff --git a/nw/config.py b/nw/config.py index 281fe863..3aa6a254 100644 --- a/nw/config.py +++ b/nw/config.py @@ -41,6 +41,7 @@ class Config: self.appHandle = nw.__package__.lower() self.showGUI = True self.debugInfo = False + self.cmdOpen = None # Set Paths self.confPath = None @@ -57,7 +58,7 @@ class Config: self.iconPath = None # Set default values - self.confChanged = False + self.confChanged = False ## General self.guiTheme = "default" diff --git a/nw/guimain.py b/nw/guimain.py index bfc67115..a1b88781 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -182,6 +182,10 @@ class GuiMain(QMainWindow): logger.debug("GUI initialisation complete") + if self.mainConf.cmdOpen is not None: + logger.debug("Opening project from additional command line option") + self.openProject(self.mainConf.cmdOpen) + return def clearGUI(self):