[node-patches] Change in ovirt-node[master]: ui: Implement Buttons and divider, add SaveButton

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


Fabian Deutsch has uploaded a new change for review.

Change subject: ui: Implement Buttons and divider, add SaveButton
......................................................................

ui: Implement Buttons and divider, add SaveButton

Change-Id: I3d1fbf4fb7a8d6b786e27a5f7902d43394d77d6f
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/plugins/__init__.py
M scripts/tui/src/ovirt/node/plugins/example.py
M scripts/tui/src/ovirt/node/plugins/ping.py
M scripts/tui/src/ovirt/node/tui.py
M scripts/tui/src/ovirt/node/widgets.py
5 files changed, 88 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/70/9870/1

diff --git a/scripts/tui/src/ovirt/node/plugins/__init__.py b/scripts/tui/src/ovirt/node/plugins/__init__.py
index 295bf9e..00634af 100644
--- a/scripts/tui/src/ovirt/node/plugins/__init__.py
+++ b/scripts/tui/src/ovirt/node/plugins/__init__.py
@@ -270,6 +270,20 @@
     pass
 
 
+class Button(Label, InputWidget):
+    def __init__(self, label="Save", enabled=True):
+        self._enabled = enabled
+        super(Button, self).__init__(label)
+
+
+class SaveButton(Button):
+    pass
+
+
+class Divider(Widget):
+    def __init__(self, char=u" "):
+        self.char = char
+
 class InvalidData(Exception):
     """E.g. if a string contains characters which are not allowed
     """
diff --git a/scripts/tui/src/ovirt/node/plugins/example.py b/scripts/tui/src/ovirt/node/plugins/example.py
index 83ccac7..ad43100 100644
--- a/scripts/tui/src/ovirt/node/plugins/example.py
+++ b/scripts/tui/src/ovirt/node/plugins/example.py
@@ -7,7 +7,6 @@
 
 import ovirt.node.plugins
 import ovirt.node.valid
-from ovirt.node.plugins import Header, Entry, PasswordEntry
 
 LOGGER = logging.getLogger(__name__)
 
@@ -45,10 +44,12 @@
         This is an ordered list of (path, widget) tuples.
         """
         widgets = [
-            ("foo.section", Header("Subsection")),
-            ("foo.hostname", Entry(label="Hostname")),
-            ("foo.port", Entry(label="Port")),
-            ("foo.password", PasswordEntry(label="Password")),
+            ("foo.section", ovirt.node.plugins.Header("Subsection")),
+            ("foo.hostname", ovirt.node.plugins.Entry(label="Hostname")),
+            ("foo.port", ovirt.node.plugins.Entry(label="Port")),
+            ("foo.password", ovirt.node.plugins.PasswordEntry(label="Password")),
+            # This SaveButton will automatuically trigger the do_merge at the end
+            ("foo.do_save", ovirt.node.plugins.SaveButton()),
         ]
         self._widgets = dict(widgets)
         return widgets
diff --git a/scripts/tui/src/ovirt/node/plugins/ping.py b/scripts/tui/src/ovirt/node/plugins/ping.py
index 6b884f2..51b1b75 100644
--- a/scripts/tui/src/ovirt/node/plugins/ping.py
+++ b/scripts/tui/src/ovirt/node/plugins/ping.py
@@ -5,7 +5,7 @@
 
 import ovirt.node.plugins
 import ovirt.node.valid
-from ovirt.node.plugins import Header, Label, Entry, PasswordEntry
+import ovirt.node.plugins
 import ovirt.node.utils
 
 LOGGER = logging.getLogger(__name__)
@@ -41,15 +41,22 @@
                 "ping.count": ovirt.node.valid.Number(min=1, max=20),
             }
 
+    def ui_metadata(self):
+        meta = super(Plugin, self).ui_metadata()
+#        meta.save_button = False
+        return meta
+
     def ui_content(self):
         """Describes the UI this plugin requires
         This is an ordered list of (path, widget) tuples.
         """
         widgets = [
-            ("ping.header", Header("Ping a remote host")),
-            ("ping.address", Entry("Address")),
-            ("ping.count", Entry("Count")),
-            ("ping.result", Label("Result:")),
+            ("ping.header", ovirt.node.plugins.Header("Ping a remote host")),
+            ("ping.address", ovirt.node.plugins.Entry("Address")),
+            ("ping.count", ovirt.node.plugins.Entry("Count")),
+            ("ping.do_ping", ovirt.node.plugins.Button("Ping")),
+            ("ping.result-divider", ovirt.node.plugins.Divider("-")),
+            ("ping.result", ovirt.node.plugins.Label("Result:")),
         ]
         self._widgets = dict(widgets)
         return widgets
@@ -62,9 +69,13 @@
             self._model.update(changes)
         if "ping.count" in changes:
             self._model.update(changes)
+        if "ping.do_ping" in changes:
+            self.on_merge(changes)
 
     def on_merge(self, changes):
         """Applies the changes to the plugins model, will do all required logic
