[node-patches] Change in ovirt-node[master]: ui: Add function to catch InvalidData exceptions

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Feb 12 19:29:03 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: ui: Add function to catch InvalidData exceptions
......................................................................

ui: Add function to catch InvalidData exceptions

A method is added to easily catch InvaliDataexceptions (which are well
understood) and display a notice on the UI to tell the user about it.

Change-Id: I61be3627dcdf1cba957811fc39485410e3bc94f5
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/app.py
1 file changed, 23 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/90/11990/1

diff --git a/scripts/tui/src/ovirt/node/app.py b/scripts/tui/src/ovirt/node/app.py
index 9966994..1ccf439 100644
--- a/scripts/tui/src/ovirt/node/app.py
+++ b/scripts/tui/src/ovirt/node/app.py
@@ -18,7 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
-from ovirt.node import base, utils, plugins, ui
+from ovirt.node import base, utils, plugins, ui, exceptions
 from ovirt.node.config import defaults
 from ovirt.node.ui import urwid_builder
 from ovirt.node.utils import system, Timer
@@ -202,15 +202,19 @@
 
         # All known handlers
         handlers = {ui.SaveAction:
-                    lambda d: self.current_plugin()._on_ui_save(),
+                    lambda d: self._catch_invalid_data(
+                        lambda: self.current_plugin()._on_ui_save()),
+                    ui.ChangeAction:
+                    lambda d: self._catch_invalid_data(
+                        lambda: self.current_plugin()._on_ui_change(d)),
+                    ui.ReloadAction:
+                    lambda d: self._catch_invalid_data(
+                        lambda: self.switch_to_plugin(self.current_plugin(),
+                                                      False)),
+
                     ui.CloseAction: cond_close_dialog,
                     ui.ResetAction:
                     lambda d: self.current_plugin()._on_ui_reset(),
-                    ui.ChangeAction:
-                    lambda d: self.current_plugin()._on_ui_change(d),
-                    ui.ReloadAction:
-                    lambda d: self.switch_to_plugin(self.current_plugin(),
-                                                    False),
                     ui.QuitAction:
                     lambda d: self.quit()
                     }
@@ -308,11 +312,20 @@
         self.logger.info("Quitting")
         self.ui.quit()
 
-    def notice(self, msg):
+    def notice(self, msg, title="Notice"):
+        """Raise a notice on the screen
+        Is currently a dialog, but this can change
+        """
         children = [ui.Label("app.notice.text", msg)]
-        dialog = ui.Dialog("app.notice", "Notice", children)
+        dialog = ui.Dialog("app.notice", title, children)
         dialog.buttons = [ui.CloseButton("app.notice.close")]
-        #self.ui._notice(dialog)
+        self.show(dialog)
+
+    def _catch_invalid_data(self, cb):
+        try:
+            cb()
+        except exceptions.InvalidData as e:
+            self.notice("%s" % e.message, "An exception occurred")
 
     def _check_outstanding_changes(self):
         has_outstanding_changes = False


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

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