[PATCH] Add set_info, set_error, set_warning functions to the BaseWindow object.

Chris Lumens clumens at redhat.com
Wed Nov 28 20:49:40 UTC 2012


This saves us from having to type the same GTK constants again and again in
python land.
---
 pyanaconda/ui/gui/__init__.py              | 31 +++++++++++++-
 pyanaconda/ui/gui/hubs/__init__.py         |  7 +--
 pyanaconda/ui/gui/spokes/custom.py         | 68 ++++++++++++------------------
 pyanaconda/ui/gui/spokes/datetime_spoke.py | 14 +++---
 pyanaconda/ui/gui/spokes/password.py       |  8 ++--
 pyanaconda/ui/gui/spokes/software.py       |  4 +-
 pyanaconda/ui/gui/spokes/source.py         |  8 ++--
 pyanaconda/ui/gui/spokes/storage.py        | 12 +++---
 widgets/src/BaseWindow.c                   | 60 ++++++++++++++++++++------
 widgets/src/BaseWindow.h                   |  4 +-
 10 files changed, 128 insertions(+), 88 deletions(-)

diff --git a/pyanaconda/ui/gui/__init__.py b/pyanaconda/ui/gui/__init__.py
index 11d39b3..52336f8 100644
--- a/pyanaconda/ui/gui/__init__.py
+++ b/pyanaconda/ui/gui/__init__.py
@@ -337,8 +337,6 @@ class GUIObject(common.UIObject):
         raise IOError("Could not load UI file '%s' for object '%s'" % (self.uiFile, self))
 
     def _handlePrntScreen(self, window, event):
-        from gi.repository import Gdk
-
         global _screenshotIndex
 
         if event.keyval != Gdk.KEY_Print:
@@ -405,6 +403,35 @@ class GUIObject(common.UIObject):
 
         return self._window
 
+    def clear_info(self):
+        """Clear any info bar from the bottom of the screen."""
+        self.window.clear_info()
+
+    def set_error(self, msg):
+        """Display an info bar along the bottom of the screen with the provided
+           message.  This method is used to display critical errors anaconda
+           may not be able to do anything about, but that the user may.  A
+           suitable background color and icon will be displayed.
+        """
+        self.window.set_info(msg)
+
+    def set_info(self, msg):
+        """Display an info bar along the bottom of the screen with the provided
+           message.  This method is used to display informational text -
+           non-critical warnings during partitioning, for instance.  The user
+           should investigate these messages but doesn't have to.  A suitable
+           background color and icon will be displayed.
+        """
+        self.window.set_info(msg)
+
+    def set_warning(self, msg):
+        """Display an info bar along the bottom of the screen with the provided
+           message.  This method is used to display errors the user needs to
+           attend to in order to continue installation.  This is the bulk of
+           messages.  A suitable background color and icon will be displayed.
+        """
+        self.window.set_info(msg)
+
 class QuitDialog(GUIObject):
     builderObjects = ["quitDialog"]
     mainWidgetName = "quitDialog"
diff --git a/pyanaconda/ui/gui/hubs/__init__.py b/pyanaconda/ui/gui/hubs/__init__.py
index 5718aab..f702fa6 100644
--- a/pyanaconda/ui/gui/hubs/__init__.py
+++ b/pyanaconda/ui/gui/hubs/__init__.py
@@ -205,9 +205,6 @@ class Hub(GUIObject, common.Hub):
         self._handleCompleteness(spoke)
 
     def _handleCompleteness(self, spoke):
-        # pylint: disable-msg=E0611
-        from gi.repository import Gtk
-
         # Add the spoke to the incomplete list if it's now incomplete, and make
         # sure it's not on the list if it's now complete.  Then show the box if
         # it's needed and hide it if it's not.
@@ -221,14 +218,14 @@ class Hub(GUIObject, common.Hub):
         self._updateContinueButton()
 
         if len(self._incompleteSpokes) == 0:
