Skip to content

Commit

Permalink
add support for <b> <i> and <span style=""></span> on the custom cloc…
Browse files Browse the repository at this point in the history
…k format (fix #1210)
  • Loading branch information
marticliment committed Jul 6, 2023
1 parent 3560505 commit 12b6b3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
29 changes: 10 additions & 19 deletions elevenclock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class Clock(QWidget):
clockFormat: str = ""
settingsEnvironment: str = ""
currentTaskbarHwnd: int = 0
baseHtmlFontTag: str = ""

LastCapturedBackgroundColor: int = -1
LastCapturedForegroundColor: str = ""
Expand Down Expand Up @@ -819,31 +820,21 @@ 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", "Segoe UI Variable Display Semib") for element in self.fontfamilies]
if self.fontfamilies != []:
self.font.setFamilies(self.fontfamilies)
if lang["locale"] in ("zh_TW", "zh_CN", "ko"):
self.font.setWeight(QFont.Weight.Normal)
else:
self.font.setWeight(QFont.Weight.DemiBold)
else:
self.font.fromString(self.customFont)
self.font.setLetterSpacing(QFont.PercentageSpacing, 100)
self.label.setFont(self.font)
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]
if self.fontfamilies != []:
self.font.setFamilies(self.fontfamilies)
else:
self.font.fromString(self.customFont)
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.setFont(self.font)
self.label.bgopacity = .5

self.label.setFont(self.font)

if self.getSettings("UseCustomFontColor"):
print("🟡 Using custom font color:", self.getSettingsValue('UseCustomFontColor'))
self.lastTheme = -1
Expand Down Expand Up @@ -1020,7 +1011,7 @@ def loadTimeFormat(self):
clockFormat = f"<p style=\"line-height:{customLineHeight}\"><span>"+clockFormat.replace("\n", "<br>").replace(" ", "")+"</span></p>"
except Exception as e:
report(e)

print("🔵 Loaded date time format:", clockFormat.replace("\n", "\\n"), f" (clock {self.index}")
self.clockFormat = clockFormat
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions elevenclock/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ def setCustomFont(v):
<li>{_("Any text can be placed here. To place items such as date and time, please use the 1989 C standard. Check the format codes on the following link:")} <a href="https://strftime.org" style="color:{f"rgb({getColors()[2 if isWindowDark() else 4]})"}">{_("Python date and time formats")}</a>
<li>{_("To disable the zero-padding effect, add a # in between the % and the code: non-zero-padded hours would be %#H, and zero-padded hours would be %H")}</li>
<li>{_("Use the nonation {%H+1} to specify offsets. Replace %H with the desired value and +1 for a positive or negative number (+n or -n, respectively, for a <i>n</i> offset), representing the offset.")}</li>
<li>{_('You can use HTML tags to set bold, italics or change the color of a piece of text through the &#60;span style="color: red"&#62;&#60;/span&#62; tag')}</li>
<li>{_("Click on Apply to apply and preview the format")}</li></ul>
{_("If you don't understand what is happening, please uncheck the checkbox over the text area")}
"""
Expand Down

0 comments on commit 12b6b3e

Please sign in to comment.