mirror of
https://github.com/NinjaCheetah/NUSGet.git
synced 2025-06-06 18:41:02 -04:00
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
|
# 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.
|
# NUSGet look nice and pretty.
|
||||||
app.setStyle("fusion")
|
app.setStyle("fusion")
|
||||||
if is_dark_theme():
|
theme_sheet = "style_dark.qss"
|
||||||
stylesheet = open(os.path.join(os.path.dirname(__file__), "resources", "style_dark.qss")).read()
|
try:
|
||||||
else:
|
# Check for an environment variable overriding the theme. This is mostly for theme testing but would also allow
|
||||||
stylesheet = open(os.path.join(os.path.dirname(__file__), "resources", "style_light.qss")).read()
|
# 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()
|
image_path_prefix = pathlib.Path(os.path.join(os.path.dirname(__file__), "resources")).resolve().as_posix()
|
||||||
stylesheet = stylesheet.replace("{IMAGE_PREFIX}", image_path_prefix)
|
stylesheet = stylesheet.replace("{IMAGE_PREFIX}", image_path_prefix)
|
||||||
app.setStyleSheet(stylesheet)
|
app.setStyleSheet(stylesheet)
|
||||||
|
@ -54,6 +54,7 @@ def connect_label_to_checkbox(label, checkbox):
|
|||||||
checkbox.toggle()
|
checkbox.toggle()
|
||||||
label.mousePressEvent = toggle_checkbox
|
label.mousePressEvent = toggle_checkbox
|
||||||
|
|
||||||
|
|
||||||
def connect_is_enabled_to_checkbox(items, chkbox):
|
def connect_is_enabled_to_checkbox(items, chkbox):
|
||||||
for item in items:
|
for item in items:
|
||||||
if chkbox.isChecked():
|
if chkbox.isChecked():
|
||||||
@ -61,6 +62,7 @@ def connect_is_enabled_to_checkbox(items, chkbox):
|
|||||||
else:
|
else:
|
||||||
item.setEnabled(False)
|
item.setEnabled(False)
|
||||||
|
|
||||||
|
|
||||||
def check_nusget_updates(app, current_version: str, progress_callback=None) -> str | None:
|
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.
|
# 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)
|
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."))
|
progress_callback.emit(app.translate("MainWindow", "\n\nYou're running the latest release of NUSGet."))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_config_file() -> pathlib.Path:
|
def get_config_file() -> pathlib.Path:
|
||||||
config_dir = pathlib.Path(os.path.join(
|
config_dir = pathlib.Path(os.path.join(
|
||||||
os.environ.get('APPDATA') or
|
os.environ.get('APPDATA') or
|
||||||
@ -90,11 +93,13 @@ def get_config_file() -> pathlib.Path:
|
|||||||
config_dir.mkdir(exist_ok=True)
|
config_dir.mkdir(exist_ok=True)
|
||||||
return config_dir.joinpath("config.json")
|
return config_dir.joinpath("config.json")
|
||||||
|
|
||||||
|
|
||||||
def save_config(config_data: dict) -> None:
|
def save_config(config_data: dict) -> None:
|
||||||
config_file = get_config_file()
|
config_file = get_config_file()
|
||||||
print(f"writing data: {config_data}")
|
print(f"writing data: {config_data}")
|
||||||
open(config_file, "w").write(json.dumps(config_data))
|
open(config_file, "w").write(json.dumps(config_data))
|
||||||
|
|
||||||
|
|
||||||
def update_setting(config_data: dict, setting: str, value: any) -> None:
|
def update_setting(config_data: dict, setting: str, value: any) -> None:
|
||||||
config_data[setting] = value
|
config_data[setting] = value
|
||||||
save_config(config_data)
|
save_config(config_data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user