mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
UI Theme switcher working
This commit is contained in:
parent
cdf8c3b6e5
commit
d3d5160861
1
liberation_theme.json
Normal file
1
liberation_theme.json
Normal file
@ -0,0 +1 @@
|
||||
{"theme_index": 1}
|
||||
@ -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):
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -40,6 +40,9 @@ QMenuBar::item:pressed {
|
||||
background: #1D2731;
|
||||
}
|
||||
|
||||
QLabel{
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
|
||||
/*QWidget*/
|
||||
|
||||
3
resources/stylesheets/windows-style.css
Normal file
3
resources/stylesheets/windows-style.css
Normal file
@ -0,0 +1,3 @@
|
||||
/*
|
||||
windows basis styles
|
||||
*/
|
||||
89
userdata/liberation_theme.py
Normal file
89
userdata/liberation_theme.py
Normal file
@ -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)
|
||||
Loading…
x
Reference in New Issue
Block a user