Skip to content

Commit

Permalink
Changed scroller wave config to be used for all text scrollings and f…
Browse files Browse the repository at this point in the history
…ixed a bug with the hassio hostname and ip fetching
  • Loading branch information
crismc committed Nov 18, 2022
1 parent f9bea56 commit 7d155c8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ This repository has been broken out to work as a standalone service and will wor
## Custom Screen & Static Text Variables
Aswell as the above screens, you can configure a static custom screen which can be fixed or animated.

If the configured text is greater than the screen size, it will scroll across the screen unless you configure it to display as lines. Scrolling animations also supports configurable apmlitude enabling the text to wave up and down as it scrolls.
If the configured text is greater than the screen size, it will scroll across the screen unless you configure it to display as lines.

Scrolling animations also supports configurable apmlitude enabling the text to wave up and down as it scrolls.

![Exit][exit-url]
![Welcome][welcome-url]
Expand Down Expand Up @@ -188,7 +190,7 @@ python3 display.py --config /path/to/options.json
| Graceful_Exit_Text | string | **Optional** | Text to display when the service is exited. Accepts same variables as the custom screen. | `Exited at {datetime}` |
| Static_Screen_Text | string | **Optional** | Text to display when the ```Show_Static_Screen``` is enabled. Accepts all static text variables. | `Hassio verion {hassio.os.version} on {hostname} with IP {ip}` |
| Static_Screen_Text_NoScroll | boolean | **Optional** | Disable the scrolling animation if the static text its too large to fit. If set to true, make a best effort to stack the text as centered lines | `false` |
| Static_Screen_Text_Animated_Wave | int | **Optional** | Amount of wave action the custom text scrolling animation has. The bigger the number, the bigger the wave. | `8` |
| Scroll_Amplitude | int | **Optional** | Amount of wave action the scrolling animation text has. The bigger the number, the bigger the wave. | `6` |
| Show_Static_Screen | boolean | **Required** | Show the static screen with the specified custom text | `false` |
| Show_Welcome_Screen | boolean | **Required** | Show the animated Welcome to `hostname` screen | `true` |
| Welcome_Screen_Text | string | **Optional** | Text to display when the ```Show_Welcome_Screen``` is enabled. Accepts all static text variables. | `Welcome to {hostname}` |
Expand Down
10 changes: 7 additions & 3 deletions bin/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import signal
from bin.Utils import Utils, HassioUtils
from bin.Screens import *
from bin.Scroller import Scroller

class Config:
DEFAULT_DURATION = 10
Expand All @@ -29,7 +30,7 @@ class Config:
'graceful_exit_text': 'graceful_exit_text',
'static_screen_text': 'static_screen_text',
'static_screen_text_noscroll': 'static_screen_text_noscroll',
'static_screen_text_animated_wave': 'static_screen_text_animated_wave',
'scroll_amplitude': 'scroll_amplitude',
'datetime_format': 'datetime_format',
'welcome_screen_text': 'welcome_screen_text'
}
Expand All @@ -54,6 +55,10 @@ def _process_default_options(self):
if duration:
self.default_duration = int(duration)

scroller_amplitude = self.get_option_value('scroll_amplitude')
if scroller_amplitude:
Scroller.default_amplitude = scroller_amplitude

def allow_screen_render(self, screen):
if self.allow_master_render:
if screen in self.screen_limits:
Expand Down Expand Up @@ -206,7 +211,6 @@ def screen_factory(self, name):
static_text = self.get_option_value('static_screen_text')
if static_text:
screen.text = static_text
screen.amplitude = self.get_option_value('static_screen_text_animated_wave')
if self.get_option_value('static_screen_text_noscroll'):
screen.noscroll = True
return screen
Expand All @@ -220,7 +224,7 @@ def screen_factory(self, name):

if name == 'welcome':
screen.text = self.get_option_value('welcome_screen_text')

screen.amplitude = self.get_option_value('scroll_amplitude')
return screen
else:
raise Exception(name + " is not an enabled screen")
Expand Down
28 changes: 14 additions & 14 deletions bin/Screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def render(self):
def render_scroller(self, text, font, amplitude = 0, startpos = None):
if not startpos:
startpos = self.display.width
scroller = Scroller(text, startpos, amplitude, font, self.display)
scroller = Scroller(text, startpos, font, self.display, amplitude)
timer = time.time() + self.duration
while self.config.allow_screen_render(self.name):
self.display.prepare()
Expand Down Expand Up @@ -143,16 +143,16 @@ def noscroll(self, state):
self._noscroll = bool(state)
self.logger.info("Static screens text animated has been set to '" + str(self._noscroll) + "'")