-            self.window.clear_info()
+            self.clear_info()
         else:
             if flags.automatedInstall:
                 msg = _("When all items marked with this icon are complete, installation will automatically continue.")
             else:
                 msg = _("Please complete items marked with this icon before continuing to the next step.")
 
-            self.window.set_info(Gtk.MessageType.WARNING, msg)
+            self.set_warning(msg)
 
     @property
     def continuePossible(self):
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index f6f88bf..eeacf8e 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -851,7 +851,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             error = validate_mountpoint(mountpoint, self.__storage.mountpoints.keys())
             if error:
                 self._error = _(mountpoint_validation_msgs[error])
-                self.window.set_info(Gtk.MessageType.WARNING, self._error)
+                self.set_warning(self._error)
                 self.window.show_all()
                 self._populate_right_side(selector)
                 return
@@ -888,7 +888,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                           "disks than you currently have selected.")
 
         if error:
-            self.window.set_info(Gtk.MessageType.WARNING, error)
+            self.set_warning(error)
             self.window.show_all()
             self._populate_right_side(selector)
             return
@@ -958,15 +958,13 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                                          selector=selector)
                 except ErrorRecoveryFailure as e:
                     self._error = e
-                    self.window.set_info(Gtk.MessageType.WARNING,
-                                         _(unrecoverable_error_msg))
+                    self.set_warning(_(unrecoverable_error_msg))
                     self.window.show_all()
                     self._reset_storage()
                 except StorageError as e:
                     log.error("newDevice failed: %s" % e)
                     self._error = e
-                    self.window.set_info(Gtk.MessageType.WARNING,
-                                         _(device_configuration_error_msg)) 
+                    self.set_warning(_(device_configuration_error_msg)) 
                     self.window.show_all()
 
                     # in this case we have removed the old device so we now have
@@ -984,8 +982,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                         # failed to recover.
                         self.clear_errors()
                         self._error = e
-                        self.window.set_info(Gtk.MessageType.WARNING,
-                                             _(unrecoverable_error_msg))
+                        self.set_warning(_(unrecoverable_error_msg))
                         self.window.show_all()
                         self._reset_storage()
                 else:
@@ -1023,9 +1020,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                         log.error("failed to schedule device resize: %s" % e)
                         device.size = old_size
                         self._error = e
-                        self.window.set_info(Gtk.MessageType.WARNING,
-                                             _("Device resize request failed. "
-                                               "Click for details."))
+                        self.set_warning(_("Device resize request failed. "
+                                           "Click for details."))
                         self.window.show_all()
                     else:
                         log.debug("%r" % device)
@@ -1046,15 +1042,13 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                                                  raid_level=raid_level)
                     except ErrorRecoveryFailure as e:
                         self._error = e
-                        self.window.set_info(Gtk.MessageType.WARNING,
-                                             _(unrecoverable_error_msg))
+                        self.set_warning(_(unrecoverable_error_msg))
                         self.window.show_all()
                         self._reset_storage()
                     except StorageError as e:
                         log.error("newDevice failed: %s" % e)
                         self._error = e
-                        self.window.set_info(Gtk.MessageType.WARNING,
-                                             _(device_configuration_error_msg))
+                        self.set_warning(_(device_configuration_error_msg))
                         self.window.show_all()
 
                     self._devices = self.__storage.devices
@@ -1132,9 +1126,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                         log.error("failed to register device format action: %s" % e)
                         device.format = old_format
                         self._error = e
-                        self.window.set_info(Gtk.MessageType.WARNING,
-                                             _("Device reformat request failed. "
-                                               "Click for details."))
+                        self.set_warning(_("Device reformat request failed. "
+                                           "Click for details."))
                         self.window.show_all()
                     else:
                         # first, remove this selector from any old install page(s)
@@ -1621,23 +1614,20 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             except ErrorRecoveryFailure as e:
                 log.error("error recovery failure")
                 self._error = e
