From 57042d2050b3e68811d6de874074df06d309cec9 Mon Sep 17 00:00:00 2001 From: pdxlocations <117498748+pdxlocations@users.noreply.github.com> Date: Sat, 8 Feb 2025 09:14:25 -0800 Subject: [PATCH 1/3] Maybe fix startup error (again) (#124) * more excuses * none isn't better than nothing * more checks * typo * refactor * less is more --- ui/curses_ui.py | 84 +++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/ui/curses_ui.py b/ui/curses_ui.py index 1464fba..1ee86d6 100644 --- a/ui/curses_ui.py +++ b/ui/curses_ui.py @@ -11,8 +11,6 @@ import default_config as config import ui.dialog import globals - - def handle_resize(stdscr, firstrun): global messages_pad, messages_win, nodes_pad, nodes_win, channel_pad, channel_win, function_win, packetlog_win, entry_win @@ -37,31 +35,46 @@ def handle_resize(stdscr, firstrun): nodes_pad = curses.newpad(1,1) channel_pad = curses.newpad(1,1) - entry_win.bkgd(get_color("background")) - channel_win.bkgd(get_color("background")) - messages_win.bkgd(get_color("background")) - nodes_win.bkgd(get_color("background")) - function_win.bkgd(get_color("background")) - packetlog_win.bkgd(get_color("background")) + # Set background colors for windows + for win in [entry_win, channel_win, messages_win, nodes_win, function_win, packetlog_win]: + win.bkgd(get_color("background")) - messages_pad.bkgd(get_color("background")) - nodes_pad.bkgd(get_color("background")) - channel_pad.bkgd(get_color("background")) + # Set background colors for pads + for pad in [messages_pad, nodes_pad, channel_pad]: + pad.bkgd(get_color("background")) + # Set colors for window frames + for win in [channel_win, entry_win, nodes_win, messages_win, function_win]: + win.attrset(get_color("window_frame")) - channel_win.attrset(get_color("window_frame")) - entry_win.attrset(get_color("window_frame")) - nodes_win.attrset(get_color("window_frame")) - messages_win.attrset(get_color("window_frame")) - function_win.attrset(get_color("window_frame")) else: - entry_win.erase() - channel_win.erase() - messages_win.erase() - nodes_win.erase() - function_win.erase() - packetlog_win.erase() + # Ensure all windows are initialized before using them + if entry_win is None: + entry_win = curses.newwin(3, width, 0, 0) + if channel_win is None: + channel_win = curses.newwin(height - 6, channel_width, 3, 0) + if messages_win is None: + messages_win = curses.newwin(height - 6, messages_width, 3, channel_width) + if nodes_win is None: + nodes_win = curses.newwin(height - 6, nodes_width, 3, channel_width + messages_width) + if function_win is None: + function_win = curses.newwin(3, width, height - 3, 0) + if packetlog_win is None: + packetlog_win = curses.newwin(int(height / 3), messages_width, height - int(height / 3) - 3, channel_width) + + # Ensure pads are initialized + if messages_pad is None: + messages_pad = curses.newpad(1,1) + if nodes_pad is None: + nodes_pad = curses.newpad(1,1) + if channel_pad is None: + channel_pad = curses.newpad(1,1) + + + for win in [entry_win, channel_win, messages_win, nodes_win, function_win, packetlog_win]: + win.erase() + entry_win.resize(3, width) channel_win.resize(height - 6, channel_width) messages_win.resize(height - 6, messages_width) @@ -73,27 +86,12 @@ def handle_resize(stdscr, firstrun): packetlog_win.resize(int(height / 3), messages_width) packetlog_win.mvwin(height - int(height / 3) - 3, channel_width) - # Reinitialize `nodes_pad` in case it was lost during a resize. - # We shouldn't need this but nodes_pad keeps throwing and error in draw_node_list so... - try: - nodes_pad.getmaxyx() # Check if it's still valid - except: - nodes_pad = curses.newpad(1, 1) # Recreate if needed + # Draw window borders + for win in [channel_win, entry_win, nodes_win, messages_win, function_win]: + win.box() + win.refresh() - channel_win.box() - entry_win.box() - nodes_win.box() - messages_win.box() - - function_win.box() - - # Refresh all windows - entry_win.refresh() - channel_win.refresh() - function_win.refresh() - nodes_win.refresh() - messages_win.refresh() entry_win.keypad(True) curses.curs_set(1) @@ -435,6 +433,10 @@ def draw_messages_window(scroll_to_bottom = False): draw_packetlog_win() def draw_node_list(): + # global nodes_pad + # if nodes_pad is None: + # nodes_pad = curses.newpad(1, 1) + try: nodes_pad.erase() box_width = nodes_win.getmaxyx()[1] From 804f82cbe6dab1629af76e8b36ab66d7ddb9d534 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Sat, 8 Feb 2025 10:03:51 -0800 Subject: [PATCH 2/3] where have all the nodes_pad gone? --- main.py | 1 - ui/curses_ui.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 34686f8..ab0efd3 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,6 @@ from pubsub import pub import os import logging import traceback -import time from utilities.arg_parser import setup_parser from utilities.interfaces import initialize_interface diff --git a/ui/curses_ui.py b/ui/curses_ui.py index 1ee86d6..115644a 100644 --- a/ui/curses_ui.py +++ b/ui/curses_ui.py @@ -433,9 +433,9 @@ def draw_messages_window(scroll_to_bottom = False): draw_packetlog_win() def draw_node_list(): - # global nodes_pad - # if nodes_pad is None: - # nodes_pad = curses.newpad(1, 1) + global nodes_pad + if nodes_pad is None: + nodes_pad = curses.newpad(1, 1) try: nodes_pad.erase() From 3c3bf0ad37f6a4535989404e04608cd53aeb8d6a Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Sat, 8 Feb 2025 13:23:30 -0800 Subject: [PATCH 3/3] rename enum to list --- input_handlers.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/input_handlers.py b/input_handlers.py index e7cb0a1..e38759b 100644 --- a/input_handlers.py +++ b/input_handlers.py @@ -207,19 +207,19 @@ def get_list_input(prompt, current_option, list_options): return current_option -def move_highlight(old_idx, new_idx, options, enum_win, enum_pad): +def move_highlight(old_idx, new_idx, options, list_win, list_pad): if old_idx == new_idx: return # no-op - enum_pad.chgat(old_idx, 0, enum_pad.getmaxyx()[1], get_color("settings_default")) - enum_pad.chgat(new_idx, 0, enum_pad.getmaxyx()[1], get_color("settings_default", reverse = True)) + list_pad.chgat(old_idx, 0, list_pad.getmaxyx()[1], get_color("settings_default")) + list_pad.chgat(new_idx, 0, list_pad.getmaxyx()[1], get_color("settings_default", reverse = True)) - enum_win.refresh() + list_win.refresh() - start_index = max(0, new_idx - (enum_win.getmaxyx()[0] - 4)) + start_index = max(0, new_idx - (list_win.getmaxyx()[0] - 4)) - enum_win.refresh() - enum_pad.refresh(start_index, 0, - enum_win.getbegyx()[0] + 3, enum_win.getbegyx()[1] + 4, - enum_win.getbegyx()[0] + enum_win.getmaxyx()[0] - 2, enum_win.getbegyx()[1] + 4 + enum_win.getmaxyx()[1] - 4) + list_win.refresh() + list_pad.refresh(start_index, 0, + list_win.getbegyx()[0] + 3, list_win.getbegyx()[1] + 4, + list_win.getbegyx()[0] + list_win.getmaxyx()[0] - 2, list_win.getbegyx()[1] + 4 + list_win.getmaxyx()[1] - 4) \ No newline at end of file