@property
def amplitude(self):
if not self._amplitude:
return 0
return self._amplitude
# @property
# def amplitude(self):
# if not self._amplitude:
# return 0
# return self._amplitude

@amplitude.setter
def amplitude(self, amplitude):
self._amplitude = int(amplitude) * -1
self.logger.info("Static screen amplitude: '" + str(self._amplitude) + "' set")
# @amplitude.setter
# def amplitude(self, amplitude):
# self._amplitude = int(amplitude) * -1
# self.logger.info("Static screen amplitude: '" + str(self._amplitude) + "' set")

def capture_screenshot(self):
slug = Utils.slugify(self.text)
Expand All @@ -162,11 +162,11 @@ def render(self):
self.display.prepare()
font = self.font(16)
text = self.text
amplitude = self.amplitude
# amplitude = self.amplitude

self.logger.info("Rendering static text: " + text + " with an amplitude of " + str(amplitude))
self.logger.info("Rendering static text: " + text)
if not self.noscroll and Utils.requires_scroller(self.display, text, font):
self.render_scroller(text, font, amplitude)
self.render_scroller(text, font)
else:
if not Utils.does_text_width_fit(self.display, text, font):
self.logger.info("Static text too wide for screen")
Expand Down Expand Up @@ -224,7 +224,7 @@ def render(self):
'''
height = self.display.height
font = self.font(16)
self.render_scroller(self.text, font, height/6)
self.render_scroller(self.text, font)

class SplashScreen(BaseScreen):
img = Image.open(r"" + Utils.current_dir + "/img/home-assistant-logo.png")
Expand Down
6 changes: 4 additions & 2 deletions bin/Scroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
import logging
from bin.Utils import Utils
class Scroller:
def __init__(self, text, startpos, amplitude, font, display, velocity = -2):
default_amplitude = 0

def __init__(self, text, startpos, font, display, amplitude = None, velocity = -2):
self.text = text
self.display = display
self.amplitude = amplitude
self.velocity = velocity
self.startpos = startpos
self.pos = startpos
self.font = font
self.amplitude = amplitude if amplitude else Scroller.default_amplitude
self.logger = logging.getLogger('Scroller')
unused, self.height_offset = Utils.get_text_center(display, text, font) # height/4
self.maxwidth, unused = Utils.get_text_size(display, text, font)
Expand Down
10 changes: 8 additions & 2 deletions bin/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def slugify(text):
class HassioUtils(Utils):
@staticmethod
def hassos_get_info(type):
cmd = 'curl -sSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" -H "Content-Type: application/json" http://supervisor/{}'.format(type)
url = 'http://supervisor/{}'.format(type)
Utils.logger.info("Requesting data from '" + url + "'")
cmd = 'curl -sSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" -H "Content-Type: application/json" ' + url
info = Utils.shell_cmd(cmd)
return json.loads(info)

Expand All @@ -85,7 +87,11 @@ def get_ip():

@staticmethod
def compile_text(text, additional_replacements = {}):
text = Utils.compile_text(text, additional_replacements)
replacements = {
"{hostname}": lambda prop: HassioUtils.get_hostname(),
"{ip}": lambda prop: HassioUtils.get_ip()
}
text = Utils.compile_text(text, {**replacements, **additional_replacements})
regex = re.compile("{hassio\.[a-z]+\.[a-z\.]+}")
return regex.sub(lambda match: HassioUtils.get_hassio_info_property(match.string[match.start():match.end()][len("hassio\."):-1]), text)

Expand Down
4 changes: 2 additions & 2 deletions options.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"DateTime_Format": "%d/%m/%Y %H:%M:%S",
"Default_Duration": 10,
"graceful_exit_text": "Exited at {datetime}",
"Scroll_Amplitude": 6,

"Show_Welcome_Screen": true,
"Welcome_Screen_Limit": 5,
Expand Down Expand Up @@ -34,6 +35,5 @@
"Static_Screen_Limit": null,
"Static_Screen_Duration": 5,
"Static_Screen_Text": "Hassio verion {hassio.os.version} on {hostname} with IP {ip}",
"static_Screen_Text_NoScroll": false,
"Static_Screen_Text_Animated_Wave": 8
"static_Screen_Text_NoScroll": false
}

0 comments on commit 7d155c8

Please sign in to comment.