[node-patches] Change in ovirt-node[master]: HACK: Can display dialogs now

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


Fabian Deutsch has uploaded a new change for review.

Change subject: HACK: Can display dialogs now
......................................................................

HACK: Can display dialogs now

Change-Id: Ic1879177815d6c7a97e7601f97432a59254baf7e
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/plugins/example.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, 56 insertions(+), 45 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/92/9892/1

diff --git a/scripts/tui/src/ovirt/node/plugins/example.py b/scripts/tui/src/ovirt/node/plugins/example.py
index 02d6c5b..7436c10 100644
--- a/scripts/tui/src/ovirt/node/plugins/example.py
+++ b/scripts/tui/src/ovirt/node/plugins/example.py
@@ -107,6 +107,10 @@
             if "/" in changes["foo.port"]:
                 raise ovirt.node.exceptions.InvalidData("No slashes allowed")
 
+        if "dialog.button" in changes:
+            LOGGER.debug("Request to close the dialog")
+            self._widgets["dialog.dialog"].close()
+
         return True
 
     def on_merge(self, effective_changes):
@@ -121,9 +125,15 @@
         return dialog
 
     def _create_dialog(self, txt):
-        page = ovirt.node.ui.Dialog("Information", [
+        LOGGER.debug("Building dialog")
+        widgets = [
                 ("dialog.text", ovirt.node.ui.Label(txt)),
                 ("dialog.button", ovirt.node.ui.Button("Close"))
-                ])
+                ]
+        page = ovirt.node.ui.Dialog("Information", widgets)
         page.has_save_button = False
+
+        self._widgets.update(dict(widgets))
+        self._widgets["dialog.dialog"] = page
+
         return page
diff --git a/scripts/tui/src/ovirt/node/tui.py b/scripts/tui/src/ovirt/node/tui.py
index 54c24c3..90f2757 100644
--- a/scripts/tui/src/ovirt/node/tui.py
+++ b/scripts/tui/src/ovirt/node/tui.py
@@ -48,6 +48,8 @@
     __menu = None
     __page_frame = None
 
+    __dialogs = []
+
     header = u"\n Configuration TUI\n"
     footer = u"Press ctrl+c to exit"
 
@@ -93,43 +95,48 @@
 
     def __change_to_plugin(self, plugin):
         page = ovirt.node.ui.builder.page_from_plugin(self, plugin)
-        self._display_page(page)
+        self.display_page(page)
 
-    def _display_page(self, page):
+    def display_page(self, page):
         # FIXME why is this fixed?
         filler = urwid.Filler(page, ("fixed top", 1), height=20)
         self.__page_frame.body = filler
 
-    def _display_dialog(self, body, title):
+    def display_dialog(self, body, title):
         filler = urwid.Filler(body, ("fixed top", 1), height=20)
