From d74b40b7e2bcaf1017bbf530b0cfd88f5ec53093 Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Sat, 27 Nov 2021 14:39:18 -0500 Subject: [PATCH] Use urwid over curses --- companion_software/dashboard/dash.py | 36 +++++-------------- companion_software/dashboard/requirements.txt | 1 + 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/companion_software/dashboard/dash.py b/companion_software/dashboard/dash.py index 5a5637d..215b1f5 100644 --- a/companion_software/dashboard/dash.py +++ b/companion_software/dashboard/dash.py @@ -1,33 +1,15 @@ -# Draw text to center of screen -import curses - -screen = curses.initscr() -num_rows, num_cols = screen.getmaxyx() +import urwid -# Make a function to print a line in the center of screen -def print_center(message): - # Calculate center row - middle_row = int(num_rows / 2) - - # Calculate center column, and then adjust starting position based - # on the length of the message - half_length_of_message = int(len(message) / 2) - middle_column = int(num_cols / 2) - x_position = middle_column - half_length_of_message - - # Draw the text - screen.addstr(middle_row, x_position, message) - screen.refresh() +def exit_on_q(key): + if key in ('q', 'Q'): + raise urwid.ExitMainLoop() -print_center("Greatness awaits...") +txt = urwid.BigText(u" Greatness Awaits... ", urwid.HalfBlock5x4Font()) +test = urwid.Padding(txt, 'center', None) +test = urwid.Filler(test, 'middle', None, 7) -# Wait and cleanup -while True: - try: - curses.napms(500) - except KeyboardInterrupt: - break -curses.endwin() +loop = urwid.MainLoop(test, unhandled_input=exit_on_q) +loop.run() diff --git a/companion_software/dashboard/requirements.txt b/companion_software/dashboard/requirements.txt index e69de29..0ac3eb6 100644 --- a/companion_software/dashboard/requirements.txt +++ b/companion_software/dashboard/requirements.txt @@ -0,0 +1 @@ +urwid