Skip to content

Commit

Permalink
Fix ColoredFlat theme centered weather by using provided text anchor …
Browse files Browse the repository at this point in the history
…and width
  • Loading branch information
mathoudebine committed Dec 21, 2024
1 parent fd24d1a commit 1e709c2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 14 deletions.
4 changes: 4 additions & 0 deletions library/lcd/lcd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ def DisplayText(
assert len(text) > 0, 'Text must not be empty'
assert font_size > 0, "Font size must be > 0"

# If only width is specified, assume height based on font size (one-line text)
if width > 0 and height == 0:
height = font_size

if background_image is None:
# A text bitmap is created with max width/height by default : text with solid background
text_image = Image.new(
Expand Down
9 changes: 0 additions & 9 deletions library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,6 @@ def stats():
wdescription_theme_data = weather_theme_data.get('WEATHER_DESCRIPTION', {}).get('TEXT', {})
whumidity_theme_data = weather_theme_data.get('HUMIDITY', {}).get('TEXT', {})

# Retrieve information used to center description, if needed
center_description_length = 40
if 'CENTER_LENGTH' in wdescription_theme_data:
center_description_length = wdescription_theme_data['CENTER_LENGTH']

activate = True if wtemperature_theme_data.get("SHOW") or wfelt_theme_data.get(
"SHOW") or wupdatetime_theme_data.get("SHOW") or wdescription_theme_data.get(
"SHOW") or whumidity_theme_data.get("SHOW") else False
Expand All @@ -861,8 +856,6 @@ def stats():
desc = "Cloudy"
time = "@15:33"
humidity = "45%"
if wdescription_theme_data['CENTER_LENGTH']:
desc = "x" * center_description_length
else:
# API Parameters
lat = config.CONFIG_DATA['config'].get('WEATHER_LATITUDE', "")
Expand All @@ -880,8 +873,6 @@ def stats():
temp = f"{data['current']['temp']:.1f}{deg}"
feel = f"({data['current']['feels_like']:.1f}{deg})"
desc = data['current']['weather'][0]['description'].capitalize()
if wdescription_theme_data['CENTER_LENGTH']:
desc = desc.center(center_description_length)
humidity = f"{data['current']['humidity']:.0f}%"
now = datetime.datetime.now()
time = f"@{now.hour:02d}:{now.minute:02d}"
Expand Down
Binary file modified res/themes/ColoredFlat/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions res/themes/ColoredFlat/theme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,14 @@ STATS:
WEATHER_DESCRIPTION:
TEXT:
SHOW: True
CENTER: True # Used to center the description, on a 40 character basis or with CENTER_LENGTH below. Use MONO font for better results. Use fake static data for better positionning !
CENTER_LENGTH: 40
X: 20
X: 0
Y: 95
WIDTH: 480
FONT: roboto-mono/RobotoMono-Bold.ttf
FONT_SIZE: 18
FONT_COLOR: 247, 227, 227
BACKGROUND_IMAGE: background.png
ANCHOR: mb # Text is centered
PING:
INTERVAL: 1
TEXT:
Expand Down
2 changes: 0 additions & 2 deletions res/themes/theme_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1508,8 +1508,6 @@ STATS:
WEATHER_DESCRIPTION:
TEXT:
SHOW: True
CENTER: True # Used to center the description, on a 40 character basis or with CENTER_LENGTH below. Use MONO font for better results. Use fake static data for better positionning !
CENTER_LENGTH: 40
X: 20
Y: 95
FONT: roboto-mono/RobotoMono-Bold.ttf
Expand Down

0 comments on commit 1e709c2

Please sign in to comment.