[gnome-tweak-tool] Add a standard way for showing stateful error and warning messages



commit 4620d0b3e279a4e72a033d9b7447ee984eefbae6
Author: John Stowers <john stowers gmail com>
Date:   Mon Jun 20 09:23:28 2011 +1200

    Add a standard way for showing stateful error and warning messages
    
    	* One can now show symbolic icons after the label in
    	  build_label_beside_widget.
    	* Use this to show errors if the shell is not running
    	  (for user-theme)

 gtweak/tweaks/tweak_shell.py |   26 +++++++++++---------------
 gtweak/tweaks/tweak_test.py  |   13 +++++++++++++
 gtweak/widgets.py            |   37 +++++++++++++++++++++++++++++++++----
 3 files changed, 57 insertions(+), 19 deletions(-)
---
diff --git a/gtweak/tweaks/tweak_shell.py b/gtweak/tweaks/tweak_shell.py
index dab5509..99c47e0 100644
--- a/gtweak/tweaks/tweak_shell.py
+++ b/gtweak/tweaks/tweak_shell.py
@@ -68,6 +68,7 @@ class ShellThemeTweak(Tweak):
                     #assume the usertheme version is that version of the shell which
                     #it most supports (this is a poor assumption)
                     self._usertheme_extension_version = max(extensions[ShellThemeTweak.THEME_EXT_NAME]["shell-version"])
+                    logging.info("Shell user-theme extension v%s", self._usertheme_extension_version)
 
                     error = None
                 except:
@@ -79,14 +80,10 @@ class ShellThemeTweak(Tweak):
             error = "Could not list shell extensions"
 
         if error:
-            info = Gtk.InfoBar()
-            info.props.message_type = Gtk.MessageType.INFO
-            info.get_content_area().add(Gtk.Label(error))
-            self.widget = build_label_beside_widget(self.name, info)
-            self.widget_for_size_group = info
+            cb = build_combo_box_text(None)
+            self.widget = build_label_beside_widget(self.name, cb, warning=error)
+            self.widget_for_size_group = cb
         else:
-            hb = Gtk.HBox()
-
             #include both system, and user themes
             #note: the default theme lives in /system/data/dir/gnome-shell/theme
             #      and not themes/, so add it manually later
@@ -97,10 +94,6 @@ class ShellThemeTweak(Tweak):
                         os.path.exists(os.path.join(d, "gnome-shell")) and \
                         os.path.exists(os.path.join(d, "gnome-shell", "gnome-shell.css")))
 
-            chooser = ZipFileChooserButton("Select a theme file")
-            chooser.connect("file-set", self._on_file_set)
-            hb.pack_start(chooser, False, False, 5)
-
             #build a combo box with all the valid theme options
             #manually add Adwaita to represent the default
             cb = build_combo_box_text(
@@ -108,10 +101,13 @@ class ShellThemeTweak(Tweak):
                     ("", "default"),
                     *[(v,v) for v in valid])
             cb.connect('changed', self._on_combo_changed)
-            hb.pack_start(cb, False, False, 0)
-            self.combo = cb
+            self._combo = cb
+
+            #a filechooser to install new themes
+            chooser = ZipFileChooserButton("Select a theme file")
+            chooser.connect("file-set", self._on_file_set)
 
-            self.widget = build_label_beside_widget(self.name, hb)
+            self.widget = build_label_beside_widget(self.name, chooser, cb)
             self.widget_for_size_group = cb
     
     def _on_file_set(self, chooser):
@@ -161,7 +157,7 @@ class ShellThemeTweak(Tweak):
 
                     #I suppose I could rely on updated as indicating whether to add the theme
                     #name to the combo, but just check to see if it is already there
-                    model = self.combo.get_model()
+                    model = self._combo.get_model()
                     if theme_name not in [r[0] for r in model]:
                         model.append( (theme_name, theme_name) )
                 else:
diff --git a/gtweak/tweaks/tweak_test.py b/gtweak/tweaks/tweak_test.py
index 1f74a28..14203ca 100644
--- a/gtweak/tweaks/tweak_test.py
+++ b/gtweak/tweaks/tweak_test.py
@@ -20,6 +20,17 @@ from __future__ import print_function
 from gi.repository import Gtk
 
 from gtweak.tweakmodel import Tweak, TweakGroup
+from gtweak.widgets import build_label_beside_widget
+
+class _TestInfoTweak(Tweak):
+    def __init__(self, name, description, **options):
+        Tweak.__init__(self, name, description, **options)
+
+        self.widget = build_label_beside_widget(
+                        name,
+                        Gtk.Button(name),
+                        info=options.get("tweak_info"),
+                        warning=options.get("tweak_warning"))
 
 class _TestTweak(Tweak):
     def __init__(self, name, description, **options):
@@ -51,6 +62,8 @@ TWEAK_GROUPS = (
             "Test Foo Bar",
             _TestTweak("foo bar", "does foo bar"),
             _TestTweak("foo baz", "does foo baz"),
+            _TestInfoTweak("foo info", "info widget", tweak_info="Information"),
+            _TestInfoTweak("foo warning", "info widget", tweak_warning="Warning"),
             _TestButtonTweak("Need Action", "foo bar", need_action=True),
             _TestButtonTweak("Report Error", "foo baz", action_error=True),
             _TestButtonTweak("Report Info", "foo bob", action_error=False)),
diff --git a/gtweak/widgets.py b/gtweak/widgets.py
index d1b3907..05277a4 100644
--- a/gtweak/widgets.py
+++ b/gtweak/widgets.py
@@ -15,19 +15,48 @@
 # You should have received a copy of the GNU General Public License
 # along with gnome-tweak-tool.  If not, see <http://www.gnu.org/licenses/>.
 
-from gi.repository import Gtk, Gio
+from gi.repository import Gtk, Gdk, Gio
 
 from gtweak.tweakmodel import Tweak
 from gtweak.gsettings import GSettingsSetting
 from gtweak.gconf import GConfSetting
 
-def build_label_beside_widget(txt, widget, hbox=None):
-    if not hbox:
+def build_label_beside_widget(txt, *widget, **kwargs):
+    """
+    Builds a HBox containing widgets.
+
+    Optional Kwargs:
+        hbox: Use an existing HBox, not a new one
+        info: Informational text to be shown after the label
+        warning: Warning text to be shown after the label
+    """
+    if kwargs.get("hbox"):
+        hbox = kwargs.get("hbox")
+    else:
         hbox = Gtk.HBox()
+
+    hbox.props.spacing = 4
     lbl = Gtk.Label(txt)
     lbl.props.xalign = 0.0
     hbox.pack_start(lbl, True, True, 0)
-    hbox.pack_start(widget, False, False, 0)
+
+    if kwargs.get("info"):
+        icon = "dialog-information-symbolic"
+        tip = kwargs.get("info")
+    elif kwargs.get("warning"):
+        icon = "dialog-warning-symbolic"
+        tip = kwargs.get("warning")
+    else:
+        icon = ""
+
+    if icon:
+        image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)
+        image.set_tooltip_text(tip)
+        hbox.pack_start(image, False, False, 0)
+
+    for w in widget:
+        hbox.pack_start(w, False, False, 0)
+
     return hbox
 
 def build_combo_box_text(selected, *values):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]