Updated config class to split the initialisation into a function
This commit is contained in:
+2
-2
@@ -62,10 +62,10 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
# Load the main config as a global object
|
# Load the main config as a global object
|
||||||
CONFIG = Config()
|
CONFIG = Config()
|
||||||
|
CONFIG.initConfig()
|
||||||
|
|
||||||
def main(sysArgs):
|
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
|
# Valid Input Options
|
||||||
|
|||||||
+42
-25
@@ -6,7 +6,7 @@
|
|||||||
This class reads and store the main preferences of the application
|
This class reads and store the main preferences of the application
|
||||||
|
|
||||||
File History:
|
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):
|
def __init__(self):
|
||||||
|
|
||||||
# Set Application Variables
|
# Set Application Variables
|
||||||
self.appName = nw.__package__
|
self.appName = nw.__package__
|
||||||
self.appHandle = nw.__package__.lower()
|
self.appHandle = nw.__package__.lower()
|
||||||
self.showGUI = True
|
self.showGUI = True
|
||||||
self.debugGUI = False
|
self.debugGUI = False
|
||||||
|
|
||||||
# Set Paths
|
# Set Paths
|
||||||
self.confPath = user_config_dir(self.appHandle)
|
self.confPath = None
|
||||||
self.confFile = self.appHandle+".conf"
|
self.confFile = None
|
||||||
self.homePath = path.expanduser("~")
|
self.homePath = None
|
||||||
self.appPath = path.dirname(__file__)
|
self.appPath = None
|
||||||
self.guiPath = path.join(self.appPath,"gui")
|
self.guiPath = None
|
||||||
self.themePath = path.join(self.appPath,"themes")
|
self.themePath = None
|
||||||
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)
|
|
||||||
|
|
||||||
# Set default values
|
# Set default values
|
||||||
self.confChanged = False
|
self.confChanged = False
|
||||||
@@ -81,13 +74,8 @@ class Config:
|
|||||||
|
|
||||||
self.spellLanguage = "en_GB"
|
self.spellLanguage = "en_GB"
|
||||||
|
|
||||||
# Check if config file exists
|
# Path
|
||||||
if path.isfile(path.join(self.confPath,self.confFile)):
|
self.recentList = [""]*10
|
||||||
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()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -95,6 +83,35 @@ class Config:
|
|||||||
# Actions
|
# 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):
|
def loadConfig(self):
|
||||||
|
|
||||||
logger.debug("Loading config file")
|
logger.debug("Loading config file")
|
||||||
|
|||||||
Reference in New Issue
Block a user