From: Michael Tremer Date: Wed, 5 May 2021 15:29:30 +0000 (+0000) Subject: tui: Setup screen with some helptext X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a150a6826aada2fe4694fcebbba5c1b064c5a9c8;p=people%2Fms%2Fbricklayer.git tui: Setup screen with some helptext Signed-off-by: Michael Tremer --- diff --git a/src/python/tui/__init__.py b/src/python/tui/__init__.py index 20ead6c..6926a4a 100644 --- a/src/python/tui/__init__.py +++ b/src/python/tui/__init__.py @@ -19,6 +19,9 @@ ############################################################################### import logging +import snack + +from ..i18n import _ # Setup logging log = logging.getLogger("bricklayer.tui") @@ -27,10 +30,63 @@ class Tui(object): def __init__(self, bricklayer): self.bricklayer = bricklayer + # Placeholder for screen + self.screen = None + # Make this class usable as context def __enter__(self): + log.debug("Entering TUI context") + + # Setup the screen + self._setup_screen() + return self def __exit__(self, type, value, traceback): - pass + log.debug("Leaving TUI context") + + # Wipe the screen + self._finish_screen() + + def refresh(self): + """ + Refreshes what is written on the screen + """ + if self.screen: + self.screen.refresh() + + def _setup_screen(self): + """ + Sets up the screen + """ + self.screen = snack.SnackScreen() + + # Setup helpline + self.push_helpline( + _("/ between elements | selects | next screen") + ) + + # Refresh the screen + self.refresh() + + def _finish_screen(self): + """ + Cleanup screen + """ + if self.screen: + self.screen.finish() + self.screen = None + + def push_helpline(self, helpline): + """ + Sets the helpline, but centers it first + """ + if not self.screen: + raise RuntimeError() + + # Center the string + if self.screen.width: + helpline = helpline.center(self.screen.width) + + self.screen.pushHelpLine(helpline)