-                self.window.set_info(Gtk.MessageType.ERROR,
-                                     _(unrecoverable_error_msg))
+                self.set_error(_(unrecoverable_error_msg))
                 self.window.show_all()
                 self._reset_storage()
             except StorageError as e:
                 log.error("newDevice failed: %s" % e)
                 self._error = e
-                self.window.set_info(Gtk.MessageType.ERROR,
-                                     _("Failed to add new device. Click for "
-                                       "details."))
+                self.set_error(_("Failed to add new device. Click for "
+                                 "details."))
                 self.window.show_all()
             except OverflowError as e:
                 log.error("invalid size set for partition")
                 self._error = e
-                self.window.set_info(Gtk.MessageType.ERROR,
-                                     _("Invalid partition size set. Use a "
-                                        "valid integer."))
+                self.set_error(_("Invalid partition size set. Use a "
+                                 "valid integer."))
                 self.window.show_all()
 
         self._devices = self.__storage.devices
@@ -1656,9 +1646,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             except StorageError as e:
                 log.error("failed to schedule device removal: %s" % e)
                 self._error = e
-                self.window.set_info(Gtk.MessageType.WARNING,
-                                     _("Device removal request failed. Click "
-                                       "for details."))
+                self.set_warning(_("Device removal request failed. Click "
+                                   "for details."))
                 self.window.show_all()
             else:
                 if is_logical_partition:
@@ -1807,8 +1796,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                                             [d.name for d in disks]))
         if not disks:
             self._error = "No disks selected. Keeping previous disk set."
-            self.window.set_info(Gtk.MessageType.INFO,
-                                 self._error)
+            self.set_info(self._error)
             self.window.show_all()
             return
 
@@ -1905,23 +1893,20 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                 # No handling should be required for this.
                 log.error("doAutoPartition failed: %s" % e)
                 self._error = e
-                self.window.set_info(Gtk.MessageType.ERROR,
-                                     _("No disks selected."))
+                self.set_error(_("No disks selected."))
                 self.window.show_all()
             except NotEnoughFreeSpaceError as e:
                 # No handling should be required for this.
                 log.error("doAutoPartition failed: %s" % e)
                 self._error = e
-                self.window.set_info(Gtk.MessageType.ERROR,
-                                     _("Not enough free space on selected disks."))
+                self.set_error(_("Not enough free space on selected disks."))
                 self.window.show_all()
             except StorageError as e:
                 log.error("doAutoPartition failed: %s" % e)
                 self._reset_storage()
                 self._error = e
-                self.window.set_info(Gtk.MessageType.ERROR,
-                                     _("Automatic partitioning failed. Click "
-                                       "for details."))
+                self.set_error(_("Automatic partitioning failed. Click "
+                                 "for details."))
                 self.window.show_all()
             else:
                 self._devices = self.__storage.devices
@@ -2050,7 +2035,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
 
     def clear_errors(self):
         self._error = None
-        self.window.clear_info()
+        self.clear_info()
 
     def on_info_bar_clicked(self, *args):
         log.debug("info bar clicked: %s (%s)" % (self._error, args))
@@ -2088,9 +2073,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             self._error = e
             device.format.passphrase = None
             entry.set_text("")
-            self.window.set_info(Gtk.MessageType.WARNING,
-                                 _("Failed to unlock encrypted block device. "
-                                   "Click for details"))
+            self.set_warning(_("Failed to unlock encrypted block device. "
+                               "Click for details"))
             self.window.show_all()
             return
 
diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py
index cfc23f5..a30b39d 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.py
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py
@@ -420,7 +420,7 @@ class DatetimeSpoke(NormalSpoke):
         if not has_active_network:
             self._show_no_network_warning()
         else:
-            self.window.clear_info()
+            self.clear_info()
             gtk_call_once(self._config_dialog.refresh_servers_state)
 
         if flags.can_touch_runtime_system("get NTP service state"):
