Skip to content

Commit

Permalink
Addon Manager: Improve darkmode check
Browse files Browse the repository at this point in the history
  • Loading branch information
chennes committed Feb 24, 2022
1 parent 0ccca56 commit ef4fdc7
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/Mod/AddonManager/addonmanager_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,42 +268,41 @@ def repair_git_repo(repo_url: str, clone_dir: str) -> None:
repo.head.reset("--hard")


def is_darkmode() -> bool:
"""Heuristics to determine if we are in a darkmode stylesheet"""
if hasattr(QtWidgets.QApplication.instance(), "styleSheet"):
if "dark" in QtWidgets.QApplication.instance().styleSheet().lower():
return True
return False


def warning_color_string() -> str:
"""A shade of red, adapted to darkmode if possible. Targets a minimum 7:1 contrast ratio."""

warningColorString = "rgb(255,0,0)"
if hasattr(QtWidgets.QApplication.instance(), "styleSheet"):
# Qt 5.9 doesn't give a QApplication instance, so can't give the stylesheet info
if "dark" in QtWidgets.QApplication.instance().styleSheet().lower():
warningColorString = "rgb(255,105,97)"
else:
warningColorString = "rgb(215,0,21)"
if is_darkmode():
warningColorString = "rgb(255,105,97)"
else:
warningColorString = "rgb(215,0,21)"
return warningColorString


def bright_color_string() -> str:
"""A shade of green, adapted to darkmode if possible. Targets a minimum 7:1 contrast ratio."""

brightColorString = "rgb(0,255,0)"
if hasattr(QtWidgets.QApplication.instance(), "styleSheet"):
# Qt 5.9 doesn't give a QApplication instance, so can't give the stylesheet info
if "dark" in QtWidgets.QApplication.instance().styleSheet().lower():
brightColorString = "rgb(48,219,91)"
else:
brightColorString = "rgb(36,138,61)"
if is_darkmode():
brightColorString = "rgb(48,219,91)"
else:
brightColorString = "rgb(36,138,61)"
return brightColorString


def attention_color_string() -> str:
"""A shade of orange, adapted to darkmode if possible. Targets a minimum 7:1 contrast ratio."""

attentionColorString = "rgb(255,149,0)"
if hasattr(QtWidgets.QApplication.instance(), "styleSheet"):
# Qt 5.9 doesn't give a QApplication instance, so can't give the stylesheet info
if "dark" in QtWidgets.QApplication.instance().styleSheet().lower():
attentionColorString = "rgb(255,179,64)"
else:
attentionColorString = "rgb(255,149,0)"
if is_darkmode():
attentionColorString = "rgb(255,179,64)"
else:
attentionColorString = "rgb(255,149,0)"
return attentionColorString


Expand Down

0 comments on commit ef4fdc7

Please sign in to comment.