[elbe-devel] [PATCH v2 04/13] Debianize - Radio buttons widget
dion at linutronix.de
dion at linutronix.de
Thu Aug 1 17:49:25 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 caller should provides an enumeration type and a member of the
enumeration type to use by default.
Signed-off-by: Olivier Dion <dion at linutronix.de>
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..7b15b5ed
--- /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 urwid import (
+ LineBox,
+ RadioButton,
+ Text
+)
+
+from elbepack.debianize.widgets.grid import Grid
+
+
+class RadioPolicy(object):
+ 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.__dict__.keys():
+ if choice.startswith('-'):
+ continue
+ RadioButton(self.radio_group,
+ label=choice.capitalize(),
+ state=choice == 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(RadioGroup, self).__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()]
--
2.11.0
More information about the elbe-devel
mailing list