Skip to content

Commit

Permalink
added logo to analog clock
Browse files Browse the repository at this point in the history
  • Loading branch information
saschaludwig committed Dec 25, 2022
1 parent 1fed274 commit e074f7f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.

## [TBA]
## [0.9.5]
### Changed
- fixed textclock when hour == 12
- fixed wrong default font size for slogan
- refactored text clock code
- fixed crash when using API to configure boolean fields
- API: you can now use colors in web notation (#00FF00) and hex notation (0x00FF00)
- fixed slogan font in settings
- fixed analog clock style

### Added
- french localization for textclock
Expand All @@ -17,6 +18,8 @@ All notable changes to this project will be documented in this file.
- IPs can be automatically replaced with custom text after 10s
- API commands for added functions
- New Hotkey "I" to display IPs for 10 seconds
- added option to select between no/separate/combined seconds display
- added logo to analog clock

## [0.9.4]
### Changed
Expand Down
61 changes: 47 additions & 14 deletions clockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import time as pytime

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QRectF
from PyQt5.QtGui import QColor


Expand All @@ -103,8 +104,9 @@ def __init__(self, parent=None):
self.digiDigitColor = QtGui.QColor(50, 50, 255, 255)

# analog mode colors
self.hourColor = QtGui.QColor(200, 200, 200, 255)
self.hourColor = QtGui.QColor(190, 190, 190, 255)
self.minuteColor = QtGui.QColor(220, 220, 220, 255)
self.secondColor = QtGui.QColor(200, 200, 200, 255)
self.circleColor = QtGui.QColor(220, 220, 220, 255)

self.image_path = ""
Expand Down Expand Up @@ -268,22 +270,45 @@ def paintEvent(self, event):
def paint_analog(self, painter):
time = self.time
# analog clock mode

# add logo
image_max_h = 40
image_max_w = 100
image = self.image
image_w = image.width()
image_h = image.height()

if image_w > 0 and image_h > 1:
painter.save()

# logo position and width without seconds
paint_x = 0
paint_y = 50

if image_w > image_h:
# calculate height from aspect ratio
paint_w = image_max_w
paint_h = (float(image_h) / float(image_w)) * paint_w
else:
# calculate width from aspect ratio
paint_h = image_max_h
paint_w = (float(image_h) / float(image_w)) * paint_h

painter.drawImage(QtCore.QRectF(paint_x - (paint_w / 2), paint_y - (paint_h / 2), paint_w, paint_h), image)
painter.restore()

painter.setPen(QtCore.Qt.NoPen)
painter.setBrush(self.hourColor)
# set hour hand length and minute hand length
hhl = -65 # -50
mhl = -85 # -75
hhl = -70 # -50
mhl = -80 # -75
shl = -85 # -75

# draw hour hand
painter.save()
painter.rotate(30.0 * (time.hour() + time.minute() / 60.0))
painter.drawRoundedRect(-4, 4, 8, hhl, 4.0, 4.0)
painter.restore()

# draw second hand
painter.save()
painter.rotate(6.0 * time.second())
painter.drawRoundedRect(-1, 1, 2, shl, 1.0, 1.0)
painter.drawEllipse(-4, hhl, 8, 8)
painter.drawRect(-4, 4, 8, hhl)
painter.restore()

painter.setPen(self.hourColor)
Expand All @@ -296,11 +321,18 @@ def paint_analog(self, painter):
painter.setBrush(self.minuteColor)

# draw minute hand
sizefactor = 1.3
painter.save()
painter.rotate(6.0 * (time.minute() + time.second() / 60.0))
painter.drawRoundedRect(-4 / sizefactor, 4 / sizefactor, 8 / sizefactor, mhl, 4.0 / sizefactor,
4.0 / sizefactor)
painter.drawEllipse(-3, mhl, 6, 6)
painter.drawRect(-3, 3, 6, mhl)
painter.restore()

# draw second hand
painter.setBrush(self.secondColor)
painter.save()
painter.rotate(6.0 * time.second())
painter.drawEllipse(-1, shl, 2, 2)
painter.drawRect(-1, 1, 2, shl)
painter.restore()

# draw center circle
Expand Down Expand Up @@ -605,10 +637,11 @@ def draw_digit(painter, digit_start_pos_x=0.0, digit_start_pos_y=0.0, value=8, d
widget = ClockWidget()
widget.setStyleSheet("background-color:black;")
widget.resize(500, 500)
widget.set_clock_mode(1)
widget.set_clock_mode(0)
widget.set_am_pm(False)
widget.set_show_seconds(True)
widget.set_static_colon(False)
widget.set_one_line_time(False)
widget.set_logo("images/astrastudio_transparent.png")
widget.show()
sys.exit(app.exec_())
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
versionString = "0.9.5beta2"
versionString = "0.9.5"

0 comments on commit e074f7f

Please sign in to comment.