forked from NinjaCheetah/NUSGet
Allow overriding the color scheme with the THEME environment variable
This commit is contained in:
parent
f29964be53
commit
4a08bd47cd
16
NUSGet.py
16
NUSGet.py
@ -656,10 +656,18 @@ if __name__ == "__main__":
|
||||
# Load Fusion because that's objectively the best base theme, and then load the fancy stylesheet on top to make
|
||||
# NUSGet look nice and pretty.
|
||||
app.setStyle("fusion")
|
||||
if is_dark_theme():
|
||||
stylesheet = open(os.path.join(os.path.dirname(__file__), "resources", "style_dark.qss")).read()
|
||||
else:
|
||||
stylesheet = open(os.path.join(os.path.dirname(__file__), "resources", "style_light.qss")).read()
|
||||
theme_sheet = "style_dark.qss"
|
||||
try:
|
||||
# Check for an environment variable overriding the theme. This is mostly for theme testing but would also allow
|
||||
# you to force a theme.
|
||||
if os.environ["THEME"].lower() == "light":
|
||||
theme_sheet = "style_light.qss"
|
||||
except KeyError:
|
||||
if is_dark_theme():
|
||||
theme_sheet = "style_dark.qss"
|
||||
else:
|
||||
theme_sheet = "style_light.qss"
|
||||
stylesheet = open(os.path.join(os.path.dirname(__file__), "resources", theme_sheet)).read()
|
||||
image_path_prefix = pathlib.Path(os.path.join(os.path.dirname(__file__), "resources")).resolve().as_posix()
|
||||
stylesheet = stylesheet.replace("{IMAGE_PREFIX}", image_path_prefix)
|
||||
app.setStyleSheet(stylesheet)
|
||||
|
@ -54,6 +54,7 @@ def connect_label_to_checkbox(label, checkbox):
|
||||
checkbox.toggle()
|
||||
label.mousePressEvent = toggle_checkbox
|
||||
|
||||
|
||||
def connect_is_enabled_to_checkbox(items, chkbox):
|
||||
for item in items:
|
||||
if chkbox.isChecked():
|
||||
@ -61,6 +62,7 @@ def connect_is_enabled_to_checkbox(items, chkbox):
|
||||
else:
|
||||
item.setEnabled(False)
|
||||
|
||||
|
||||
def check_nusget_updates(app, current_version: str, progress_callback=None) -> str | None:
|
||||
# Simple function to make a request to the GitHub API and then check if the latest available version is newer.
|
||||
gh_api_request = requests.get(url="https://api.github.com/repos/NinjaCheetah/NUSGet/releases/latest", stream=True)
|
||||
@ -80,6 +82,7 @@ def check_nusget_updates(app, current_version: str, progress_callback=None) -> s
|
||||
progress_callback.emit(app.translate("MainWindow", "\n\nYou're running the latest release of NUSGet."))
|
||||
return None
|
||||
|
||||
|
||||
def get_config_file() -> pathlib.Path:
|
||||
config_dir = pathlib.Path(os.path.join(
|
||||
os.environ.get('APPDATA') or
|
||||
@ -90,11 +93,13 @@ def get_config_file() -> pathlib.Path:
|
||||
config_dir.mkdir(exist_ok=True)
|
||||
return config_dir.joinpath("config.json")
|
||||
|
||||
|
||||
def save_config(config_data: dict) -> None:
|
||||
config_file = get_config_file()
|
||||
print(f"writing data: {config_data}")
|
||||
open(config_file, "w").write(json.dumps(config_data))
|
||||
|
||||
|
||||
def update_setting(config_data: dict, setting: str, value: any) -> None:
|
||||
config_data[setting] = value
|
||||
save_config(config_data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user