Updated config class to split the initialisation into a function

This commit is contained in:
Veronica K. B. Olsen
2019-05-12 11:59:47 +02:00
parent fe05761fe7
commit ea34884d8c
2 changed files with 44 additions and 27 deletions
+2 -2
View File
@@ -62,10 +62,10 @@ 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.
"""Parses command line, sets up logging, and launches main GUI.
"""
# Valid Input Options
+42 -25
View File
@@ -6,7 +6,7 @@
This class reads and store the main preferences of the application
File History:
Created: 2018-0+-22 [0.0.1]
Created: 2018-09-22 [0.0.1]
"""
@@ -28,25 +28,18 @@ class Config:
def __init__(self):
# Set Application Variables
self.appName = nw.__package__
self.appHandle = nw.__package__.lower()
self.showGUI = True
self.debugGUI = False
self.appName = nw.__package__
self.appHandle = nw.__package__.lower()
self.showGUI = True
self.debugGUI = False
# Set Paths
self.confPath = user_config_dir(self.appHandle)
self.confFile = self.appHandle+".conf"
self.homePath = path.expanduser("~")
self.appPath = path.dirname(__file__)
self.guiPath = path.join(self.appPath,"gui")
self.themePath = path.join(self.appPath,"themes")
self.recentList = [""]*10
# If config folder does not exist, make it.
# This assumes that the os config folder itself exists.
# TODO: This does not work on Windows
if not path.isdir(self.confPath):
mkdir(self.confPath)
self.confPath = None
self.confFile = None
self.homePath = None
self.appPath = None
self.guiPath = None
self.themePath = None
# Set default values
self.confChanged = False
@@ -81,13 +74,8 @@ class Config:
self.spellLanguage = "en_GB"
# Check if config file exists
if path.isfile(path.join(self.confPath,self.confFile)):
self.loadConfig()
# Save a copy of the default config if no file exists
if not path.isfile(path.join(self.confPath,self.confFile)):
self.saveConfig()
# Path
self.recentList = [""]*10
return
@@ -95,6 +83,35 @@ class Config:
# Actions
##
def initConfig(self, confPath=None):
if confPath is None:
self.confPath = user_config_dir(self.appHandle)
else:
self.confPath = confPath
self.confFile = self.appHandle+".conf"
self.homePath = path.expanduser("~")
self.appPath = path.dirname(__file__)
self.guiPath = path.join(self.appPath,"gui")
self.themePath = path.join(self.appPath,"themes")
# If config folder does not exist, make it.
# This assumes that the os config folder itself exists.
# TODO: This does not work on Windows
if not path.isdir(self.confPath):
mkdir(self.confPath)
# Check if config file exists
if path.isfile(path.join(self.confPath,self.confFile)):
# If it exists, load it
self.loadConfig()
else:
# If it does not exist, save a copy of the defaults
self.saveConfig()
return
def loadConfig(self):
logger.debug("Loading config file")