@@ -789,13 +789,11 @@ class DatetimeSpoke(NormalSpoke):
         footer_alignment.set_sensitive(sensitive)
 
     def _show_no_network_warning(self):
-        self.window.set_info(Gtk.MessageType.WARNING,
-                             _("You need to set up networking first if you "\
-                               "want to use NTP"))
+        self.set_warning(_("You need to set up networking first if you "\
+                           "want to use NTP"))
 
     def _show_no_ntp_server_warning(self):
-        self.window.set_info(Gtk.MessageType.WARNING,
-                             _("You have no working NTP server configured"))
+        self.set_warning(_("You have no working NTP server configured"))
 
     def on_ntp_switched(self, switch, *args):
         if switch.get_active():
@@ -809,7 +807,7 @@ class DatetimeSpoke(NormalSpoke):
                 switch.set_active(False)
                 return
             else:
-                self.window.clear_info()
+                self.clear_info()
 
                 working_server = self._config_dialog.working_server
                 if working_server is None:
@@ -853,5 +851,5 @@ class DatetimeSpoke(NormalSpoke):
             if self._config_dialog.working_server is None:
                 self._show_no_ntp_server_warning()
             else:
-                self.window.clear_info()
+                self.clear_info()
 
diff --git a/pyanaconda/ui/gui/spokes/password.py b/pyanaconda/ui/gui/spokes/password.py
index 6ffb2f6..ac113af 100644
--- a/pyanaconda/ui/gui/spokes/password.py
+++ b/pyanaconda/ui/gui/spokes/password.py
@@ -120,16 +120,16 @@ class PasswordSpoke(NormalSpoke):
 
         # if no errors, clear the info for next time we go into the spoke
         self._password = pw
-        self.window.clear_info()
+        self.clear_info()
         self._error = False
         return True
 
     def on_back_clicked(self, button):
         if self._validatePassword():
-            self.window.clear_info()
+            self.clear_info()
             NormalSpoke.on_back_clicked(self, button)
         else:
-            self.window.clear_info()
-            self.window.set_info(Gtk.MessageType.WARNING, self._error)
+            self.clear_info()
+            self.set_warning(self._error)
             self.pw.grab_focus()
             self.window.show_all()
diff --git a/pyanaconda/ui/gui/spokes/software.py b/pyanaconda/ui/gui/spokes/software.py
index f861ec2..8fd4c59 100644
--- a/pyanaconda/ui/gui/spokes/software.py
+++ b/pyanaconda/ui/gui/spokes/software.py
@@ -260,9 +260,9 @@ class SoftwareSelectionSpoke(NormalSpoke):
         self._selectFlag = True
 
         if self._errorMsgs:
-            self.window.set_info(Gtk.MessageType.WARNING, _("Error checking software dependencies.  Click for details."))
+            self.set_warning(_("Error checking software dependencies.  Click for details."))
         else:
-            self.window.clear_info()
+            self.clear_info()
 
     def _get_selected_addons(self):
         return [row[2] for row in self._addonStore if row[0]]
diff --git a/pyanaconda/ui/gui/spokes/source.py b/pyanaconda/ui/gui/spokes/source.py
index 0bf99b4..33518b5 100644
--- a/pyanaconda/ui/gui/spokes/source.py
+++ b/pyanaconda/ui/gui/spokes/source.py
@@ -524,7 +524,7 @@ class SourceSpoke(NormalSpoke):
 
         threadMgr.add(AnacondaThread(name="AnaPayloadMDThread",
                                      target=self.getRepoMetadata))
-        self.window.clear_info()
+        self.clear_info()
 
     def getRepoMetadata(self):
         communication.send_not_ready("SoftwareSelectionSpoke")
@@ -545,9 +545,9 @@ class SourceSpoke(NormalSpoke):
             communication.send_message(self.__class__.__name__,
                                        _("Failed to set up install source"))
             if not self.data.method.proxy:
