Commit 4620d0b3 authored by John Stowers's avatar John Stowers

Add a standard way for showing stateful error and warning messages

	* One can now show symbolic icons after the label in
	* Use this to show errors if the shell is not running
	  (for user-theme)
parent ad8a2233
......@@ -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"])"Shell user-theme extension v%s", self._usertheme_extension_version)
error = None
......@@ -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
self.widget = build_label_beside_widget(, info)
self.widget_for_size_group = info
cb = build_combo_box_text(None)
self.widget = build_label_beside_widget(, cb, warning=error)
self.widget_for_size_group = cb
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(, hb)
self.widget = build_label_beside_widget(, 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) )
......@@ -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(
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)),
......@@ -15,19 +15,48 @@
# You should have received a copy of the GNU General Public License
# along with gnome-tweak-tool. If not, see <>.
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")
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")
icon = ""
if icon:
image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)
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):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment