From edab608c3b5d32e19b4cbe6fcce4c00482fe8f32 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sun, 12 May 2019 13:29:41 +0200 Subject: [PATCH] Some changes to core classes and files to support the test suite --- nw/__init__.py | 7 ++++--- nw/config.py | 15 ++++++++++----- nw/gui/winmain.py | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/nw/__init__.py b/nw/__init__.py index 8f5c06dc..a1755d6c 100644 --- a/nw/__init__.py +++ b/nw/__init__.py @@ -62,7 +62,6 @@ logger = logging.getLogger(__name__) # Load the main config as a global object CONFIG = Config() -CONFIG.initConfig() def main(sysArgs): """Parses command line, sets up logging, and launches main GUI. @@ -149,10 +148,10 @@ def main(sysArgs): showGUI = False elif inOpt in ("-D","--debuggui"): debugLevel = logging.DEBUG - debugStr = "{name:>22}:{lineno:<4d} {levelname:8} {message:}" + debugStr = "{name:>20}:{lineno:<4d} {levelname:8} {message:}" debugGUI = True - # Set GUI options + # Set Config Options CONFIG.showGUI = showGUI CONFIG.debugGUI = debugGUI @@ -179,6 +178,8 @@ def main(sysArgs): logger.setLevel(debugLevel) + CONFIG.initConfig(confPath) + nwApp = QApplication([]) nwGUI = NovelWriter() exit(nwApp.exec_()) diff --git a/nw/config.py b/nw/config.py index 2555c58c..254c06df 100644 --- a/nw/config.py +++ b/nw/config.py @@ -88,6 +88,7 @@ class Config: if confPath is None: self.confPath = user_config_dir(self.appHandle) else: + logger.info("Setting config from alternative path: %s" % confPath) self.confPath = confPath self.confFile = self.appHandle+".conf" @@ -110,13 +111,13 @@ class Config: # If it does not exist, save a copy of the defaults self.saveConfig() - return + return True def loadConfig(self): logger.debug("Loading config file") confParser = configparser.ConfigParser() - confParser.readfp(open(path.join(self.confPath,self.confFile))) + confParser.read_file(open(path.join(self.confPath,self.confFile))) # Get options @@ -231,10 +232,14 @@ class Config: confParser.set(cnfSec,"recent%d" % i, str(self.recentList[i])) # Write config file - confParser.write(open(path.join(self.confPath,self.confFile),"w")) - self.confChanged = False + try: + confParser.write(open(path.join(self.confPath,self.confFile),"w")) + self.confChanged = False + except Exception as e: + logger.error("Could not save config file") + return False - return + return True def unpackList(self, inStr, listLen, listDefault, castTo=int): inData = inStr.split(",") diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index a6125afe..e0b6693b 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -106,7 +106,8 @@ class GuiMain(QMainWindow): self.asDocTimer.timeout.connect(self._autoSaveDocument) self.asDocTimer.start() - self.show() + if self.mainConf.showGUI: + self.show() logger.debug("GUI initialisation complete")