ui: refactor signals

This commit is contained in:
rr-
2018-11-05 21:04:39 +01:00
parent 35083e42e9
commit 30b8643b12
4 changed files with 40 additions and 41 deletions
+13 -10
View File
@@ -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")