[node-patches] Change in ovirt-node[master]: ui: Add basic window abstraction

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 basic window abstraction
......................................................................

ui: Add basic window abstraction

Change-Id: Id9fcf58ddcfcbd31a02f84c2cf2d2cf4c57c16c0
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/app.py
M scripts/tui/src/ovirt/node/ui/__init__.py
R scripts/tui/src/ovirt/node/ui/tui.py
3 files changed, 44 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/24/9924/1

diff --git a/scripts/tui/src/ovirt/node/app.py b/scripts/tui/src/ovirt/node/app.py
index a46c840..a036d55 100644
--- a/scripts/tui/src/ovirt/node/app.py
+++ b/scripts/tui/src/ovirt/node/app.py
@@ -32,7 +32,7 @@
 LOGGER = logging.getLogger(__name__)
 
 
-import ovirt.node.tui
+import ovirt.node.ui.tui
 import ovirt.node.utils
 
 
@@ -41,8 +41,11 @@
 
     ui = None
 
-    def __init__(self):
-        self.ui = ovirt.node.tui.UrwidTUI(self)
+    def __init__(self, ui_backend="urwid"):
+        ui_backend_class = {
+            "urwid": ovirt.node.ui.tui.UrwidTUI
+        }[ui_backend]
+        self.ui = ui_backend_class(self)
 
     def __load_plugins(self):
         self.plugins = [m.Plugin(self) for m in ovirt.node.plugins.load_all()]
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index aaa974b..7168ea2 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -321,3 +321,34 @@
         if selected in dict(self.items).keys():
             self._selected = selected
         return self._selected
+
+
+class Window(Element):
+    """Abstract Window definition
+    """
+
+    def __init__(self, app):
+        LOGGER.info("Creating UI for application '%s'" % app)
+        self.app = app
+
+        self._plugins = {}
+        self._hotkeys = {}
+
+        self.footer = None
+
+
+    def register_plugin(self, title, plugin):
+        """Register a plugin to be shown in the UI
+        """
+        self._plugins[title] = plugin
+
+    def register_hotkey(self, hotkey, cb):
+        """Register a hotkey
+        """
+        if type(hotkey) is str:
+            hotkey = [hotkey]
+        LOGGER.debug("Registering hotkey '%s': %s" % (hotkey, cb))
+        self._hotkeys[str(hotkey)] = cb
+
+    def run(self):
+        raise NotImplementedError
diff --git a/scripts/tui/src/ovirt/node/tui.py b/scripts/tui/src/ovirt/node/ui/tui.py
similarity index 93%
rename from scripts/tui/src/ovirt/node/tui.py
rename to scripts/tui/src/ovirt/node/ui/tui.py
index 47c5ad8..b5b821b 100644
--- a/scripts/tui/src/ovirt/node/tui.py
+++ b/scripts/tui/src/ovirt/node/ui/tui.py
@@ -38,11 +38,11 @@
 LOGGER = logging.getLogger(__name__)
 
 
-class UrwidTUI(object):
+class UrwidTUI(ovirt.node.ui.Window):
     app = None
 
-    __pages = {}
-    __hotkeys = {}
+    _plugins = {}
+    _hotkeys = {}
 
     __loop = None
     __main_frame = None
@@ -97,9 +97,10 @@
     def __init__(self, app):
         LOGGER.info("Creating urwid tui for '%s'" % app)
         self.app = app
+        super(UrwidTUI, self).__init__(app)
 
     def __build_menu(self):
-        self.__menu = ovirt.node.ui.widgets.PluginMenu(self.__pages)
+        self.__menu = ovirt.node.ui.widgets.PluginMenu(self._plugins)
 
         def menu_item_changed(plugin):
             self.display_plugin(plugin)
@@ -195,9 +196,9 @@
                 self.close_dialog(self.__widget_stack[-1])
                 return
 
-        if key in self.__hotkeys.keys():
+        if key in self._hotkeys.keys():
             LOGGER.debug("Running hotkeys: %s" % key)
-            self.__hotkeys[key]()
+            self._hotkeys[key]()
 
         LOGGER.debug("Keypress: %s" % key)
 
@@ -232,19 +233,6 @@
             def __exit__(self, a, b, c):
                 self.__loop.screen.start()
         return SuspendedScreen(self.__loop)
-
-    def register_plugin(self, title, plugin):
-        """Register a plugin to be shown in the UI
-        """
-        self.__pages[title] = plugin
-
-    def register_hotkey(self, hotkey, cb):
-        """Register a hotkey
-        """
-        if type(hotkey) is str:
-            hotkey = [hotkey]
-        LOGGER.debug("Registering hotkey '%s': %s" % (hotkey, cb))
-        self.__hotkeys[str(hotkey)] = cb
 
     def quit(self):
         """Quit the UI


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

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