diff --git a/example_config.json b/example_config.json index 01f6eca..bcec215 100644 --- a/example_config.json +++ b/example_config.json @@ -3,27 +3,32 @@ { "label": "example 1", "action_type": "MSG", - "action_param": "This is example 1" + "action_param": "1", + "action_message": "Doing example 1" }, { "label": "example 2", "action_type": "MSG", - "action_param": "This is example 2" + "action_param": "2", + "action_message": "Doing example 2" }, { "label": "example 3", "action_type": "MSG", - "action_param": "This is example 3" + "action_param": "3", + "action_message": "Doing example 3" }, { "label": "example 4", "action_type": "MSG", - "action_param": "This is example 4" + "action_param": "Bad time definition", + "action_message": "Doing example 4" }, { "label": "GET example", "action_type": "GET", - "action_param": "http://example.com/" + "action_param": "http://example.com/", + "action_message": "Doing GET example" } ], "bg_color": "lime" diff --git a/menu.py b/menu.py index ca55fe5..b44fe13 100644 --- a/menu.py +++ b/menu.py @@ -30,7 +30,8 @@ class ActionType(Enum): class Action(TypedDict): label: str action_type: ActionType - param: str + action_param: str + action_message: str class Button: @@ -163,12 +164,22 @@ class App: def end_thr(): self.board = previous_board - sleep(5) - self.task_q.put(end_thr) + try: + sleep_time = int(action['action_param']) + sleep(sleep_time) + except Exception as e: + def f(ex): + def x(): + self.board = MessageBoard(self.get_screen_rect(), f"Exception caught: {ex}", bg_color="red") + return x + self.task_q.put(f(e)) + sleep(5) + finally: + self.task_q.put(end_thr) process_thr = Thread(target=thr_fun) process_thr.start() - self.board = MessageBoard(self.get_screen_rect(), action['param'], bg_color=self.bg_color) + self.board = MessageBoard(self.get_screen_rect(), action['action_message'], bg_color=self.bg_color) return impl def get_handler(self, action: Action) -> Callable[[], None]: @@ -179,13 +190,13 @@ class App: def end_thr(): self.board = previous_board - ret = requests.get(action['param']) - print(f"GET {action['param']}: {ret}") + ret = requests.get(action['action_param']) + print(f"GET {action['action_param']}: {ret}") self.task_q.put(end_thr) process_thr = Thread(target=thr_fun) process_thr.start() - self.board = MessageBoard(self.get_screen_rect(), f"GETting {action['param']}", bg_color=self.bg_color) + self.board = MessageBoard(self.get_screen_rect(), action['action_message'], bg_color=self.bg_color) return impl def button_press_handler(self, action: Action) -> Callable[[], None]: @@ -230,7 +241,8 @@ def get_url_defs(config_data: dict) -> List[Action]: for d in data['urls']: url_defs.append(Action(label=d['label'], action_type=ActionType[d['action_type']], - param=d['action_param'])) + action_param=d['action_param'], + action_message=d['action_message'])) return url_defs