diff --git a/liberation_theme.json b/liberation_theme.json new file mode 100644 index 00000000..7fa657ab --- /dev/null +++ b/liberation_theme.json @@ -0,0 +1 @@ +{"theme_index": 1} \ No newline at end of file diff --git a/qt_ui/main.py b/qt_ui/main.py index 6bbf6b81..09b33d59 100644 --- a/qt_ui/main.py +++ b/qt_ui/main.py @@ -1,6 +1,8 @@ from userdata import logging_config # Logging setup +from userdata.liberation_theme import get_theme_file + VERSION_STRING = "2.0RC7" logging_config.init_logging(VERSION_STRING) @@ -18,18 +20,17 @@ from qt_ui.windows.GameUpdateSignal import GameUpdateSignal from qt_ui.windows.QLiberationWindow import QLiberationWindow from qt_ui.windows.preferences.QLiberationFirstStartWindow import QLiberationFirstStartWindow from userdata import liberation_install, persistency +from userdata import liberation_theme, persistency if __name__ == "__main__": app = QApplication(sys.argv) + liberation_theme.init(); css = "" - with open("./resources/stylesheets/style-dcs.css") as stylesheet: + with open("./resources/stylesheets/"+get_theme_file()) as stylesheet: app.setStyleSheet(stylesheet.read()) - - - # Inject custom payload in pydcs framework custom_payloads = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..\\resources\\customized_payloads") if os.path.exists(custom_payloads): diff --git a/qt_ui/uiconstants.py b/qt_ui/uiconstants.py index be107c02..33fbbb71 100644 --- a/qt_ui/uiconstants.py +++ b/qt_ui/uiconstants.py @@ -19,6 +19,24 @@ URLS : Dict[str, str] = { LABELS_OPTIONS = ["Full", "Abbreviated", "Dot Only", "Off"] SKILL_OPTIONS = ["Average", "Good", "High", "Excellent"] +# new themes can be added here +THEMES: Dict[int, Dict[str, str]] = { + 0: {'themeName': 'Windows', + 'themeFile': 'windows-style.css', + 'themeIcons': 'medium', + }, + + 1: {'themeName': 'DCS World', + 'themeFile': 'style-dcs.css', + 'themeIcons': 'light', + }, + + 2: {'themeName': 'Blue', + 'themeFile': 'style.css', + 'themeIcons': 'dark', + }, +} + COLORS: Dict[str, QColor] = { "dark_red": QColor(140, 20, 20), "red": QColor(200, 80, 80), diff --git a/qt_ui/windows/preferences/QLiberationPreferences.py b/qt_ui/windows/preferences/QLiberationPreferences.py index eba000fe..755c0d18 100644 --- a/qt_ui/windows/preferences/QLiberationPreferences.py +++ b/qt_ui/windows/preferences/QLiberationPreferences.py @@ -1,11 +1,16 @@ import os from PySide2 import QtWidgets +from PySide2.QtCore import QFile from PySide2.QtGui import Qt from PySide2.QtWidgets import QFrame, QLineEdit, QGridLayout, QVBoxLayout, QLabel, QPushButton, \ - QFileDialog, QMessageBox, QDialog + QFileDialog, QMessageBox, QDialog, QComboBox, QApplication +import qt_ui.uiconstants as CONST +import sys -from userdata import liberation_install +import userdata +from userdata import liberation_install, liberation_theme +from userdata.liberation_theme import get_theme_file, set_theme_name, get_theme_index, set_theme_index class QLiberationPreferences(QFrame): @@ -28,9 +33,14 @@ class QLiberationPreferences(QFrame): self.browse_saved_game.clicked.connect(self.on_browse_saved_games) self.browse_install_dir = QPushButton("Browse...") self.browse_install_dir.clicked.connect(self.on_browse_installation_dir) + self.themeSelect = QComboBox() + + for x, y in CONST.THEMES.items(): + self.themeSelect.addItem(y['themeName']) self.initUi() + def initUi(self): main_layout = QVBoxLayout() layout = QGridLayout() @@ -40,6 +50,9 @@ class QLiberationPreferences(QFrame): layout.addWidget(QLabel("DCS installation directory:"), 2, 0, alignment=Qt.AlignLeft) layout.addWidget(self.edit_dcs_install_dir, 3, 0, alignment=Qt.AlignRight) layout.addWidget(self.browse_install_dir, 3, 1, alignment=Qt.AlignRight) + layout.addWidget(QLabel("Theme (Requires Restart)"), 4, 0) + layout.addWidget(self.themeSelect, 4, 1, alignment=Qt.AlignRight) + self.themeSelect.setCurrentIndex(get_theme_index()) main_layout.addLayout(layout) main_layout.addStretch() @@ -63,6 +76,7 @@ class QLiberationPreferences(QFrame): print("Applying changes") self.saved_game_dir = self.edit_saved_game_dir.text() self.dcs_install_dir = self.edit_dcs_install_dir.text() + set_theme_index(self.themeSelect.currentIndex()) if not os.path.isdir(self.saved_game_dir): error_dialog = QMessageBox.critical(self, "Wrong DCS Saved Games directory.", @@ -87,6 +101,7 @@ class QLiberationPreferences(QFrame): liberation_install.setup(self.saved_game_dir, self.dcs_install_dir) liberation_install.save_config() + liberation_theme.set_theme_file() return True diff --git a/resources/stylesheets/style-dcs.css b/resources/stylesheets/style-dcs.css index d5c5be60..6a2ea53c 100644 --- a/resources/stylesheets/style-dcs.css +++ b/resources/stylesheets/style-dcs.css @@ -40,6 +40,9 @@ QMenuBar::item:pressed { background: #1D2731; } +QLabel{ +font-weight:bold; +} /*QWidget*/ diff --git a/resources/stylesheets/windows-style.css b/resources/stylesheets/windows-style.css new file mode 100644 index 00000000..cbf5010f --- /dev/null +++ b/resources/stylesheets/windows-style.css @@ -0,0 +1,3 @@ +/* +windows basis styles +*/ diff --git a/userdata/liberation_theme.py b/userdata/liberation_theme.py new file mode 100644 index 00000000..3bbfc317 --- /dev/null +++ b/userdata/liberation_theme.py @@ -0,0 +1,89 @@ +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" + +DEFAULT_THEME_INDEX = 0 + + +def init(): + global __theme_index + + __theme_index = DEFAULT_THEME_INDEX + print("init setting theme index to " + str(__theme_index)) + + if os.path.isfile(THEME_PREFERENCES_FILE_PATH): + try: + with(open(THEME_PREFERENCES_FILE_PATH)) as prefs: + pref_data = json.loads(prefs.read()) + __theme_index = pref_data["theme_index"] + print(__theme_index) + set_theme_index(__theme_index) + set_theme_file() + print("file setting theme index to " + str(__theme_index)) + except: + set_theme_index(DEFAULT_THEME_INDEX) + print("except setting theme index to " + str(__theme_index)) + else: + set_theme_index(DEFAULT_THEME_INDEX) + print("else setting theme index to " + str(__theme_index)) + + +def set_theme_index(x): + global __theme_index + __theme_index = x + + +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) + + +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"] + + +def get_theme_icons(): + global __theme_icons + return str(__theme_icons) + + +# get or set theme from json file +def set_theme_file(): + theme_file = CONST.THEMES[get_theme_index()]['themeFile'] + global __theme_file + __theme_file = theme_file + + 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)