mirror of https://git.sr.ht/~michalr/menu
Action messages, ability to define message timeout in param
This commit is contained in:
parent
598c882076
commit
8c64d82fa9
|
@ -3,27 +3,32 @@
|
||||||
{
|
{
|
||||||
"label": "example 1",
|
"label": "example 1",
|
||||||
"action_type": "MSG",
|
"action_type": "MSG",
|
||||||
"action_param": "This is example 1"
|
"action_param": "1",
|
||||||
|
"action_message": "Doing example 1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "example 2",
|
"label": "example 2",
|
||||||
"action_type": "MSG",
|
"action_type": "MSG",
|
||||||
"action_param": "This is example 2"
|
"action_param": "2",
|
||||||
|
"action_message": "Doing example 2"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "example 3",
|
"label": "example 3",
|
||||||
"action_type": "MSG",
|
"action_type": "MSG",
|
||||||
"action_param": "This is example 3"
|
"action_param": "3",
|
||||||
|
"action_message": "Doing example 3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "example 4",
|
"label": "example 4",
|
||||||
"action_type": "MSG",
|
"action_type": "MSG",
|
||||||
"action_param": "This is example 4"
|
"action_param": "Bad time definition",
|
||||||
|
"action_message": "Doing example 4"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "GET example",
|
"label": "GET example",
|
||||||
"action_type": "GET",
|
"action_type": "GET",
|
||||||
"action_param": "http://example.com/"
|
"action_param": "http://example.com/",
|
||||||
|
"action_message": "Doing GET example"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"bg_color": "lime"
|
"bg_color": "lime"
|
||||||
|
|
24
menu.py
24
menu.py
|
@ -30,7 +30,8 @@ class ActionType(Enum):
|
||||||
class Action(TypedDict):
|
class Action(TypedDict):
|
||||||
label: str
|
label: str
|
||||||
action_type: ActionType
|
action_type: ActionType
|
||||||
param: str
|
action_param: str
|
||||||
|
action_message: str
|
||||||
|
|
||||||
|
|
||||||
class Button:
|
class Button:
|
||||||
|
@ -163,12 +164,22 @@ class App:
|
||||||
def end_thr():
|
def end_thr():
|
||||||
self.board = previous_board
|
self.board = previous_board
|
||||||
|
|
||||||
|
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)
|
sleep(5)
|
||||||
|
finally:
|
||||||
self.task_q.put(end_thr)
|
self.task_q.put(end_thr)
|
||||||
|
|
||||||
process_thr = Thread(target=thr_fun)
|
process_thr = Thread(target=thr_fun)
|
||||||
process_thr.start()
|
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
|
return impl
|
||||||
|
|
||||||
def get_handler(self, action: Action) -> Callable[[], None]:
|
def get_handler(self, action: Action) -> Callable[[], None]:
|
||||||
|
@ -179,13 +190,13 @@ class App:
|
||||||
def end_thr():
|
def end_thr():
|
||||||
self.board = previous_board
|
self.board = previous_board
|
||||||
|
|
||||||
ret = requests.get(action['param'])
|
ret = requests.get(action['action_param'])
|
||||||
print(f"GET {action['param']}: {ret}")
|
print(f"GET {action['action_param']}: {ret}")
|
||||||
self.task_q.put(end_thr)
|
self.task_q.put(end_thr)
|
||||||
|
|
||||||
process_thr = Thread(target=thr_fun)
|
process_thr = Thread(target=thr_fun)
|
||||||
process_thr.start()
|
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
|
return impl
|
||||||
|
|
||||||
def button_press_handler(self, action: Action) -> Callable[[], None]:
|
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']:
|
for d in data['urls']:
|
||||||
url_defs.append(Action(label=d['label'],
|
url_defs.append(Action(label=d['label'],
|
||||||
action_type=ActionType[d['action_type']],
|
action_type=ActionType[d['action_type']],
|
||||||
param=d['action_param']))
|
action_param=d['action_param'],
|
||||||
|
action_message=d['action_message']))
|
||||||
return url_defs
|
return url_defs
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue