[node-patches] Change in ovirt-node[master]: ui: Add checkbox element and widget

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Dec 11 20:09:38 UTC 2012


Fabian Deutsch has uploaded a new change for review.

Change subject: ui: Add checkbox element and widget
......................................................................

ui: Add checkbox element and widget

Change-Id: I4f4eb2309832a7dad2a96cd3da4eb85e31e94728
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/tui.py
M scripts/tui/src/ovirt/node/ui/__init__.py
M scripts/tui/src/ovirt/node/ui/builder.py
M scripts/tui/src/ovirt/node/ui/widgets.py
4 files changed, 44 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/20/9920/1

diff --git a/scripts/tui/src/ovirt/node/tui.py b/scripts/tui/src/ovirt/node/tui.py
index e695376..6413fe9 100644
--- a/scripts/tui/src/ovirt/node/tui.py
+++ b/scripts/tui/src/ovirt/node/tui.py
@@ -86,6 +86,7 @@
                ('plugin.widget.dialog', None),
                ('plugin.widget.page', None),
                ('plugin.widget.page.frame', None),
+               ('plugin.widget.checkbox.label', 'dark gray, bold'),
                ]
 
     def __init__(self, app):
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index e0441ee..3391ab0 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -255,6 +255,24 @@
         self.option(txt)
 
 
+class Checkbox(InputElement):
+    """A simple Checkbox
+
+    Args:
+        label: Caption of this checkbox
+        state: The initial change
+    """
+    def __init__(self, label, state):
+        self.label = label
+        self.state(state)
+
+    @Element.signal_change
+    def state(self, s):
+        if s in [True, False]:
+            self._state = s
+        return self._state
+
+
 class ProgressBar(Element):
     """A abstract progress bar.
 
diff --git a/scripts/tui/src/ovirt/node/ui/builder.py b/scripts/tui/src/ovirt/node/ui/builder.py
index 8758c91..4645f93 100644
--- a/scripts/tui/src/ovirt/node/ui/builder.py
+++ b/scripts/tui/src/ovirt/node/ui/builder.py
@@ -95,6 +95,7 @@
         ovirt.node.ui.Row: build_row,
         ovirt.node.ui.ProgressBar: build_progressbar,
         ovirt.node.ui.Table: build_table,
+        ovirt.node.ui.Checkbox: build_checkbox,
     }
 
     # Check if builder is available for UI Element
@@ -110,7 +111,8 @@
                       ovirt.node.ui.PasswordEntry,
                       ovirt.node.ui.Label,
                       ovirt.node.ui.KeywordLabel,
-                      ovirt.node.ui.Options]:
+                      ovirt.node.ui.Options,
+                      ovirt.node.ui.Checkbox]:
         model = plugin.model()
         if path in model:
             text = model[path]
@@ -219,6 +221,11 @@
     return widget
 
 
+def build_checkbox(path, item, tui, plugin):
+    widget = ovirt.node.ui.widgets.Checkbox(item.label, item.state())
+    return widget
+
+
 def build_row(path, container_item, tui, plugin):
     widgets = []
     for path, element in container_item.children:
diff --git a/scripts/tui/src/ovirt/node/ui/widgets.py b/scripts/tui/src/ovirt/node/ui/widgets.py
index 991e1f3..5409fb1 100644
--- a/scripts/tui/src/ovirt/node/ui/widgets.py
+++ b/scripts/tui/src/ovirt/node/ui/widgets.py
@@ -399,6 +399,23 @@
         self.select(txt)
 
 
+class Checkbox(urwid.WidgetWrap):
+    def __init__(self, label, state):
+        self._label = urwid.Text(label)
+        self._label_attrmap = urwid.AttrMap(self._label,
+                                            "plugin.widget.checkbox.label")
+        self._checkbox = urwid.CheckBox("", state)
+        self._divider = urwid.Divider()
+        self._container = urwid.Columns([self._label_attrmap,
+                                         self._checkbox])
+        super(Checkbox, self).__init__(urwid.Pile([self._container,
+                                                   self._divider]))
+
+    def set_text(self, s):
+        if s in [True, False]:
+            self._checkbox.set_state(s)
+
+
 class PageWidget(urwid.WidgetWrap):
     save_button = None
 


--
To view, visit http://gerrit.ovirt.org/9920
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f4eb2309832a7dad2a96cd3da4eb85e31e94728
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list