[elbe-devel] [PATCH 05/14] Debianize - Radio buttons widget
Bastian Germann
bage at linutronix.de
Thu Aug 1 14:58:28 CEST 2019
> From: Olivier Dion <dion at linutronix.de>
>
> Radio buttons can be grouped either vertically (default) or
> horizontally. This is decided within the ctor with the policy
> variable argument.
>
> The calle should provides an enumeration type and a member of the
caller
> enumeration type to use by default.
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
With this applied
Reviewed-by: Bastian Germann <bage at linutronix.de>
> ---
> elbepack/debianize/widgets/radio.py | 53 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 53 insertions(+)
> create mode 100644 elbepack/debianize/widgets/radio.py
>
> diff --git a/elbepack/debianize/widgets/radio.py b/elbepack/debianize/widgets/radio.py
> new file mode 100644
> index 00000000..2caccf39
> --- /dev/null
> +++ b/elbepack/debianize/widgets/radio.py
> @@ -0,0 +1,53 @@
> +# ELBE - Debian Based Embedded Rootfilesystem Builder
> +# Copyright (c) 2019 Olivier Dion <dion at linutronix.de>
> +#
> +# SPDX-License-Identifier: GPL-3.0-or-later
> +
> +
> +from enum import IntEnum
> +
> +from urwid import (
> + LineBox,
> + RadioButton,
> + Text
> +)
> +
> +from elbepack.debianize.widgets.grid import Grid
> +
> +
> +class RadioPolicy(IntEnum):
> + HORIZONTAL = 0
> + VERTICAL = 1
> +
> +
> +class RadioGroup(Grid):
> + def __init__(self, title, enum_type, starting_value, policy=RadioPolicy.VERTICAL):
> + self.selected_value = starting_value
> + self.enum_type = enum_type
> +
> + self.radio_group = []
> + for choice in enum_type:
> + RadioButton(self.radio_group,
> + label=choice.name.capitalize(),
> + state=choice is starting_value)
> +
> + rows = [
> + [Text(("header", title))]
> + ]
> +
> + if policy is RadioPolicy.VERTICAL:
> + for radio in self.radio_group:
> + rows.append([radio])
> + else:
> + col = []
> + for radio in self.radio_group:
> + col.append(radio)
> + rows.append(col)
> +
> + super().__init__(rows)
> + self._w = LineBox(self._w)
> +
> + def get_data(self):
> + for radio in self.radio_group:
> + if radio.state:
> + return self.enum_type[radio.label.upper()]
>
More information about the elbe-devel
mailing list