mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 14:54:00 -06:00
ui: refactor signals
This commit is contained in:
+13
-10
@@ -6,15 +6,12 @@ from pqcli.ui.button import MenuButton
|
||||
|
||||
|
||||
class ExitView(urwid.Overlay):
|
||||
def __init__(
|
||||
self, parent: urwid.Widget, on_exit: T.Callable, on_cancel: T.Callable
|
||||
) -> None:
|
||||
self.on_exit = on_exit
|
||||
self.on_cancel = on_cancel
|
||||
signals = ["exit", "cancel"]
|
||||
|
||||
def __init__(self, parent: urwid.Widget) -> None:
|
||||
question = urwid.Text(("bold", "Really quit?"), "center")
|
||||
yes_btn = MenuButton("Yes", lambda _user_data: self.on_exit())
|
||||
no_btn = MenuButton("No", lambda _user_data: self.on_cancel())
|
||||
yes_btn = MenuButton("Yes", lambda _user_data: self.exit())
|
||||
no_btn = MenuButton("No", lambda _user_data: self.cancel())
|
||||
|
||||
line_box = urwid.LineBox(
|
||||
urwid.ListBox(
|
||||
@@ -26,9 +23,15 @@ class ExitView(urwid.Overlay):
|
||||
|
||||
def keypress(self, size: T.Any, key: str) -> T.Optional[str]:
|
||||
if key in {"y", "Y"}:
|
||||
self.on_exit()
|
||||
self.exit()
|
||||
return None
|
||||
if key in {"n", "N"}:
|
||||
self.on_cancel()
|
||||
self.cancel()
|
||||
return None
|
||||
return super().keypress(size, key)
|
||||
return T.cast(T.Optional[str], super().keypress(size, key))
|
||||
|
||||
def exit(self) -> None:
|
||||
self._emit("exit")
|
||||
|
||||
def cancel(self) -> None:
|
||||
self._emit("cancel")
|
||||
|
||||
Reference in New Issue
Block a user