Skip to content

Commit

Permalink
fix an issue where clock's custom font would be broken (fix #1217, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Jul 8, 2023
1 parent 5bad23e commit a193850
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"python.analysis.extraPaths": [
"./elevenclock",
"./elevenclock/lang"
],
"cSpell.enableFiletypes": [
"!python"
]
}
36 changes: 18 additions & 18 deletions elevenclock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,9 @@ def __init__(self, dpix: float, dpiy: float, screen: QScreen, index: int, isCove
styleSheetString = self.makeLabelStyleSheet(0, 0, 0, 0, f"transparent")
self.label.setStyleSheet(styleSheetString)
else:
customFont = self.getSettingsValue("UseCustomFont")
if customFont == "":
self.customFont = self.getSettingsValue("UseCustomFont")

if self.customFont == "":
if lang["locale"] == "ko":
self.fontfamilies = ["Malgun Gothic", "Segoe UI Variable Text", "sans-serif"]
elif lang["locale"] == "zh_TW":
Expand All @@ -804,11 +805,24 @@ def __init__(self, dpix: float, dpiy: float, screen: QScreen, index: int, isCove
self.fontfamilies = ["Microsoft YaHei UI", "Segoe UI Variable Text", "sans-serif"]
else:
self.fontfamilies = ["Segoe UI Variable Display", "sans-serif"]
self.font.setPointSizeF(9.3)

DISABLE_SEMIBOLD = not self.getSettings("CustomClockStringsDisabled") and "<b>" in self.getSettingsValue("CustomClockStrings")
if isTaskbarDark():
self.fontfamilies = [element.replace("Segoe UI Variable Display", f"Segoe UI Variable Display{'' if DISABLE_SEMIBOLD else ' Semib'}") for element in self.fontfamilies]
self.font.setFamilies(self.fontfamilies if self.fontfamilies != [] else self.customFont)
self.font.setLetterSpacing(QFont.PercentageSpacing, 110 if DISABLE_SEMIBOLD else 100)
self.label.bgopacity = .1
else:
self.fontfamilies = [element.replace("Segoe UI Variable Display Semib", "Segoe UI Variable Display") for element in self.fontfamilies]
self.font.setFamilies(self.fontfamilies if self.fontfamilies != [] else self.customFont)
self.font.setWeight(QFont.Weight.ExtraLight)
self.font.setLetterSpacing(QFont.PercentageSpacing, 110)
self.label.bgopacity = .5
else:
self.fontfamilies = []
self.customFont = customFont
self.font.fromString(self.customFont)

self.label.setFont(self.font)
customSize = self.getSettingsValue("UseCustomFontSize")
if customSize == "":
self.font.setPointSize(9)
Expand All @@ -820,20 +834,6 @@ def __init__(self, dpix: float, dpiy: float, screen: QScreen, index: int, isCove
except Exception as e:
self.font.setPointSize(9)
report(e)

DISABLE_SEMIBOLD = not self.getSettings("CustomClockStringsDisabled") and "<b>" in self.getSettingsValue("CustomClockStrings")
if isTaskbarDark():
self.fontfamilies = [element.replace("Segoe UI Variable Display", f"Segoe UI Variable Display{'' if DISABLE_SEMIBOLD else ' Semib'}") for element in self.fontfamilies]
self.font.setFamilies(self.fontfamilies if self.fontfamilies != [] else self.customFont)
self.font.setLetterSpacing(QFont.PercentageSpacing, 110 if DISABLE_SEMIBOLD else 100)
self.label.bgopacity = .1
else:
self.fontfamilies = [element.replace("Segoe UI Variable Display Semib", "Segoe UI Variable Display") for element in self.fontfamilies]
self.font.setFamilies(self.fontfamilies if self.fontfamilies != [] else self.customFont)
self.font.setWeight(QFont.Weight.ExtraLight)
self.font.setLetterSpacing(QFont.PercentageSpacing, 110)
self.label.bgopacity = .5
self.label.setFont(self.font)

if self.getSettings("UseCustomFontColor"):
print("🟡 Using custom font color:", self.getSettingsValue('UseCustomFontColor'))
Expand Down
4 changes: 2 additions & 2 deletions elevenclock/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ def setSettings(s: str, v: bool, r: bool = True, thread = False, env: str = ""):
except Exception as e:
report(e)

def getSettingsValue(s: str, env: str = ""):
def getSettingsValue(s: str, env: str = "") -> str:
settingsName = (env+s).replace("\\", "").replace("/", "")
try:
try:
return globals.settingsCache[settingsName+"Value"]
return str(globals.settingsCache[settingsName+"Value"])
except KeyError:
with open(os.path.join(os.path.join(os.path.expanduser("~"), ".elevenclock"), settingsName), "r") as sf:
v = sf.read()
Expand Down

0 comments on commit a193850

Please sign in to comment.