[node-patches] Change in ovirt-node[master]: tui: Add ResetButton
fabiand at fedoraproject.org
fabiand at fedoraproject.org
Tue Dec 11 20:09:40 UTC 2012
Fabian Deutsch has uploaded a new change for review.
Change subject: tui: Add ResetButton
......................................................................
tui: Add ResetButton
Change-Id: I60b882bb243fedbe85456c11d88786a27d2265f1
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/plugins.py
M scripts/tui/src/ovirt/node/setup/example.py
M scripts/tui/src/ovirt/node/setup/features.py
M scripts/tui/src/ovirt/node/setup/network_page.py
M scripts/tui/src/ovirt/node/setup/ping.py
M scripts/tui/src/ovirt/node/setup/status_page.py
M scripts/tui/src/ovirt/node/setup/support_page.py
M scripts/tui/src/ovirt/node/setup/usage.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/tui.py
11 files changed, 99 insertions(+), 69 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/40/9940/1
diff --git a/scripts/tui/src/ovirt/node/plugins.py b/scripts/tui/src/ovirt/node/plugins.py
index 3d82a31..a1d01f2 100644
--- a/scripts/tui/src/ovirt/node/plugins.py
+++ b/scripts/tui/src/ovirt/node/plugins.py
@@ -192,7 +192,7 @@
except NotImplementedError:
self.logger.debug("Plugin has no model")
except ovirt.node.exceptions.InvalidData:
- self.logger.warning("Plugins model does not pass sematic " +
+ self.logger.warning("Plugins model does not pass semantic " +
"check: %s" % model)
is_valid = False
finally:
@@ -245,6 +245,15 @@
self.__changes = {}
return successfull_merge
+ def _on_ui_reset(self):
+ """Called when a ResetButton was clicked
+ Discards all changes
+ """
+ changes = self.pending_changes(False)
+ self.logger.debug("Request to discard model changes: %s" % changes)
+ self.__changes = {}
+
+
def pending_changes(self, only_effective_changes=True):
"""Return all changes which happened since the last on_merge call
diff --git a/scripts/tui/src/ovirt/node/setup/example.py b/scripts/tui/src/ovirt/node/setup/example.py
index 062eb93..1f777c8 100644
--- a/scripts/tui/src/ovirt/node/setup/example.py
+++ b/scripts/tui/src/ovirt/node/setup/example.py
@@ -134,7 +134,7 @@
("dialog.button", ovirt.node.ui.Button("Close"))
]
page = ovirt.node.ui.Dialog("Information", widgets)
- page.has_save_button = False
+ page.buttons = []
self._widgets.update(dict(widgets))
self._widgets["dialog.dialog"] = page
diff --git a/scripts/tui/src/ovirt/node/setup/features.py b/scripts/tui/src/ovirt/node/setup/features.py
index 61ef6fb..f56d39f 100644
--- a/scripts/tui/src/ovirt/node/setup/features.py
+++ b/scripts/tui/src/ovirt/node/setup/features.py
@@ -49,7 +49,7 @@
]
page = ovirt.node.ui.Page(widgets)
- page.has_save_button = False
+ page.buttons = []
return page
def model(self):
diff --git a/scripts/tui/src/ovirt/node/setup/network_page.py b/scripts/tui/src/ovirt/node/setup/network_page.py
index 3be2acc..3e44f89 100644
--- a/scripts/tui/src/ovirt/node/setup/network_page.py
+++ b/scripts/tui/src/ovirt/node/setup/network_page.py
@@ -219,7 +219,7 @@
]))
])
- dialog.has_save_button = False
+ dialog.buttons = []
self._nic_details_group.enabled(False)
diff --git a/scripts/tui/src/ovirt/node/setup/ping.py b/scripts/tui/src/ovirt/node/setup/ping.py
index 6c6437f..5c7246e 100644
--- a/scripts/tui/src/ovirt/node/setup/ping.py
+++ b/scripts/tui/src/ovirt/node/setup/ping.py
@@ -81,7 +81,7 @@
self._widgets = dict(widgets)
page = ovirt.node.ui.Page(widgets)
- page.has_save_button = False
+ page.buttons = []
return page
def on_change(self, changes):
diff --git a/scripts/tui/src/ovirt/node/setup/status_page.py b/scripts/tui/src/ovirt/node/setup/status_page.py
index 03847f2..fde8245 100644
--- a/scripts/tui/src/ovirt/node/setup/status_page.py
+++ b/scripts/tui/src/ovirt/node/setup/status_page.py
@@ -113,7 +113,7 @@
self._widgets = dict(widgets)
page = ovirt.node.ui.Page(widgets)
- page.has_save_button = False
+ page.buttons = []
return page
def on_change(self, changes):
diff --git a/scripts/tui/src/ovirt/node/setup/support_page.py b/scripts/tui/src/ovirt/node/setup/support_page.py
index 5d829c9..bd118d1 100644
--- a/scripts/tui/src/ovirt/node/setup/support_page.py
+++ b/scripts/tui/src/ovirt/node/setup/support_page.py
@@ -30,8 +30,8 @@
class Plugin(ovirt.node.plugins.NodePlugin):
def __init__(self, application):
# Register F8: Display this plugin when F( is pressed
- display_page = lambda: application.ui.display_page(self.ui_content())
- application.ui.register_hotkey(["f8"], display_page)
+ show_page = lambda: application.ui.show_page(self.ui_content())
+ application.ui.register_hotkey(["f8"], show_page)
def name(self):
return "Support"
@@ -46,7 +46,7 @@
]
page = ovirt.node.ui.Page(widgets)
- page.has_save_button = False
+ page.buttons = []
return page
def model(self):
diff --git a/scripts/tui/src/ovirt/node/setup/usage.py b/scripts/tui/src/ovirt/node/setup/usage.py
index b854123..832910d 100644
--- a/scripts/tui/src/ovirt/node/setup/usage.py
+++ b/scripts/tui/src/ovirt/node/setup/usage.py
@@ -51,7 +51,7 @@
]
page = ovirt.node.ui.Page(widgets)
- page.has_save_button = False
+ page.buttons = []
return page
def model(self):
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index cc4191a..cd84465 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -133,7 +133,14 @@
class Page(ContainerElement):
"""An abstract page with a couple of widgets
"""
- has_save_button = True
+ buttons = []
+
+ def __init__(self, children):
+ super(Page, self).__init__(children)
+ self.buttons = [
+ (None, SaveButton()),
+ (None, ResetButton())
+ ]
class Dialog(Page):
@@ -223,6 +230,11 @@
super(SaveButton, self).__init__("Save", enabled)
+class ResetButton(Button):
+ def __init__(self, enabled=True):
+ super(ResetButton, self).__init__("Reset", enabled)
+
+
class Divider(Element):
def __init__(self, char=u" "):
super(Divider, self).__init__()
diff --git a/scripts/tui/src/ovirt/node/ui/builder.py b/scripts/tui/src/ovirt/node/ui/builder.py
index 471657e..26ead9e 100644
--- a/scripts/tui/src/ovirt/node/ui/builder.py
+++ b/scripts/tui/src/ovirt/node/ui/builder.py
@@ -28,8 +28,8 @@
import logging
-import ovirt.node.ui.widgets
import ovirt.node.exceptions
+from ovirt.node import ui
LOGGER = logging.getLogger(__name__)
@@ -39,7 +39,7 @@
widget = None
# FIXME could also be done using dict.
- if type(element) is ovirt.node.ui.Page:
+ if type(element) is ui.Page:
widget = build_page(tui, plugin, element)
else:
raise Exception("Unknown element container: %s" % element)
@@ -50,18 +50,18 @@
def build_page(tui, plugin, container):
widgets = []
- # Always create the SaveButton, but only display it if requested
- #save = ovirt.node.ui.widgets.Button("Save")
- #urwid.connect_signal(save, 'click', lambda x: plugin._on_ui_save())
- save = build_button("_save", ovirt.node.ui.SaveButton(), tui, plugin)
- plugin._save_button = save
-
for path, item in container.children:
widget = widget_for_item(tui, plugin, path, item)
widgets.append(("flow", widget))
- if container.has_save_button:
- widgets.append(urwid.Filler(save))
+ # Add buttons
+ button_widgets = []
+ for path, item in container.buttons:
+ assert type(item) in [ui.SaveButton, ui.ResetButton, ui.Button]
+ button_widgets.append(build_button(path, item, tui, plugin))
+
+ if button_widgets:
+ widgets.append(urwid.Filler(urwid.Columns(button_widgets)))
widgets.append(urwid.Filler(urwid.Text("")))
@@ -71,7 +71,7 @@
except:
tui.notify("error", "Initial model validation failed.")
- page = ovirt.node.ui.widgets.PageWidget(widgets)
+ page = ui.widgets.PageWidget(widgets)
page.plugin = plugin
return page
@@ -79,19 +79,25 @@
def widget_for_item(tui, plugin, path, item):
item_to_builder = {
- ovirt.node.ui.Label: build_label,
- ovirt.node.ui.Header: build_label,
- ovirt.node.ui.KeywordLabel: build_label,
- ovirt.node.ui.Entry: build_entry,
- ovirt.node.ui.PasswordEntry: build_entry,
- ovirt.node.ui.Button: build_button,
- ovirt.node.ui.SaveButton: build_button,
- ovirt.node.ui.Divider: build_divider,
- ovirt.node.ui.Options: build_options,
- ovirt.node.ui.Row: build_row,
- ovirt.node.ui.ProgressBar: build_progressbar,
- ovirt.node.ui.Table: build_table,
- ovirt.node.ui.Checkbox: build_checkbox,
+ ui.Header: build_label,
+
+ ui.Label: build_label,
+ ui.KeywordLabel: build_label,
+
+ ui.Entry: build_entry,
+ ui.PasswordEntry: build_entry,
+
+ ui.Button: build_button,
+ ui.SaveButton: build_button,
+ ui.ResetButton: build_button,
+
+ ui.Options: build_options,
+ ui.ProgressBar: build_progressbar,
+ ui.Table: build_table,
+ ui.Checkbox: build_checkbox,
+
+ ui.Divider: build_divider,
+ ui.Row: build_row,
}
# Check if builder is available for UI Element
@@ -103,12 +109,12 @@
widget = build_func(path, item, tui, plugin)
# Populate with values
- if type(item) in [ovirt.node.ui.Entry,
- ovirt.node.ui.PasswordEntry,
- ovirt.node.ui.Label,
- ovirt.node.ui.KeywordLabel,
- ovirt.node.ui.Options,
- ovirt.node.ui.Checkbox]:
+ if type(item) in [ui.Entry,
+ ui.PasswordEntry,
+ ui.Label,
+ ui.KeywordLabel,
+ ui.Options,
+ ui.Checkbox]:
model = plugin.model()
if path in model:
text = model[path]
@@ -119,10 +125,10 @@
def build_entry(path, item, tui, plugin):
widget_class = None
- if type(item) is ovirt.node.ui.Entry:
- widget_class = ovirt.node.ui.widgets.Entry
+ if type(item) is ui.Entry:
+ widget_class = ui.widgets.Entry
else:
- widget_class = ovirt.node.ui.widgets.PasswordEntry
+ widget_class = ui.widgets.PasswordEntry
widget = widget_class(item.label, align_vertical=item.align_vertical)
widget.enable(item.enabled())
@@ -145,7 +151,6 @@
plugin._on_ui_change(change)
widget.notice = ""
widget.valid(True)
- plugin._save_button.enable(True)
except ovirt.node.exceptions.Concern as e:
LOGGER.error("Concern when updating: %s" % e)
@@ -155,10 +160,6 @@
if widget._selectable:
widget.notice = e.message
widget.valid(False)
- plugin._save_button.enable(False)
-
- # FIXME page validation must happen within tui, not plugin
- # as UI data should be handled in tui
tui._draw_screen()
urwid.connect_signal(widget, 'change', on_widget_value_change)
@@ -167,13 +168,13 @@
def build_label(path, item, tui, plugin):
- if type(item) is ovirt.node.ui.KeywordLabel:
- widget = ovirt.node.ui.widgets.KeywordLabel(item.keyword,
+ if type(item) is ui.KeywordLabel:
+ widget = ui.widgets.KeywordLabel(item.keyword,
item.text())
- elif type(item) is ovirt.node.ui.Header:
- widget = ovirt.node.ui.widgets.Header(item.text())
+ elif type(item) is ui.Header:
+ widget = ui.widgets.Header(item.text())
else:
- widget = ovirt.node.ui.widgets.Label(item.text())
+ widget = ui.widgets.Label(item.text())
def on_item_text_change_cb(w, v):
LOGGER.debug("Element changed, updating label '%s': %s" % (w, v))
@@ -187,13 +188,18 @@
def build_button(path, item, tui, plugin):
- widget = ovirt.node.ui.widgets.Button(item.text())
+ widget = ui.widgets.Button(item.text())
def on_widget_click_cb(widget, data=None):
LOGGER.debug("Button click: %s %s" % (path, widget))
- if type(item) is ovirt.node.ui.Button:
+ itemtype = type(item)
+ if itemtype is ui.Button:
plugin._on_ui_change({path: True})
- r = plugin._on_ui_save()
+ if itemtype in [ui.Button, ui.SaveButton]:
+ r = plugin._on_ui_save()
+ if itemtype in [ui.ResetButton]:
+ r = plugin._on_ui_reset()
+ tui._display_plugin(plugin)
parse_plugin_result(tui, plugin, r)
# else:
@@ -206,11 +212,11 @@
def build_divider(path, item, tui, plugin):
- return ovirt.node.ui.widgets.Divider(item.char)
+ return ui.widgets.Divider(item.char)
def build_options(path, item, tui, plugin):
- widget = ovirt.node.ui.widgets.Options(item.label, item.options,
+ widget = ui.widgets.Options(item.label, item.options,
plugin.model()[path])
def on_widget_change_cb(widget, data):
@@ -223,7 +229,7 @@
def build_checkbox(path, item, tui, plugin):
- widget = ovirt.node.ui.widgets.Checkbox(item.label, item.state())
+ widget = ui.widgets.Checkbox(item.label, item.state())
return widget
@@ -237,7 +243,7 @@
def build_progressbar(path, item, tui, plugin):
- widget = ovirt.node.ui.widgets.ProgressBarWidget(item.current(), item.done)
+ widget = ui.widgets.ProgressBarWidget(item.current(), item.done)
def on_item_current_change_cb(w, v):
LOGGER.debug("Model changed, updating progressbar '%s': %s" % (w, v))
@@ -253,7 +259,7 @@
for key, label in item.items:
c = _build_tableitem(tui, path, plugin, key, label)
children.append(c)
- widget = ovirt.node.ui.widgets.TableWidget(item.label, item.header,
+ widget = ui.widgets.TableWidget(item.label, item.header,
children,
item.height, item.enabled())
@@ -266,7 +272,7 @@
def _build_tableitem(tui, path, plugin, key, label):
- c = ovirt.node.ui.widgets.TableEntryWidget(label)
+ c = ui.widgets.TableEntryWidget(label)
c._key = key
def on_activate_cb(w, data):
@@ -279,11 +285,11 @@
def parse_plugin_result(tui, plugin, result):
LOGGER.debug("Parsing plugin change/save result: %s" % result)
- if type(result) in [ovirt.node.ui.Page]:
+ if type(result) in [ui.Page]:
LOGGER.debug("Page requested.")
tui.show_page(result)
- elif type(result) in [ovirt.node.ui.Dialog]:
+ elif type(result) in [ui.Dialog]:
LOGGER.debug("Dialog requested.")
dialog = tui.show_dialog(result)
diff --git a/scripts/tui/src/ovirt/node/ui/tui.py b/scripts/tui/src/ovirt/node/ui/tui.py
index b6a2a8d..c7e2287 100644
--- a/scripts/tui/src/ovirt/node/ui/tui.py
+++ b/scripts/tui/src/ovirt/node/ui/tui.py
@@ -26,6 +26,7 @@
import timeit
import urwid
+from ovirt.node import base
from ovirt.node import ui
import ovirt.node.ui.builder
import ovirt.node.ui.widgets
@@ -95,6 +96,7 @@
def __init__(self, app):
super(UrwidTUI, self).__init__(app)
self.logger.info("Creating urwid tui for '%s'" % app)
+ self.logger.debug("Detected encoding: %s" % urwid.get_encoding_mode())
def show_body(self, body):
"""
@@ -142,7 +144,7 @@
self.__menu = ovirt.node.ui.widgets.PluginMenu(self._plugins)
def menu_item_changed(plugin):
- self.__display_plugin(plugin)
+ self._display_plugin(plugin)
urwid.connect_signal(self.__menu, 'changed', menu_item_changed)
def __create_screen(self):
@@ -195,7 +197,7 @@
filler = urwid.Pile([page])
self.__page_frame.body = filler
- def __display_plugin(self, plugin):
+ def _display_plugin(self, plugin):
if self._check_outstanding_changes():
return
timer = timeit.Timer()
@@ -277,7 +279,7 @@
self.logger.warning(msg)
if not hasattr(self, "_error_dialog") or not self._error_dialog:
d = ui.Dialog("Error", [("dialog.error", ui.Label(msg))])
- d.has_save_button = False
+ d.buttons = []
self._error_dialog = self.show_dialog(d)
else:
if hasattr(self, "_error_dialog") and self._error_dialog:
@@ -296,8 +298,9 @@
def suspended(self):
"""Supspends the screen to do something in the foreground
"""
- class SuspendedScreen(object):
+ class SuspendedScreen(base.Base):
def __init__(self, loop):
+ super(SuspendedScreen, self).__init__()
self.__loop = loop
def __enter__(self):
--
To view, visit http://gerrit.ovirt.org/9940
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I60b882bb243fedbe85456c11d88786a27d2265f1
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