-        dialog = ovirt.node.ui.widgets.ModalDialog(filler,
-                                                   title, "esc",
+        dialog = ovirt.node.ui.widgets.ModalDialog(title, filler, "esc",
                                                    self.__loop.widget)
+        urwid.connect_signal(dialog, "close", lambda: self.close_dialog())
         self.__loop.widget = dialog
+        return dialog
 
-    def display(self, widget):
-        return {
-                   ovirt.node.ui.widgets.PageWidget: self._display_page
-               }[type(widget)](widget)
+    def close_dialog(self):
+        # FIXME stack to allow more than one dialog
+        if type(self.__loop.widget) is ovirt.node.ui.widgets.ModalDialog:
+            self.__loop.widget = self.__loop.widget.previous_widget
+            LOGGER.debug("Dialog closed")
 
     def popup(self, title, msg, buttons=None):
         LOGGER.debug("Launching popup")
         body = urwid.Filler(urwid.Text(msg))
-        self._display_dialog(body)
+        self.display_dialog(body)
 
     def __filter_hotkeys(self, keys, raw):
         key = str(keys)
-        LOGGER.debug("Keypress: %s" % key)
+
         if type(self.__loop.widget) is ovirt.node.ui.widgets.ModalDialog:
             LOGGER.debug("Modal dialog escape: %s" % key)
             dialog = self.__loop.widget
             if dialog.escape_key in keys:
-                self.__loop.widget = dialog.previous_widget
-            return
+                self.close_dialog()
+#            return
 
         if key in self.__hotkeys.keys():
             LOGGER.debug("Running hotkeys: %s" % key)
             self.__hotkeys[key]()
+
+        LOGGER.debug("Keypress: %s" % key)
+
         return keys
 
     def __register_default_hotkeys(self):
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index 08783ce..70e0160 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -124,6 +124,7 @@
 
     def __init__(self, children):
         self.children = children
+        super(ContainerElement, self).__init__()
 
     @property
     @deprecated
@@ -144,10 +145,16 @@
 class Dialog(Page):
     """An abstract dialog, similar to a page
     """
+
     def __init__(self, title, children):
         self.title = title
+        self.close(False) # FIXME hack
         super(Dialog, self).__init__(children)
 
+    @Element.signal_change
+    def close(self, v=True):
+        self._close = v
+
 
 class Row(ContainerElement):
     """Align elements horizontally in one row
diff --git a/scripts/tui/src/ovirt/node/ui/builder.py b/scripts/tui/src/ovirt/node/ui/builder.py
index f26bc6b..5771750 100644
--- a/scripts/tui/src/ovirt/node/ui/builder.py
+++ b/scripts/tui/src/ovirt/node/ui/builder.py
@@ -191,13 +191,18 @@
         if type(item) is ovirt.node.ui.SaveButton:
             r = plugin._on_ui_save()
             LOGGER.debug("Got save: %s" % r)
-            # FIXME hacks to display page or dialog
+
             if type(r) in [ovirt.node.ui.Page]:
                 w = build_page(tui, plugin, r)
-                tui.display(w)
+                tui.display_page(w)
+
             elif type(r) in [ovirt.node.ui.Dialog]:
                 w = build_page(tui, plugin, r)
-                tui._display_dialog(w, r.title)
+                dialog = tui.display_dialog(w, r.title)
+                def on_item_close_changed_cb(i, v):
+                    dialog.close()
+                r.connect_signal("close", on_item_close_changed_cb)
+
         else:
 #           Not propagating the signal as a signal to the plugin
 #           item.emit_signal("click", widget)
diff --git a/scripts/tui/src/ovirt/node/ui/widgets.py b/scripts/tui/src/ovirt/node/ui/widgets.py
index a59d4aa..b13dc02 100644
--- a/scripts/tui/src/ovirt/node/ui/widgets.py
+++ b/scripts/tui/src/ovirt/node/ui/widgets.py
@@ -104,32 +104,10 @@
         self.__list.set_focus(n)
 
 
-class DialogBox(urwid.WidgetWrap):
-    def __init__(self, body, title, bodyattr=None, titleattr=None):
-        self.body = urwid.LineBox(body)
-        self.title = urwid.Text(title)
-        if titleattr is not None:
-            self.title = urwid.AttrMap(self.title, titleattr)
-        if bodyattr is not None:
-            self.body = urwid.AttrMap(self.body, bodyattr)
+class ModalDialog(urwid.WidgetWrap):
+    signals = ['close']
 
-        box = urwid.Overlay(self.title, self.body,
-                            align='center',
-                            valign='top',
-                            width=len(title),
-                            height=None,
-                            )
-        urwid.WidgetWrap.__init__(self, box)
-
-    def selectable(self):
-        return self.body.selectable()
-
-    def keypress(self, size, key):
-        return self.body.keypress(size, key)
-
-
-class ModalDialog(urwid.Overlay):
-    def __init__(self, body, title, escape_key, previous_widget, bodyattr=None,
+    def __init__(self, title, body, escape_key, previous_widget, bodyattr=None,
                  titleattr=None):
         self.escape_key = escape_key
         self.previous_widget = previous_widget
@@ -137,11 +115,15 @@
         if type(body) in [str, unicode]:
             body = urwid.Text(body)
 
-        box = DialogBox(body, title, bodyattr, titleattr)
+        body = urwid.LineBox(body, title)
 
-        super(ModalDialog, self).__init__(box, previous_widget, 'center',
+        overlay = urwid.Overlay(body, previous_widget, 'center',
                                           ('relative', 70), 'middle',
                                           ('relative', 70))
+        super(ModalDialog, self).__init__(overlay)
+
+    def close(self):
+        urwid.emit_signal(self, "close")
 
 
 class Label(urwid.WidgetWrap):


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

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