-                gtk_call_once(self.window.set_info, Gtk.MessageType.WARNING, _("Failed to set up install source, check the repo url"))
+                gtk_call_once(self.set_warning, _("Failed to set up install source, check the repo url"))
             else:
-                gtk_call_once(self.window.set_info, Gtk.MessageType.WARNING, _("Failed to set up install source, check the repo url and proxy settings"))
+                gtk_call_once(self.set_warning, _("Failed to set up install source, check the repo url and proxy settings"))
         else:
             self._error = False
             communication.send_message(self.__class__.__name__,
@@ -559,7 +559,7 @@ class SourceSpoke(NormalSpoke):
                                            _(METADATA_ERROR_MESSAGE))
                 communication.send_ready(self.__class__.__name__)
                 self._error = True
-                gtk_call_once(self.window.set_info, Gtk.MessageType.WARNING, _("Failed to set up install source, check the repo url"))
+                gtk_call_once(self.set_warning, _("Failed to set up install source, check the repo url"))
             else:
                 communication.send_ready("SoftwareSelectionSpoke")
         finally:
diff --git a/pyanaconda/ui/gui/spokes/storage.py b/pyanaconda/ui/gui/spokes/storage.py
index 8969fbf..e5bb10b 100644
--- a/pyanaconda/ui/gui/spokes/storage.py
+++ b/pyanaconda/ui/gui/spokes/storage.py
@@ -493,7 +493,7 @@ class StorageSpoke(NormalSpoke, StorageChecker):
         self._update_summary()
 
         if self.errors:
-            self.window.set_info(Gtk.MessageType.WARNING, _("Error checking storage configuration.  Click for details."))
+            self.set_warning(_("Error checking storage configuration.  Click for details."))
 
     def initialize(self):
         from pyanaconda.ui.gui.utils import setViewportBackground
@@ -579,11 +579,11 @@ class StorageSpoke(NormalSpoke, StorageChecker):
         summary_label.set_text(summary)
 
         if len(self.disks) == 0:
-            self.window.set_info(Gtk.MessageType.WARNING, _("No disks detected.  Please shut down the computer, connect at least one disk, and restart to complete installation."))
+            self.set_warning(_("No disks detected.  Please shut down the computer, connect at least one disk, and restart to complete installation."))
         elif count == 0:
-            self.window.set_info(Gtk.MessageType.WARNING, _("No disks selected; please select at least one disk to install to."))
+            self.set_warning(_("No disks selected; please select at least one disk to install to."))
         else:
-            self.window.clear_info()
+            self.clear_info()
 
         self.builder.get_object("continue_button").set_sensitive(count > 0)
         self.builder.get_object("summary_label").set_sensitive(count > 0)
@@ -624,10 +624,10 @@ class StorageSpoke(NormalSpoke, StorageChecker):
         self._update_summary()
 
         if self.data.bootloader.location == "none":
-            self.window.set_info(Gtk.MessageType.WARNING, _("You have chosen to skip bootloader installation.  Your system may not be bootable."))
+            self.set_warning(_("You have chosen to skip bootloader installation.  Your system may not be bootable."))
             self.window.show_all()
         else:
-            self.window.clear_info()
+            self.clear_info()
 
     def run_lightbox_dialog(self, dialog):
         with enlightbox(self.window, dialog.window):
diff --git a/widgets/src/BaseWindow.c b/widgets/src/BaseWindow.c
index 5ad7635..8b3fcc3 100644
--- a/widgets/src/BaseWindow.c
+++ b/widgets/src/BaseWindow.c
@@ -400,20 +400,7 @@ GtkWidget *anaconda_base_window_get_alignment(AnacondaBaseWindow *win) {
     return win->priv->alignment;
 }
 
