Skip to content

Commit

Permalink
Add text below the clock if shown. Text is left in ramdisk /dev/shm/c…
Browse files Browse the repository at this point in the history
…lock.txt
  • Loading branch information
paddywwoof committed Aug 13, 2024
1 parent 796ee85 commit 5d40c55
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/picframe/config/configuration_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ viewer:
show_clock: False # default=False, True shows clock overlay. False does not show clock overlay
clock_justify: "R" # default="R", clock justification L, C, or R
clock_text_sz: 120 # default=120, clock character size
clock_format: "%I:%M" # default="%I:%M", strftime format for clock string
clock_format: "%-I:%M" # default="%-I:%M", strftime format for clock string
clock_opacity: 1.0 # default=1.0 (0.0-1.0), alpha value of clock overlay
clock_top_bottom: "T" # default="T" ("T", "B"), whether to display clock at top or bottom of screen
clock_wdt_offset_pct: 3.0 # default=3.0 (1.0-10.0), used to calclate pixels between clock text and side of screen
clock_hgt_offset_pct: 3.0 # default=3.0 (1.0-10.0), used to calclate pixels between clock text and top/bottom of screen
# If text is found in the ramdisk /dev/shm/clock.txt then it will be displayed under the time

menu_text_sz: 40 # default=40, menu character size
menu_autohide_tm: 10.0 # default=10.0, time in seconds to show menu before auto hiding (0 disables auto hiding)
Expand Down
3 changes: 3 additions & 0 deletions src/picframe/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
'clock_text_sz': 120,
'clock_format': "%I:%M",
'clock_opacity': 1.0,
'clock_top_bottom': "T",
'clock_wdt_offset_pct': 3.0,
'clock_hgt_offset_pct': 3.0,
'menu_text_sz': 40,
'menu_autohide_tm': 10.0,
'geo_suppress_list': [],
Expand Down
23 changes: 20 additions & 3 deletions src/picframe/viewer_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def __init__(self, config):
self.__clock_text_sz = config['clock_text_sz']
self.__clock_format = config['clock_format']
self.__clock_opacity = config['clock_opacity']
self.__clock_top_bottom = config['clock_top_bottom']
self.__clock_wdt_offset_pct = config['clock_wdt_offset_pct']
self.__clock_hgt_offset_pct = config['clock_hgt_offset_pct']
ImageFile.LOAD_TRUNCATED_IMAGES = True # occasional damaged file hangs app

@property
Expand Down Expand Up @@ -400,22 +403,36 @@ def __draw_clock(self):
# With the default H:M display, this will only rebuild once each minute. Note however,
# time strings containing a "seconds" component will rebuild once per second.
if current_time != self.__prev_clock_time:
width = self.__display.width - 50
self.__clock_overlay = pi3d.FixedString(self.__font_file, current_time, font_size=self.__clock_text_sz,
# Calculate width and height offsets based on percents from configuration.yaml
wdt_offset = int(self.__display.width * self.__clock_wdt_offset_pct / 100)
hgt_offset = int(self.__display.height * self.__clock_hgt_offset_pct / 100)
width = self.__display.width - wdt_offset
# check if /dev/shm/clock.txt exists, if so add it to current_time
clock_text = current_time
if os.path.isfile("/dev/shm/clock.txt"):
with open("/dev/shm/clock.txt", "r") as f:
clock_text = f.read()
clock_text = f"{current_time}\n{clock_text}"
self.__clock_overlay = pi3d.FixedString(self.__font_file, clock_text, font_size=self.__clock_text_sz,
shader=self.__flat_shader, width=width, shadow_radius=3,
justify=self.__clock_justify,
color=(255, 255, 255, int(255 * float(self.__clock_opacity))))
x = (width - self.__clock_overlay.sprite.width) // 2
if self.__clock_justify == "L":
x *= -1
elif self.__clock_justify == "C":
x = 0
y = (self.__display.height - self.__clock_text_sz - 20) // 2
y = (self.__display.height - self.__clock_overlay.sprite.height + self.__clock_text_sz * 0.5 - hgt_offset) // 2
# Handle whether to draw the clock at top or bottom
if self.__clock_top_bottom == "B":
y *= -1
self.__clock_overlay.sprite.position(x, y, 0.1)
self.__prev_clock_time = current_time

if self.__clock_overlay:
self.__clock_overlay.sprite.draw()


@property
def display_width(self):
return self.__display.width
Expand Down

0 comments on commit 5d40c55

Please sign in to comment.