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

@ -17,16 +17,16 @@ from qt_ui import uiconstants
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
from userdata import liberation_install, persistency, liberation_theme
if __name__ == "__main__":
app = QApplication(sys.argv)
# init the theme and load the stylesheet based on the theme index
liberation_theme.init();
css = ""
with open("./resources/stylesheets/"+liberation_theme.get_theme_file()) as stylesheet:
with open("./resources/stylesheets/"+liberation_theme.get_theme_css_file()) as stylesheet:
app.setStyleSheet(stylesheet.read())
# Inject custom payload in pydcs framework

View File

@ -22,7 +22,7 @@ SKILL_OPTIONS = ["Average", "Good", "High", "Excellent"]
# new themes can be added here
THEMES: Dict[int, Dict[str, str]] = {
0: {'themeName': 'Windows',
0: {'themeName': 'Vanilla',
'themeFile': 'windows-style.css',
'themeIcons': 'medium',
},
@ -32,10 +32,6 @@ THEMES: Dict[int, Dict[str, str]] = {
'themeIcons': 'light',
},
2: {'themeName': 'Blue',
'themeFile': 'style.css',
'themeIcons': 'dark',
},
}
COLORS: Dict[str, QColor] = {
@ -96,9 +92,9 @@ def load_icons():
ICONS["ship"] = QPixmap("./resources/ui/ground_assets/ship.png")
ICONS["ship_blue"] = QPixmap("./resources/ui/ground_assets/ship_blue.png")
ICONS["Generator"] = QPixmap("./resources/ui/misc/generator.png")
ICONS["Missile"] = QPixmap("./resources/ui/misc/missile.png")
ICONS["Cheat"] = QPixmap("./resources/ui/misc/cheat.png")
ICONS["Generator"] = QPixmap("./resources/ui/misc/"+get_theme_icons()+"/generator.png")
ICONS["Missile"] = QPixmap("./resources/ui/misc/"+get_theme_icons()+"/missile.png")
ICONS["Cheat"] = QPixmap("./resources/ui/misc/"+get_theme_icons()+"/cheat.png")
ICONS["TaskCAS"] = QPixmap("./resources/ui/tasks/cas.png")
ICONS["TaskCAP"] = QPixmap("./resources/ui/tasks/cap.png")

View File

@ -10,7 +10,7 @@ import sys
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
from userdata.liberation_theme import get_theme_index, set_theme_index
class QLiberationPreferences(QFrame):
@ -34,13 +34,10 @@ class QLiberationPreferences(QFrame):
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.themeSelect.addItem(y['themeName']) for x, y in CONST.THEMES.items()]
self.initUi()
def initUi(self):
main_layout = QVBoxLayout()
layout = QGridLayout()
@ -92,7 +89,8 @@ class QLiberationPreferences(QFrame):
error_dialog.exec_()
return False
if not os.path.isdir(os.path.join(self.dcs_install_dir, "Scripts")) and os.path.isfile(os.path.join(self.dcs_install_dir, "bin", "DCS.exe")):
if not os.path.isdir(os.path.join(self.dcs_install_dir, "Scripts")) and os.path.isfile(
os.path.join(self.dcs_install_dir, "bin", "DCS.exe")):
error_dialog = QMessageBox.critical(self, "Wrong DCS installation directory.",
self.dcs_install_dir + " is not a valid DCS installation directory",
QMessageBox.StandardButton.Ok)
@ -101,8 +99,5 @@ class QLiberationPreferences(QFrame):
liberation_install.setup(self.saved_game_dir, self.dcs_install_dir)
liberation_install.save_config()
liberation_theme.set_theme_file()
liberation_theme.save_theme_config()
return True

View File

@ -82,7 +82,7 @@ QPushButton:hover {
cursor:pointer;
}
/*btn-success = a green button*/
/*btn-primary*/
QPushButton[style="btn-primary"]{
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,stop:0 #A4B3B9, stop:1 #85989D);
border: 1px solid #97A9A9;
@ -93,9 +93,13 @@ QPushButton[style="btn-primary"]{
font-weight:bold;
text-transform:uppercase;
}
QPushButton[style="btn-primary"]:hover{
background: #85989D;
}
/*btn-success = a green button*/
QPushButton[style="btn-success"]{
/*highlighted buttons*/
QPushButton[style="btn-success"] , QPushButton[style="start-button"]{
background-color:#82A466;
color: white;
cursor:pointer;
@ -105,27 +109,12 @@ QPushButton[style="btn-success"]{
text-transform:uppercase;
}
QPushButton[style="btn-success"]:hover{
background-color:#5C863F;
padding: 5px;
border-radius:2px;
cursor: pointer;
}
/*mission start button*/
QPushButton[style="start-button"]{
background:qlineargradient(x1:0, y1:0, x2:1, y2:1,stop:0 #82A466, stop:1 #5C863F);
border-radius:2px;
border: none;
text-transform: uppercase;
text-weight: bold;
padding: 8px 30px;
padding: 8px 30px;
}
QPushButton[style="start-button"]:hover{
QPushButton[style="btn-success"]:hover , QPushButton[style="start-button"]:hover{
background:#5C863F;
}
QPushButton[style="btn-danger"]{
@ -145,13 +134,12 @@ QPushButton[style="btn-danger"]:hover{
/*QLabel*/
QLabel{
border: none;
border: none;
}
QLabel[style="base-title"]{
font-size: 24px;
font-color: #ccc;
/*border: 1px solid #ccc;*/
}
QLabel[style="icon-plane"]{
@ -163,68 +151,74 @@ QLabel[style="icon-plane"]{
color:white;
}
QLabel[style="bordered"]{
border: 1px solid black;
}
QLabel[style="BARCAP"]{
border: 1px solid black;
background-color: #445299;
color:white;
padding:2px 6px;
}
QLabel[style="TARCAP"]{
border: 1px solid black;
background-color: #445299;
color:white;
padding:2px 6px;
}
QLabel[style="CAP"]{
border: 1px solid black;
background-color: #445299;
color:white;
padding:2px 6px;
}
QLabel[style="INTERCEPTION"]{
border: 1px solid black;
background-color: #7752bc;
color:white;
padding:2px 6px;
}
QLabel[style="CAS"]{
border: 1px solid black;
background-color: #ab2244;
color:white;
padding:2px 6px;
}
QLabel[style="BAI"]{
border: 1px solid black;
background-color: #ab2244;
color:white;
padding:2px 6px;
}
QLabel[style="ANTISHIP"]{
border: 1px solid black;
background-color: #ab2244;
color:white;
padding:2px 6px;
}
QLabel[style="STRIKE"]{
border: 1px solid black;
background-color: #ab2244;
color:white;
padding:2px 6px;
}
QLabel[style="DEAD"]{
border: 1px solid black;
background-color: #cc8844;
color:white;
padding:2px 6px;
}
QLabel[style="SEAD"]{
border: 1px solid black;
background-color: #aa7744;
color:white;
padding:2px 6px;
}
/*QGroupBox these are the sections that look like fieldsets*/
@ -311,7 +305,6 @@ QComboxBox {
padding:10px;
margin:10px;
border:1px solid #3B4656;
background: #1D2731;
color: #fff;
}
QComboBox:editable {
@ -319,14 +312,13 @@ QComboBox:editable {
}
QComboBox:!editable{
background: #1D2731;
/*background: #1D2731;*/
}
QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
padding: 10px;
border:none;
background: #1D2731;
color: #fff;
height: 20px;
}
@ -336,13 +328,18 @@ QComboBox::down-arrow {
}
QComboBox QAbstractItemView {
padding: 10px;
padding: 10px;
border:1px solid #3B4656;
background: #465C74;
}
QSpinBox{
/*TODO:style this*/
}
QLineEdit{
padding: 6px;
border:1px solid #3B4656;
@ -382,7 +379,11 @@ QTableWidget {
/*helper modifiers*/
*[style="no-border"] {
border:none;
border:none;
}
*[style="bordered"]{
border: 1px solid #1D2731;
}

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)