+        Normally on_merge is called by pushing the SaveButton instance, in this
+        case it is called by on_change
         """
 
         if "ping.address" in self._model:
@@ -77,8 +88,7 @@
                 cmd = "ping6"
 
             cmd = "%s -c %s %s" % (cmd, count, addr)
-            out = cmd
+            out = ""
             for line in ovirt.node.utils.pipe_async(cmd):
-                LOGGER.debug("xx" + line)
                 out += line
                 self._widgets["ping.result"].text("Result:\n\n%s" % out)
diff --git a/scripts/tui/src/ovirt/node/tui.py b/scripts/tui/src/ovirt/node/tui.py
index fb6e0ad..1765160 100644
--- a/scripts/tui/src/ovirt/node/tui.py
+++ b/scripts/tui/src/ovirt/node/tui.py
@@ -36,6 +36,8 @@
                ('plugin.widget.disabled', 'dark gray', 'light gray'),
                ('plugin.widget.notice', 'light red', ''),
                ('plugin.widget.header', 'light blue', 'light gray'),
+               ('plugin.widget.divider', 'dark gray', ''),
+               ('plugin.widget.button', 'dark blue', ''),
                ]
 
     def __init__(self, app):
@@ -65,7 +67,10 @@
             ovirt.node.plugins.Label: ovirt.node.widgets.Label,
             ovirt.node.plugins.Header: ovirt.node.widgets.Header,
             ovirt.node.plugins.Entry: ovirt.node.widgets.Entry,
-            ovirt.node.plugins.PasswordEntry: ovirt.node.widgets.PasswordEntry
+            ovirt.node.plugins.PasswordEntry: ovirt.node.widgets.PasswordEntry,
+            ovirt.node.plugins.Button: ovirt.node.widgets.Button,
+            ovirt.node.plugins.SaveButton: ovirt.node.widgets.Button,
+            ovirt.node.plugins.Divider: ovirt.node.widgets.Divider,
         }
 
         assert type(item) in item_to_widget_map.keys(), \
@@ -117,6 +122,20 @@
                 self.__loop.draw_screen()
             item.connect_signal("text[change]", on_item_text_change_cb)
 
+        elif type(item) in [ovirt.node.plugins.Button,
+                            ovirt.node.plugins.SaveButton]:
+            widget = widget_class(item.text())
+            def on_widget_click_cb(widget, data=None):
+                if type(item) is ovirt.node.plugins.SaveButton:
+                    plugin._on_ui_save()
+                else:
+#                   Nit propagating the signal as a signal to the plugin
+#                   item.emit_signal("click", widget)
+                    plugin._on_ui_change({path: True})
+            urwid.connect_signal(widget, "click", on_widget_click_cb)
+
+        elif type(item) in [ovirt.node.plugins.Divider]:
+            widget = widget_class(item.char)
         return widget
 
     def __build_plugin_widget(self, plugin):
@@ -128,10 +147,12 @@
             widget = self.__build_widget_for_item(plugin, path, item)
             widgets.append(("flow", widget))
 
-        save = urwid.Button("Save", lambda x: plugin._on_ui_save())
-        save = urwid.Padding(save, "left", width=8)
-        save = urwid.Filler(save, ("fixed top", 1))
-        widgets.append(save)
+#            save = urwid.Button("Save", lambda x: plugin._on_ui_save())
+#            save = urwid.Padding(save, "left", width=8)
+#            save = urwid.Filler(save, ("fixed top", 1))
+
+        widgets.append(urwid.Filler(urwid.Text("")))
+
 
         pile = urwid.Pile(widgets)
         # FIXME why is this fixed?
diff --git a/scripts/tui/src/ovirt/node/widgets.py b/scripts/tui/src/ovirt/node/widgets.py
index 3a4e9d4..c3b173b 100644
--- a/scripts/tui/src/ovirt/node/widgets.py
+++ b/scripts/tui/src/ovirt/node/widgets.py
@@ -145,7 +145,6 @@
 
 
 class Entry(urwid.WidgetWrap):
-
     signals = ['change']
 
     notice = property(lambda self: self._notice.get_text(), \
@@ -190,3 +189,28 @@
 class PasswordEntry(Entry):
     def __init__(self, label, value=None):
         super(PasswordEntry, self).__init__(label, value, mask="*")
+
+
+class Button(urwid.WidgetWrap):
+    signals = ["click"]
+
+    def __init__(self, label):
+        self._button = urwid.Button(label)
+
+        def on_click_cb(widget, data=None):
+            urwid.emit_signal(self, 'click', self)
+        urwid.connect_signal(self._button, 'click', on_click_cb)
+
+        self._button_attrmap = urwid.AttrMap(self._button,
+                                              "plugin.widget.button")
+
+        self._padding = urwid.Padding(self._button_attrmap, width=len(label)+4)
+
+        super(Button, self).__init__(self._padding)
+
+class Divider(urwid.WidgetWrap):
+    def __init__(self, char=u" "):
+        self._divider = urwid.Divider(char)
+        self._divider_attrmap = urwid.AttrMap(self._divider,
+                                              "plugin.widget.divider")
+        super(Divider, self).__init__(self._divider_attrmap)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d1fbf4fb7a8d6b786e27a5f7902d43394d77d6f
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