[node-patches] Change in ovirt-node[master]: installer: Add custom device dialog

fabiand at fedoraproject.org fabiand at fedoraproject.org
Mon Jan 28 17:34:52 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: installer: Add custom device dialog
......................................................................

installer: Add custom device dialog

Change-Id: Ic5b6e16cbdf900c24e02e4b9effc61b81249f4ec
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/installer/boot_device_page.py
M scripts/tui/src/ovirt/node/installer/installation_device_page.py
M scripts/tui/src/ovirt/node/setup/support_page.py
M scripts/tui/src/ovirt/node/ui/__init__.py
M scripts/tui/src/ovirt/node/ui/urwid_builder.py
M scripts/tui/src/ovirt/node/ui/widgets.py
6 files changed, 87 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/79/11479/1

diff --git a/scripts/tui/src/ovirt/node/installer/boot_device_page.py b/scripts/tui/src/ovirt/node/installer/boot_device_page.py
index b42152b..8133aa2 100644
--- a/scripts/tui/src/ovirt/node/installer/boot_device_page.py
+++ b/scripts/tui/src/ovirt/node/installer/boot_device_page.py
@@ -22,7 +22,7 @@
 """
 Boot device selection page of the installer
 """
-from ovirt.node import plugins, ui, utils
+from ovirt.node import plugins, ui, utils, valid
 
 
 class Plugin(plugins.NodePlugin):
@@ -44,7 +44,8 @@
         return self._model
 
     def validators(self):
-        return {"boot.device": lambda v: None if v else "No device given"
+        return {"boot.device": lambda v: None if v else "No device given",
+                "boot.device.custom": valid.BlockDevice()
                 }
 
     def ui_content(self):
@@ -77,16 +78,36 @@
             do_fake = True
         devices = utils.storage.Devices(fake=do_fake)
         all_devices = devices.get_all().items()
-        return sorted([(name, " %6s  %11s  %5s GB" % (d.bus, d.name, d.size))
-                       for name, d in all_devices], key=lambda t: t[0])
+        devices = sorted([(name, " %6s  %11s  %5s GB" % (d.bus, d.name,
+                                                         d.size))
+                          for name, d in all_devices], key=lambda t: t[0])
+        devices += [("other", "Other Device")]
+        return devices
 
     def on_change(self, changes):
         if changes.contains_any(["boot.device"]):
+            device = changes["boot.device"]
+            if device == "other":
+                self.widgets["label.details"].text("")
+            else:
+                self._model.update(changes)
+                self.widgets["label.details"].set_device(device)
+
+        if changes.contains_any(["boot.device.custom"]):
             self._model.update(changes)
-            self.widgets["label.details"].set_device(changes["boot.device"])
 
     def on_merge(self, effective_changes):
         changes = self.pending_changes(False)
+        if changes.contains_any(["boot.device"]):
+            device = changes["boot.device"]
+            if device == "other":
+                self._dialog = CustomDeviceDialog("custom", "x", "y")
+                return self._dialog
+
+        if changes.contains_any(["boot.device.custom"]):
+            self._dialog.close()
+            self.application.ui.navigate.to_next_plugin()
+
         if changes.contains_any(["button.next", "boot.device"]):
             self.application.ui.navigate.to_next_plugin()
         elif changes.contains_any(["button.back"]):
@@ -94,7 +115,11 @@
 
 
 class DeviceDetails(ui.Label):
+    """A simple widget to display the details for a given device
+    """
     def set_device(self, device_name):
+        """
+        """
         devices = utils.storage.Devices(fake=True)
         all_devices = devices.get_all()
         device = all_devices[device_name]
@@ -117,3 +142,18 @@
         if value:
             self.set_device(value)
         return value
+
+
+class CustomDeviceDialog(ui.Dialog):
+    """The dialog to input a custom root/boot device
+    """
+    def __init__(self, path, title, description):
+        title = "Custom Block Device"
+        description = "Please select the disk to use for booting PRODUCT_NAME"
+        device_entry = ui.Entry("boot.device.custom", "Device path:")
+        children = [ui.Label("label[0]", description),
+                    ui.Divider("divider[0]"),
+                    device_entry]
+        super(CustomDeviceDialog, self).__init__(path, title, children)
+        self.buttons = [ui.SaveButton("save_dialog"),
+                        ui.CloseButton("close_button", "Cancel")]
diff --git a/scripts/tui/src/ovirt/node/installer/installation_device_page.py b/scripts/tui/src/ovirt/node/installer/installation_device_page.py
index 3ea1355..e7c2dd6 100644
--- a/scripts/tui/src/ovirt/node/installer/installation_device_page.py
+++ b/scripts/tui/src/ovirt/node/installer/installation_device_page.py
@@ -41,7 +41,7 @@
         if devices:
             first_dev = devices[0][0]
             self._model["label.details"] = first_dev
-            #self._model["installation.device"] = first_dev
+            self._model["installation.device"] = first_dev
         return self._model
 
     def validators(self):
@@ -85,8 +85,8 @@
     def on_change(self, changes):
         if changes.contains_any(["installation.device"]):
             highlighted_device = changes["installation.device"]
-            all_selected_devices = self.widgets["installation.device"].selection()
-            self.logger.debug("devices: %s" % all_selected_devices)
+            selected_devices = self.widgets["installation.device"].selection()
+            self.logger.debug("devices: %s" % selected_devices)
             self._model.update(changes)
             w = self.widgets["label.details"]
             if highlighted_device:
diff --git a/scripts/tui/src/ovirt/node/setup/support_page.py b/scripts/tui/src/ovirt/node/setup/support_page.py
index 5794641..93d4639 100644
--- a/scripts/tui/src/ovirt/node/setup/support_page.py
+++ b/scripts/tui/src/ovirt/node/setup/support_page.py
@@ -51,7 +51,7 @@
 
               ui.Header("header[1]", "(Data:)"),
               ui.Label("support.contents", "")
-        ]
+              ]
 
         page = ui.Page("page", ws)
         page.buttons = []
