[elbe-devel] [PATCH 04/14] Debianize - Button widget
Bastian Germann
bage at linutronix.de
Thu Aug 1 14:53:23 CEST 2019
> From: Olivier Dion <dion at linutronix.de>
>
> A simple and clean button widget.
>
> The button ctor takes 3 arguments.
>
> * text
>
> The text to show in the button.
>
> * palette
>
> A valid palette name to apply on the button. See TUI::palette.
>
> * callback
>
> The callback to call when the button is clicked.
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
Please move the description to the file as pydoc.
> ---
> elbepack/debianize/widgets/button.py | 44 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
> create mode 100644 elbepack/debianize/widgets/button.py
>
> diff --git a/elbepack/debianize/widgets/button.py b/elbepack/debianize/widgets/button.py
> new file mode 100644
> index 00000000..e3cd08ab
> --- /dev/null
> +++ b/elbepack/debianize/widgets/button.py
> @@ -0,0 +1,44 @@
> +# ELBE - Debian Based Embedded Rootfilesystem Builder
> +# Copyright (c) 2019 Olivier Dion <dion at linutronix.de>
> +#
> +# SPDX-License-Identifier: GPL-3.0-or-later
> +
> +
> +from collections import Callable
> +
> +from urwid import (
> + AttrMap,
> + LineBox,
> + Text,
> + WidgetWrap,
> + connect_signal,
> + emit_signal
> +)
> +
> +from elbepack.debianize.base.signal import SignalType
> +
> +
> +class Button(WidgetWrap):
> +
> + signals = [SignalType.CLICK]
> +
> + def __init__(self, text: str, palette: str, callback: Callable):
> + widget = LineBox(AttrMap(Text("[{}]".format(text), align="center"), "default", palette))
> + super().__init__(widget)
> + connect_signal(self, SignalType.CLICK, callback)
> +
> + # Very important! This is not documented in urwid's
> + # documentation! Without this, the button would only text.
> + self._w.base_widget._selectable = True
> +
> + def keypress(self, size, key):
> + if key == "enter":
> + emit_signal(self, SignalType.CLICK)
> + return None
> + return key
> +
> + def mouse_event(self, size, event, button, col, row, focus):
> + if focus and event == "mouse release":
> + emit_signal(self, SignalType.CLICK)
> + return True
> + return False
>
More information about the elbe-devel
mailing list