-/**
- * anaconda_base_window_set_info:
- * @win: a #AnacondaBaseWindow
- * @ty: a #GtkMessageType
- * @msg: a message
- *
- * Causes an info bar to be shown at the bottom of the screen with the provided
- * message.  The type argument is used to determine the background color of the
- * info bar area.  Only one message may be shown at a time.  In order to show
- * a second message, anaconda_base_window_clear_info must first be called.
- *
- * Since: 1.0
- */
-void anaconda_base_window_set_info(AnacondaBaseWindow *win, GtkMessageType ty, const char *msg) {
+static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessageType ty, const char *msg) {
     GtkWidget *label, *image, *content_area;
 
     if (win->priv->info_shown)
@@ -452,6 +439,51 @@ void anaconda_base_window_set_info(AnacondaBaseWindow *win, GtkMessageType ty, c
     win->priv->info_shown = TRUE;
 }
 
+/**
+ * anaconda_base_window_set_error:
+ * @win: a #AnacondaBaseWindow
+ * @msg: a message
+ *
+ * Causes an info bar to be shown at the bottom of the screen with the provided
+ * message.  Only one message may be shown at a time.  In order to show
+ * a second message, anaconda_base_window_clear_info must first be called.
+ *
+ * Since: 1.0
+ */
+void anaconda_base_window_set_error(AnacondaBaseWindow *win, const char *msg) {
+    anaconda_base_window_set_info_bar(win, GTK_MESSAGE_ERROR, msg);
+}
+
+/**
+ * anaconda_base_window_set_info:
+ * @win: a #AnacondaBaseWindow
+ * @msg: a message
+ *
+ * Causes an info bar to be shown at the bottom of the screen with the provided
+ * message.  Only one message may be shown at a time.  In order to show
+ * a second message, anaconda_base_window_clear_info must first be called.
+ *
+ * Since: 1.0
+ */
+void anaconda_base_window_set_info(AnacondaBaseWindow *win, const char *msg) {
+    anaconda_base_window_set_info_bar(win, GTK_MESSAGE_INFO, msg);
+}
+
+/**
+ * anaconda_base_window_set_warning:
+ * @win: a #AnacondaBaseWindow
+ * @msg: a message
+ *
+ * Causes an info bar to be shown at the bottom of the screen with the provided
+ * message.  Only one message may be shown at a time.  In order to show
+ * a second message, anaconda_base_window_clear_info must first be called.
+ *
+ * Since: 1.0
+ */
+void anaconda_base_window_set_warning(AnacondaBaseWindow *win, const char *msg) {
+    anaconda_base_window_set_info_bar(win, GTK_MESSAGE_WARNING, msg);
+}
+
 static gboolean anaconda_base_window_info_bar_clicked(GtkWidget *wiget, GdkEvent *event, AnacondaBaseWindow *win) {
     g_signal_emit(win, window_signals[SIGNAL_INFO_BAR_CLICKED], 0);
     return FALSE;
diff --git a/widgets/src/BaseWindow.h b/widgets/src/BaseWindow.h
index d82d1a3..3dd82bc 100644
--- a/widgets/src/BaseWindow.h
+++ b/widgets/src/BaseWindow.h
@@ -71,7 +71,9 @@ void        anaconda_base_window_retranslate (AnacondaBaseWindow *win);
 gboolean    anaconda_base_window_get_beta (AnacondaBaseWindow *win);
 void        anaconda_base_window_set_beta (AnacondaBaseWindow *win, gboolean is_beta);
 
-void        anaconda_base_window_set_info    (AnacondaBaseWindow *win, GtkMessageType ty, const char *msg);
+void        anaconda_base_window_set_error   (AnacondaBaseWindow *win, const char *msg);
+void        anaconda_base_window_set_info    (AnacondaBaseWindow *win, const char *msg);
+void        anaconda_base_window_set_warning (AnacondaBaseWindow *win, const char *msg);
 void        anaconda_base_window_clear_info  (AnacondaBaseWindow *win);
 
 GtkWidget  *anaconda_base_window_get_action_area   (AnacondaBaseWindow *win);
-- 
1.7.11.2



More information about the anaconda-patches mailing list