Some clean up and refactoring

This commit is contained in:
Donnie
2020-06-26 11:39:28 -04:00
parent 2dc1b3ec43
commit d775b8baa0
5 changed files with 59 additions and 82 deletions

View File

@@ -1,15 +1,9 @@
import json
import os
from shutil import copyfile
import dcs
import qt_ui.uiconstants as CONST
from userdata import persistency
global __theme_index
global __theme_name
global __theme_file
global __theme_icons
THEME_PREFERENCES_FILE_PATH = "liberation_theme.json"
@@ -29,61 +23,52 @@ def init():
__theme_index = pref_data["theme_index"]
print(__theme_index)
set_theme_index(__theme_index)
set_theme_file()
save_theme_config()
print("file setting theme index to " + str(__theme_index))
except:
# is this necessary?
set_theme_index(DEFAULT_THEME_INDEX)
print("except setting theme index to " + str(__theme_index))
else:
# is this necessary?
set_theme_index(DEFAULT_THEME_INDEX)
print("else setting theme index to " + str(__theme_index))
# set theme index then use save_theme_config to save to file
def set_theme_index(x):
global __theme_index
__theme_index = x
# get theme index to reference other theme properties(themeName, themeFile, themeIcons)
def get_theme_index():
global __theme_index
return __theme_index
# get or set current theme index number
def set_theme_name(x):
global __theme_name
__theme_name = str(x)
# get theme name based on current index
def get_theme_name():
global __theme_name
return __theme_name
# get or set current theme icons based on the theme name
def set_theme_icons():
global __theme_icons
__theme_icons = CONST.THEMES[get_theme_name()]["themeIcons"]
theme_name = CONST.THEMES[get_theme_index()]['themeName']
return theme_name
# get theme icon sub-folder name based on current index
def get_theme_icons():
theme_icons = CONST.THEMES[get_theme_index()]['themeIcons']
return str(theme_icons)
# get or set theme from json file
def set_theme_file():
# get theme stylesheet css based on current index
def get_theme_css_file():
theme_file = CONST.THEMES[get_theme_index()]['themeFile']
global __theme_file
__theme_file = theme_file
return str(theme_file)
# save current theme index to json file
def save_theme_config():
pref_data = {
"theme_index": get_theme_index()
}
with(open(THEME_PREFERENCES_FILE_PATH, "w")) as prefs:
prefs.write(json.dumps(pref_data))
def get_theme_file():
global __theme_file
return str(__theme_file)