Skip to content

Commit

Permalink
Add seconds as option
Browse files Browse the repository at this point in the history
  • Loading branch information
odest committed Jun 5, 2024
1 parent 5c032df commit b31c759
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
27 changes: 26 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def initVar(self):
self.backgroundCustomGifCount = self.configData[self.user]["background"]["customGifCount"]
self.backgroundCustomGifs = self.configData[self.user]["background"]["customGifs"]

self.secondVisibility = self.configData[self.user]["text"]["secondVisibility"]
self.blinkingColonVisibility = self.configData[self.user]["text"]["blinkingColonVisibility"]
self.blinkingColonAnimation = self.configData[self.user]["text"]["blinkingColonAnimation"]
self.clockFontSize = self.configData[self.user]["text"]["clockFontSize"]
Expand Down Expand Up @@ -113,6 +114,10 @@ def initWidgets(self):
self.minuteText = QLabel(self)
self.minuteText.setAlignment(Qt.AlignCenter)

self.secondText = QLabel(self)
self.secondText.setAlignment(Qt.AlignCenter)
self.secondText.setVisible(self.secondVisibility)

self.topLayer = QLabel(self)
self.topLayer.setScaledContents(True)
self.topLayer.setGeometry(0, 0, self.windowWidth, self.windowHeight)
Expand Down Expand Up @@ -165,7 +170,7 @@ def initWidgets(self):

self.clockTimer = QTimer(self)
self.clockTimer.timeout.connect(self.updateTime)
self.clockTimer.start(500)
self.clockTimer.start(1000)

self.sideGrips = [SideGrip(self, Qt.LeftEdge), SideGrip(self, Qt.TopEdge), SideGrip(self, Qt.RightEdge), SideGrip(self, Qt.BottomEdge), ]
self.cornerGrips = [QSizeGrip(self) for i in range(4)]
Expand All @@ -180,11 +185,13 @@ def setWidgets(self):
self.fontFamily = QFontDatabase.applicationFontFamilies(fontID)[0]

self.clockFont = QFont(self.fontFamily, self.clockFontSize)
self.secondFont = QFont(self.fontFamily, int(self.clockFontSize / 2))
self.dateFont = QFont(self.fontFamily, self.dateFontSize)

currentTime = QTime.currentTime()
hour = str(currentTime.hour()).zfill(2)
minute = str(currentTime.minute()).zfill(2)
second = str(currentTime.second()).zfill(2)

currentDate = datetime.now()
dateString = currentDate.strftime("%d/%m/%Y")
Expand All @@ -194,6 +201,7 @@ def setWidgets(self):
self.blinkingColonText.setText(":")
self.hourText.setText(hour)
self.minuteText.setText(minute)
self.secondText.setText(second)

self.updateFontMetrics()
self.updateWidgets()
Expand Down Expand Up @@ -253,6 +261,14 @@ def updateFontMetrics(self):
self.minuteYCoord = self.textYCoord
self.minuteText.setGeometry(self.minuteXCoord, self.minuteYCoord, self.minuteWidth, self.minuteHeight)

self.secondMetrics = QFontMetrics(self.secondFont)
self.secondWidth = self.secondMetrics.horizontalAdvance("99")
self.secondHeight = self.secondMetrics.height()
self.secondText.setFixedSize(self.secondWidth, self.secondHeight)
self.secondXCoord = int(self.minuteXCoord + self.minuteWidth)
self.secondYCoord = int((self.textYCoord) + (self.secondHeight / 1.2))
self.secondText.setGeometry(self.secondXCoord, self.secondYCoord, self.secondWidth, self.secondHeight)


def updateAnimation(self):
""" update background gif frame animation """
Expand All @@ -270,6 +286,7 @@ def updateTime(self):
currentTime = QTime.currentTime()
hour = str(currentTime.hour()).zfill(2)
minute = str(currentTime.minute()).zfill(2)
second = str(currentTime.second()).zfill(2)

self.hourText.setText(hour)
self.minuteText.setText(minute)
Expand All @@ -289,6 +306,10 @@ def updateTime(self):
self.blinkingColonText.setText(":")
self.blinkingColonVisibility = True

if self.secondVisibility:
self.secondText.setText(second)
self.secondText.setStyleSheet(f"background-color: transparent; color: rgba{self.textColor};")


