[node-patches] Change in ovirt-node[master]: tui: Fix color and size handling

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


Fabian Deutsch has uploaded a new change for review.

Change subject: tui: Fix color and size handling
......................................................................

tui: Fix color and size handling

Change-Id: I4216d39046ce5662ef80fc336eedffc0f52a6c7d
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/tui.py
M scripts/tui/src/ovirt/node/ui/builder.py
M scripts/tui/src/ovirt/node/ui/widgets.py
M scripts/tui/src/ovirt/node/valid.py
4 files changed, 36 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/17/9917/1

diff --git a/scripts/tui/src/ovirt/node/tui.py b/scripts/tui/src/ovirt/node/tui.py
index 5997fcf..2d99818 100644
--- a/scripts/tui/src/ovirt/node/tui.py
+++ b/scripts/tui/src/ovirt/node/tui.py
@@ -51,6 +51,8 @@
 
     __widget_stack = []
 
+    _current_plugin = None
+
     header = u"\n Configuration TUI\n"
     footer = u"Press ctrl+c to exit"
 
@@ -81,6 +83,8 @@
                ('plugin.widget.progressbar.complete', None, 'light gray'),
                ('plugin.widget.options.label', 'dark gray, bold'),
                ('plugin.widget.dialog', None),
+               ('plugin.widget.page', None),
+               ('plugin.widget.page.frame', None),
                ]
 
     def __init__(self, app):
@@ -113,23 +117,35 @@
         header = urwid.Text(self.header, wrap='clip')
         header = urwid.AttrMap(header, 'header')
         footer = urwid.Text(self.footer, wrap='clip')
-        return urwid.Frame(body, header, footer)
+        screen = urwid.Frame(body, header, footer)
+        return urwid.AttrMap(screen, "screen")
 
     def display_plugin(self, plugin):
+        if self._current_plugin:
+            pending_changes = self._current_plugin.pending_changes()
+            if pending_changes:
+                LOGGER.warning("Pending changes: %s" % pending_changes)
+                self.display_dialog(urwid.Filler(urwid.Text(
+                                    "Pending changes:\n%s" % pending_changes)),
+                                    "There are pending changes")
+                return
+
         timer = timeit.Timer()
+        self._current_plugin = plugin
         page = ovirt.node.ui.builder.page_from_plugin(self, plugin)
         self.display_page(page)
         LOGGER.debug("Build and displayed page in %ss" % timer.timeit())
 
     def display_page(self, page):
-        # FIXME why is this fixed?
-        filler = urwid.Filler(page, ("fixed top", 1), height=35)
-#        filler = urwid.Filler(page)
+        LOGGER.debug("Displaying page %s" % page)
+#        filler = urwid.Filler(page, ("fixed top", 1), height=35)
+        filler = urwid.Pile([page])
         self.__page_frame.body = filler
 
     def display_dialog(self, body, title):
         LOGGER.debug("Displaying dialog: %s / %s" % (body, title))
-        filler = urwid.Filler(body, ("fixed top", 1), height=35)
+#        filler = urwid.Filler(body, ("fixed top", 1), height=35)
+        filler = urwid.Pile([body])
         dialog = ovirt.node.ui.widgets.ModalDialog(title, filler, "esc",
                                                    self.__loop.widget)
         urwid.connect_signal(dialog, "close",
@@ -146,7 +162,10 @@
                 if len(self.__widget_stack) > 0:
                     self.__loop.widget = self.__widget_stack[:-1]
                 else:
+                    LOGGER.debug("No more dialog, main frame " + \
+                                 "%s" % self.__main_frame)
                     self.__loop.widget = self.__main_frame
+            self.draw_screen()
             LOGGER.debug("Dialog closed")
 
     def popup(self, title, msg, buttons=None):
@@ -245,10 +264,9 @@
         """Run the UI
         """
         self.__main_frame = self.__create_screen()
-        self.__main_frame_attrmap = urwid.AttrMap(self.__main_frame, "screen")
         self.__register_default_hotkeys()
 
-        self.__loop = urwid.MainLoop(self.__main_frame_attrmap,
+        self.__loop = urwid.MainLoop(self.__main_frame,
                               self._convert_palette(),
                               input_filter=self.__filter_hotkeys)
         self.__loop.run()
diff --git a/scripts/tui/src/ovirt/node/ui/builder.py b/scripts/tui/src/ovirt/node/ui/builder.py
index 41d9b27..19d556e 100644
--- a/scripts/tui/src/ovirt/node/ui/builder.py
+++ b/scripts/tui/src/ovirt/node/ui/builder.py
@@ -76,6 +76,7 @@
         tui.notify("error", "Initial model validation failed.")
 
     page = ovirt.node.ui.widgets.PageWidget(widgets)
+    page.plugin = plugin
 
     return page
 
diff --git a/scripts/tui/src/ovirt/node/ui/widgets.py b/scripts/tui/src/ovirt/node/ui/widgets.py
index 5a7dced..fb57a05 100644
--- a/scripts/tui/src/ovirt/node/ui/widgets.py
+++ b/scripts/tui/src/ovirt/node/ui/widgets.py
@@ -243,7 +243,7 @@
     notice = property(lambda self: self._notice.get_text(), \
                       lambda self, v: self._notice.set_text(v))
 
-    selectable = lambda self: True
+    _selectable = True
 
     def __init__(self, label, mask=None, align_vertical=False):
         with_linebox = True
@@ -286,7 +286,7 @@
         super(Entry, self).__init__(self._pile)
 
     def enable(self, is_enabled):
-        self.selectable = lambda: is_enabled
+        self._selectable = is_enabled
         attr_map = {None: "plugin.widget.entry"}
         if not is_enabled:
             attr_map = {None: "plugin.widget.entry.disabled"}
@@ -300,6 +300,10 @@
 
     def set_text(self, txt):
         self._edit.set_edit_text(txt)
+
+    def selectable(self):
+        return self._selectable
+
 
 
 class PasswordEntry(Entry):
@@ -398,7 +402,9 @@
 #        self._listwalker = urwid.SimpleListWalker(widgets)
 #        self._container = urwid.ListBox(self._listwalker)
         self._container = urwid.Pile(widgets)
-        super(PageWidget, self).__init__(self._container)
+        self._container_attrmap = urwid.AttrMap(self._container,
+                                                "plugin.widget.page")
+        super(PageWidget, self).__init__(self._container_attrmap)
 
 
 class RowWidget(urwid.Columns):
diff --git a/scripts/tui/src/ovirt/node/valid.py b/scripts/tui/src/ovirt/node/valid.py
index 460ce6a..535e41a 100644
--- a/scripts/tui/src/ovirt/node/valid.py
+++ b/scripts/tui/src/ovirt/node/valid.py
@@ -98,7 +98,7 @@
     def validate(self, value):
         if type(self.pattern) in [str, unicode]:
             self.pattern = (self.pattern, )
-        return re.compile(*self.pattern).search(str(value)) != None
+        return re.compile(*self.pattern).search(value) != None
 
 
 class Text(RegexValidator):


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

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