@@ -84,4 +84,4 @@
     def __debugfiles_to_offer(self):
         return [("ui", "Node Debug Log"),
                 ("dmesg", "dmesg"),
-                ("messages", "/var/log/messages")]
\ No newline at end of file
+                ("messages", "/var/log/messages")]
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index 818bb71..a3a0a81 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -30,6 +30,10 @@
     """An abstract UI Element.
     This basically provides signals to communicate between real UI widget and
     the plugins
+
+    Args:
+        path: The model path this item is mapped to
+        on_value_change: Emitted by the value() method if the value changes
     """
     path = None
     on_value_change = None
@@ -59,11 +63,13 @@
 
 class InputElement(Element):
     """An abstract UI Element for user input
-    on_change:
-        To be called by the consumer when the associated widget changed
 
-    on_enabled_change:
-        Called by the Element when enabled changes
+    Args:
+        on_change: To be called by the consumer when the associated widget
+                   changed
+
+        on_enabled_change: Called by the Element when enabled changes°
+        on_valid_change: Called by the Element when validity changes°
     """
     on_change = None
 
@@ -89,7 +95,7 @@
 
     def valid(self, is_valid):
         if is_valid in [True, False]:
-            self.on_value_change(is_valid)
+            self.on_valid_change(is_valid)
             self._valid = is_valid
         return self._valid
 
@@ -624,20 +630,23 @@
 
 class Dialog(Page):
     """An abstract dialog, similar to a page
+
+    Args:
+        on_close: Emitted by the Dialog when it requests a close
     """
 
     escape_key = "esc"
-    on_close = None
+    on_close_change = None
 
     def __init__(self, path, title, children):
         super(Dialog, self).__init__(path, children, title)
-        self.on_close = self.new_signal()
+        self.on_close_change = self.new_signal()
         self.close(False)
-        self.on_close.connect(CloseAction(dialog=self))
+        self.on_close_change.connect(CloseAction(dialog=self))
 
     def close(self, v=True):
         if v:
-            self.on_close(self)
+            self.on_close_change(self)
 
 
 class TransactionProgressDialog(Dialog):
@@ -687,6 +696,9 @@
 
 class AbstractUIBuilder(base.Base):
     """An abstract class
+    Every toolkit that wants to be a backend for the above elements needs to
+    implement this builder. An instance of that specififc builder is then
+    passed to the application which uses the builder to build the UI.
     """
     application = None
 
diff --git a/scripts/tui/src/ovirt/node/ui/urwid_builder.py b/scripts/tui/src/ovirt/node/ui/urwid_builder.py
index bdf9476..5cfa89c 100644
--- a/scripts/tui/src/ovirt/node/ui/urwid_builder.py
+++ b/scripts/tui/src/ovirt/node/ui/urwid_builder.py
@@ -70,7 +70,7 @@
         def on_item_text_change_cb(w, v):
             self.logger.debug("Element changed, updating label " +
                               "'%s': %s" % (w, v))
-            widget.text(v)
+            widget.text(ui_label.text())
             self.application.ui.force_redraw()
         ui_label.on_value_change.connect(on_item_text_change_cb)
 
@@ -156,6 +156,7 @@
                               (widget, ui_entry.path))
 
             try:
+                # FIXME this logic needs to go somewhere else - more generic
                 change = {ui_entry.path: new_value}
                 ui_entry.on_change(change)
                 widget.notice = ""
@@ -248,6 +249,13 @@
 
         urwid.connect_signal(widget, "changed", on_change_cb)
 
+        def on_item_value_change_cb(p, v):
+            for c in children:
+                if c._key in v:
+                    c.selected(True)
+
+        ui_table.on_value_change.connect(on_item_value_change_cb)
+
         return widget
 
     def _build_tableitem(self, ui_table, key, label):
diff --git a/scripts/tui/src/ovirt/node/ui/widgets.py b/scripts/tui/src/ovirt/node/ui/widgets.py
index faee564..447c4cc 100644
--- a/scripts/tui/src/ovirt/node/ui/widgets.py
+++ b/scripts/tui/src/ovirt/node/ui/widgets.py
@@ -72,18 +72,20 @@
     def is_selected(self):
         return self._text.text.startswith(self.checkboxes[True])
 
+    def select(self, is_selected=True):
+        new_text = "%s%s" % (self.checkboxes[is_selected], self.title)
+        self._text.set_text(new_text)
+
     def __build_child(self):
-        title = "%s" % self.title
+        self._text = SelectableText(self.title)
         if self.multi:
-            title = "%s%s" % (self.checkboxes[False], self.title)
-        self._text = SelectableText(title)
+            self.select(False)
         return self._text
 
     def __handle_activate(self):
         if self.multi:
             is_checked = self.is_selected()
-            new_text = "%s%s" % (self.checkboxes[not is_checked], self.title)
-            self._text.set_text(new_text)
+            self.select(not is_checked)
         self._emit('activate', self)
 
 


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

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