def updateGrips(self):
self.setContentsMargins(*[self._gripSize] * 4)
Expand Down Expand Up @@ -523,6 +544,9 @@ def resizeEvent(self, event):
self.dateText.setScaledContents(True)
self.dateText.setFont(self.dateFont)

self.secondFont = QFont(self.fontFamily, int(self.clockFontSize / 2))
self.secondText.setFont(self.secondFont)

self.updateFontMetrics()

buttonWidth = event.size().width() / 10
Expand Down Expand Up @@ -641,6 +665,7 @@ def save(self):
self.configData[self.user]["background"]["customGifCount"] = self.backgroundCustomGifCount
self.configData[self.user]["background"]["customGifs"] = self.backgroundCustomGifs

self.configData[self.user]["text"]["secondVisibility"] = self.secondVisibility
self.configData[self.user]["text"]["blinkingColonVisibility"] = self.blinkingColonVisibility
self.configData[self.user]["text"]["blinkingColonAnimation"] = self.blinkingColonAnimation
self.configData[self.user]["text"]["clockFontSize"] = self.clockFontSize
Expand Down
2 changes: 2 additions & 0 deletions src/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"text": {
"blinkingColonAnimation": false,
"blinkingColonVisibility": true,
"secondVisibility": false,
"color": {
"Gif": [
0,
Expand Down Expand Up @@ -243,6 +244,7 @@
"text": {
"blinkingColonAnimation": false,
"blinkingColonVisibility": true,
"secondVisibility": false,
"color": {
"Gif": [
0,
Expand Down
14 changes: 14 additions & 0 deletions src/menu/settingsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def initWidgets(self):
self.staysOnTopCard.switch.checkedChanged.connect(lambda i: self.switchEvent(i, "Stays on Top", self.staysOnTopCard.switch))
self.mainVBoxLayout.addWidget(self.staysOnTopCard)

self.secondCard = ListCard("Show Second", self)
self.secondCard.switch.setChecked(self.parent.secondVisibility)
self.secondCard.switch.setText("")
self.secondCard.switch.checkedChanged.connect(lambda i: self.switchEvent(i, "Show Second", self.secondCard.switch))
self.mainVBoxLayout.addWidget(self.secondCard)

self.blinkingColonCard = ListCard("Blinking Colon", self)
self.blinkingColonCard.switch.setChecked(self.parent.blinkingColonAnimation)
self.blinkingColonCard.switch.setText("")
Expand Down Expand Up @@ -64,6 +70,8 @@ def updateToolTips(self):
self.parent.setToolTip(self.taskbarCard.switch, 'Set whether the widget logo appears on the taskbar')
self.parent.setToolTip(self.staysOnTopCard.title, 'Set whether the widget stays on top of other apps')
self.parent.setToolTip(self.staysOnTopCard.switch, 'Set whether the widget stays on top of other apps')
self.parent.setToolTip(self.secondCard.title, 'Set second visibility')
self.parent.setToolTip(self.secondCard.switch, 'Set second visibility')
self.parent.setToolTip(self.blinkingColonCard.title, 'Set whether the colon between hour and minute is visible')
self.parent.setToolTip(self.blinkingColonCard.switch, 'Set whether the colon between hour and minute is visible')
self.parent.setToolTip(self.advancedOptionsCard.title, 'Set whether to open advanced configuration settings')
Expand All @@ -85,6 +93,9 @@ def switchEvent(self, isChecked: bool, value, switch):
self.parent.staysOnTop = True
self.parent.updateStaysOnTopEvent(self.parent)
self.parent.updateStaysOnTopEvent(self.menu)
elif value == "Show Second":
self.parent.secondVisibility = True
self.parent.secondText.setVisible(self.parent.secondVisibility)
elif value == "Blinking Colon":
self.parent.blinkingColonAnimation = True
elif value == "Advanced Options":
Expand All @@ -104,6 +115,9 @@ def switchEvent(self, isChecked: bool, value, switch):
self.parent.staysOnTop = False
self.parent.updateStaysOnTopEvent(self.parent)
self.parent.updateStaysOnTopEvent(self.menu)
elif value == "Show Second":
self.parent.secondVisibility = False
self.parent.secondText.setVisible(self.parent.secondVisibility)
elif value == "Blinking Colon":
self.parent.blinkingColonAnimation = False
elif value == "Advanced Options":
Expand Down
17 changes: 17 additions & 0 deletions src/menu/textPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def updateTextColor(self, color):
self.parent.textColor = (r, g, b, self.parent.textColor[3])
self.parent.hourText.setStyleSheet(f"background-color: transparent; color: rgba{self.parent.textColor};")
self.parent.minuteText.setStyleSheet(f"background-color: transparent; color: rgba{self.parent.textColor};")
self.parent.secondText.setStyleSheet(f"background-color: transparent; color: rgba{self.parent.textColor};")
self.parent.blinkingColonText.setStyleSheet(f'background-color: transparent; color: rgba{self.parent.textColor};')
self.parent.dateText.setStyleSheet(f'background-color: transparent; color: rgba{self.parent.textColor};')
self.colorPickerMiniButton.setStyleSheet("PushButton {background: rgba%s; border-radius: 5px;}" % str(self.parent.textColor))
Expand Down Expand Up @@ -188,8 +189,10 @@ def sliderEvent(self, whichWidget, slider, label):
if whichWidget == "Size":
self.parent.clockFontSize = value
self.parent.clockFont = QFont(self.parent.fontFamily, self.parent.clockFontSize)
self.parent.secondFont = QFont(self.parent.fontFamily, int(self.parent.clockFontSize / 2))
self.parent.hourText.setFont(self.parent.clockFont)
self.parent.minuteText.setFont(self.parent.clockFont)
self.parent.secondText.setFont(self.parent.secondFont)
self.parent.blinkingColonText.setFont(self.parent.clockFont)

self.parent.updateFontMetrics()
Expand All @@ -207,6 +210,12 @@ def sliderEvent(self, whichWidget, slider, label):
self.parent.hourText.move(self.parent.hourXCoord, self.parent.hourYCoord)
self.parent.minuteText.move(self.parent.minuteXCoord, self.parent.minuteYCoord)

if self.parent.secondVisibility:
self.parent.secondXCoord = int(self.parent.minuteXCoord + self.parent.minuteWidth)
self.parent.secondYCoord = int((self.parent.textYCoord) + (self.parent.secondHeight / 1.2))
self.parent.secondText.move(self.parent.secondXCoord, self.parent.secondYCoord)


elif whichWidget == "Y Coord":
self.parent.textYCoord = value

Expand All @@ -217,12 +226,18 @@ def sliderEvent(self, whichWidget, slider, label):
self.parent.hourText.move(self.parent.hourXCoord, self.parent.hourYCoord)
self.parent.minuteText.move(self.parent.minuteXCoord, self.parent.minuteYCoord)

if self.parent.secondVisibility:
self.parent.secondYCoord = int((self.parent.textYCoord) + (self.parent.secondHeight / 1.2))
self.parent.secondText.move(self.parent.secondXCoord, self.parent.secondYCoord)


elif whichWidget == "Opacity":
self.parent.textOpacity = value
self.parent.textColor = self.parent.textColor[:-1] + (int(value * 2.55),)
color = f"rgba{str(self.parent.textColor[:-1] + (value * 0.01,))}"
self.parent.hourText.setStyleSheet(f"background-color : transparent; color: {color};")
self.parent.minuteText.setStyleSheet(f"background-color : transparent; color: {color};")
self.parent.secondText.setStyleSheet(f"background-color : transparent; color: {color};")
self.parent.blinkingColonText.setStyleSheet(f"background-color : transparent; color: {color};")
self.colorPickerMiniButton.setStyleSheet("PushButton {background: %s; border-radius: 5px;}" % color)

Expand Down Expand Up @@ -291,9 +306,11 @@ def comboBoxSelect(self, text):
self.parent.fontFamily = text
self.parent.font = self.fontDict[text]
self.parent.clockFont = QFont(text, self.parent.clockFontSize)
self.parent.secondFont = QFont(text, int(self.parent.clockFontSize / 2))
self.parent.dateFont = QFont(text, self.parent.dateFontSize)
self.parent.hourText.setFont(self.parent.clockFont)
self.parent.minuteText.setFont(self.parent.clockFont)
self.parent.secondText.setFont(self.parent.secondFont)
self.parent.dateText.setFont(self.parent.dateFont)
self.parent.blinkingColonText.setFont(self.parent.clockFont)
self.parent.updateFontMetrics()
Expand Down

0 comments on commit b31c759

Please sign in to comment.