[node-patches] Change in ovirt-node[master]: Add ovirt-node.ui.ProgressBar element

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


Fabian Deutsch has uploaded a new change for review.

Change subject: Add ovirt-node.ui.ProgressBar element
......................................................................

Add ovirt-node.ui.ProgressBar element

Change-Id: I3ba4f6739ba82b6b0aeadafe09b0cb4599babac1
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/plugins/ping.py
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
5 files changed, 55 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/95/9895/1

diff --git a/scripts/tui/src/ovirt/node/plugins/ping.py b/scripts/tui/src/ovirt/node/plugins/ping.py
index 0cc10f1..855a11a 100644
--- a/scripts/tui/src/ovirt/node/plugins/ping.py
+++ b/scripts/tui/src/ovirt/node/plugins/ping.py
@@ -50,8 +50,9 @@
                 # The target address
                 "ping.address": "127.0.0.1",
                 "ping.count": "3",
+                "ping.progress": "0",
                 # The result field
-                "ping.result": ""
+                "ping.result": "",
             }
         return self._model
 
@@ -73,7 +74,9 @@
             ("ping.address", ovirt.node.ui.Entry("Address")),
             ("ping.count", ovirt.node.ui.Entry("Count")),
             ("ping.do_ping", ovirt.node.ui.Button("Ping")),
-            ("ping.result-divider", ovirt.node.ui.Divider("-")),
+            ("ping.progress._space", ovirt.node.ui.Divider()),
+            ("ping.progress", ovirt.node.ui.ProgressBar()),
+            ("ping.result._space", ovirt.node.ui.Divider("-")),
             ("ping.result", ovirt.node.ui.Label("Result:")),
         ]
         # Save it "locally" as a dict, for better accessability
@@ -112,6 +115,10 @@
 
             cmd = "%s -c %s %s" % (cmd, count, addr)
             out = ""
+            current = 0
             for line in ovirt.node.utils.process.pipe_async(cmd):
                 out += line
+                if "icmp_req" in line:
+                    current += 100.0 / float(count)
+                    self._widgets["ping.progress"].current(current)
                 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 90f2757..65ecc6f 100644
--- a/scripts/tui/src/ovirt/node/tui.py
+++ b/scripts/tui/src/ovirt/node/tui.py
@@ -69,6 +69,9 @@
                ('plugin.widget.button.disabled', 'light gray', ''),
                ('plugin.widget.label', '', ''),
                ('plugin.widget.label.keyword', 'bold', ''),
+               ('plugin.widget.progressbar.box', 'light gray', ''),
+               ('plugin.widget.progressbar.uncomplete', '', ''),
+               ('plugin.widget.progressbar.complete', '', 'light gray'),
                ]
 
     def __init__(self, app):
@@ -99,7 +102,7 @@
 
     def display_page(self, page):
         # FIXME why is this fixed?
-        filler = urwid.Filler(page, ("fixed top", 1), height=20)
+        filler = urwid.Filler(page, ("fixed top", 1), height=30)
         self.__page_frame.body = filler
 
     def display_dialog(self, body, title):
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index 70e0160..fc948fa 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -250,3 +250,16 @@
 
     def set_text(self, txt):
         self.option(txt)
+
+
+class ProgressBar(Element):
+    def __init__(self, current=0, done=100):
+        self.current(current)
+        self.done = done
+        super(ProgressBar, self).__init__()
+
+    @Element.signal_change
+    def current(self, current=None):
+        if current is not None:
+            self._current = current
+        return self._current
diff --git a/scripts/tui/src/ovirt/node/ui/builder.py b/scripts/tui/src/ovirt/node/ui/builder.py
index 5771750..96aee29 100644
--- a/scripts/tui/src/ovirt/node/ui/builder.py
+++ b/scripts/tui/src/ovirt/node/ui/builder.py
@@ -92,6 +92,7 @@
         ovirt.node.ui.Divider: build_divider,
         ovirt.node.ui.Options: build_options,
         ovirt.node.ui.Row: build_row,
+        ovirt.node.ui.ProgressBar: build_progressbar,
     }
 
     # Check if builder is available for UI Element
@@ -236,3 +237,16 @@
         widgets.append(child)
 
     return urwid.Columns(widgets)
+
+
+def build_progressbar(path, item, tui, plugin):
+    widget = ovirt.node.ui.widgets.ProgressBarWidget(item.current(), item.done)
+
+    def on_item_current_change_cb(w, v):
+        LOGGER.debug("Model changed, updating widget '%s': %s" % (w,
+                                                                  v))
+        widget.set_completion(v)
+        tui.draw_screen()
+    item.connect_signal("current", on_item_current_change_cb)
+
+    return widget
diff --git a/scripts/tui/src/ovirt/node/ui/widgets.py b/scripts/tui/src/ovirt/node/ui/widgets.py
index b13dc02..83431fa 100644
--- a/scripts/tui/src/ovirt/node/ui/widgets.py
+++ b/scripts/tui/src/ovirt/node/ui/widgets.py
@@ -314,3 +314,18 @@
 
 class RowWidget(urwid.Columns):
     pass
+
+
+class ProgressBarWidget(urwid.WidgetWrap):
+    def __init__(self, current, done):
+        self._progressbar = urwid.ProgressBar(
+                               "plugin.widget.progressbar.uncomplete",
+                               "plugin.widget.progressbar.complete",
+                               current, done)
+        self._linebox = urwid.LineBox(self._progressbar)
+        self._linebox_attrmap = urwid.AttrMap(self._linebox,
+                                        "plugin.widget.progressbar.box")
+        super(ProgressBarWidget, self).__init__(self._linebox_attrmap)
+
+    def set_completion(self, v):
+        self._progressbar.set_completion(v)


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

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