UI Theme switcher working

This commit is contained in:
Donnie
2020-06-26 00:39:04 -04:00
parent cdf8c3b6e5
commit d3d5160861
7 changed files with 136 additions and 6 deletions

View File

@@ -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):

View File

@@ -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),

View File

@@ -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("<strong>DCS installation directory:</strong>"), 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("<strong>Theme (Requires Restart)</strong>"), 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