Commit 256f5e8c authored by John Stowers's avatar John Stowers

convert tweaks to gtk widgets

parent 49e2ea7c
......@@ -45,8 +45,11 @@ TWEAK_SORT_LAST = 1e3
LOG = logging.getLogger(__name__)
class Tweak:
class Tweak(object):
main_window = None
widget_for_size_group = None
def __init__(self, name, description, **options):
self.name = name
self.description = description
......@@ -61,14 +64,6 @@ class Tweak:
#would prohibit other tweaks from inheriting from GtkWidgets
self._notify_cb = None
@property
def widget(self):
raise NotImplementedError
@property
def widget_for_size_group(self):
return None
def search_matches(self, txt):
if self._search_cache == None:
self._search_cache = self.name.lower() + " " + self.description.lower()
......
......@@ -46,7 +46,7 @@ class ShowWindowButtons(GSettingsComboTweak):
loaded=_shell_loaded,
**options)
class ShellThemeTweak(Tweak):
class ShellThemeTweak(Gtk.Box, Tweak):
THEME_EXT_NAME = "user-theme@gnome-shell-extensions.gcampax.github.com"
THEME_GSETTINGS_SCHEMA = "org.gnome.shell.extensions.user-theme"
......@@ -57,6 +57,7 @@ class ShellThemeTweak(Tweak):
THEME_DIR = os.path.join(GLib.get_user_data_dir(), "themes")
def __init__(self, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
Tweak.__init__(self, _("Shell theme"), _("Install custom or user themes for gnome-shell"), **options)
#check the shell is running and the usertheme extension is present
......@@ -97,7 +98,9 @@ class ShellThemeTweak(Tweak):
if error:
cb = build_combo_box_text(None)
self.widget = build_label_beside_widget(self.name, cb, warning=error)
build_label_beside_widget(self.name, cb,
warning=error,
hbox=self)
self.widget_for_size_group = cb
else:
#include both system, and user themes
......@@ -131,7 +134,7 @@ class ShellThemeTweak(Tweak):
["application/zip"])
chooser.connect("file-set", self._on_file_set)
self.widget = build_label_beside_widget(self.name, chooser, cb)
build_label_beside_widget(self.name, chooser, cb, hbox=self)
self.widget_for_size_group = cb
self.widget_sort_hint = TWEAK_SORT_LAST
......@@ -202,7 +205,7 @@ class ShellThemeTweak(Tweak):
val = combo.get_model().get_value(combo.get_active_iter(), 0)
self._settings.set_string(ShellThemeTweak.THEME_GSETTINGS_NAME, val)
class StaticWorkspaceTweak(Tweak):
class StaticWorkspaceTweak(Gtk.Box, Tweak):
NUM_WORKSPACES_SCHEMA = "org.gnome.desktop.wm.preferences"
NUM_WORKSPACES_KEY = "num-workspaces"
......@@ -212,6 +215,7 @@ class StaticWorkspaceTweak(Tweak):
def __init__(self, **options):
schema = adjust_schema_for_overrides(self.DYNAMIC_SCHEMA, self.DYNAMIC_KEY, options)
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
Tweak.__init__(self, _("Dynamic workspaces"), _("Disable gnome-shell dynamic workspace management, use static workspaces"), **options)
try:
......@@ -240,7 +244,7 @@ class StaticWorkspaceTweak(Tweak):
hb.pack_start(sw, False, False, 0)
hb.pack_start(sb, True, True, 0)
self.widget = build_label_beside_widget(self.name, hb)
build_label_beside_widget(self.name, hb, hbox=self)
self.widget_for_size_group = hb
sg = build_horizontal_sizegroup()
......
......@@ -19,9 +19,10 @@ from gtweak.utils import DisableExtension
def N_(x): return x
class _ShellExtensionTweak(Tweak):
class _ShellExtensionTweak(Gtk.Box, Tweak):
def __init__(self, shell, ext, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
Tweak.__init__(self, ext["name"], ext.get("description",""), **options)
self._shell = shell
......@@ -68,10 +69,11 @@ class _ShellExtensionTweak(Tweak):
widgets.append(sw)
self.widget = build_label_beside_widget(
build_label_beside_widget(
ext["name"].lower().capitalize(),
*widgets,
warning=warning)
warning=warning,
hbox=self)
self.widget_for_size_group = None
def _on_disable_extension(self, de, sw):
......@@ -130,9 +132,10 @@ class _ShellExtensionTweak(Tweak):
if self.widget.get_visible() == True:
self.widget.show_all()
class _ShellExtensionInstallerTweak(Tweak):
class _ShellExtensionInstallerTweak(Gtk.Box, Tweak):
def __init__(self, shell, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
Tweak.__init__(self, _("Install Shell Extension"), "", **options)
self._shell = shell
......@@ -149,7 +152,7 @@ class _ShellExtensionInstallerTweak(Tweak):
False, False, 0)
hb.pack_start(chooser, False, False, 0)
self.widget = build_label_beside_widget(self.name, hb)
build_label_beside_widget(self.name, hb, hbox=self)
self.widget_for_size_group = hb
self.loaded = self._shell is not None
......
......@@ -149,7 +149,7 @@ class Window(Gtk.ApplicationWindow):
if isinstance(t, Title):
cssname = "tweak-title"
row = Gtk.ListBoxRow(name=cssname)
row.add(t.widget)
row.add(t)
box.add(row)
t.set_notify_cb(self._on_tweak_notify)
scroll = Gtk.ScrolledWindow()
......@@ -216,9 +216,9 @@ class Window(Gtk.ApplicationWindow):
def show_only_tweaks(self, tweaks):
for t in self._model.tweaks:
if t in tweaks:
t.widget.show_all()
t.show_all()
else:
t.widget.hide()
t.hide()
def _on_tweak_notify_response(self, info, response, func):
self._detail_vbox.remove(info)
......
......@@ -190,7 +190,7 @@ class _GSettingsTweak(Tweak):
need_logout=True,
)
class _DependableMixin:
class _DependableMixin(object):
def add_dependency_on_tweak(self, depends, depends_how):
if isinstance(depends, Tweak):
......@@ -203,23 +203,25 @@ class _DependableMixin:
depends.settings,
depends.key_name,
)
self.widget.set_sensitive(sensitive)
self.set_sensitive(sensitive)
depends.settings.connect("changed::%s" % depends.key_name, self._on_changed_depend)
def _on_changed_depend(self, settings, key_name):
sensitive = self._depends_how(settings,key_name)
self.widget.set_sensitive(sensitive)
self.set_sensitive(sensitive)
class GSettingsCheckTweak(_GSettingsTweak, _DependableMixin):
class GSettingsCheckTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, name, schema_name, key_name, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
self.widget = Gtk.CheckButton.new_with_label(name)
widget = Gtk.CheckButton.new_with_label(name)
self.settings.bind(
key_name,
self.widget,
widget,
"active", Gio.SettingsBindFlags.DEFAULT)
self.add(widget)
self.widget_for_size_group = None
self.add_dependency_on_tweak(
......@@ -227,14 +229,15 @@ class GSettingsCheckTweak(_GSettingsTweak, _DependableMixin):
options.get("depends_how")
)
class GSettingsSwitchTweak(_GSettingsTweak, _DependableMixin):
class GSettingsSwitchTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, name, schema_name, key_name, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
w = Gtk.Switch()
self.settings.bind(key_name, w, "active", Gio.SettingsBindFlags.DEFAULT)
self.widget = build_label_beside_widget(name, w)
# never change the size of a switch
build_label_beside_widget(name, w, hbox=self)
self.widget_for_size_group = None
self.add_dependency_on_tweak(
......@@ -242,17 +245,19 @@ class GSettingsSwitchTweak(_GSettingsTweak, _DependableMixin):
options.get("depends_how")
)
class GSettingsFontButtonTweak(_GSettingsTweak, _DependableMixin):
class GSettingsFontButtonTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, name, schema_name, key_name, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
w = Gtk.FontButton()
self.settings.bind(key_name, w, "font-name", Gio.SettingsBindFlags.DEFAULT)
self.widget = build_label_beside_widget(name, w)
build_label_beside_widget(name, w, hbox=self)
self.widget_for_size_group = w
class GSettingsRangeTweak(_GSettingsTweak, _DependableMixin):
class GSettingsRangeTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, schema_name, key_name, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
#returned variant is range:(min, max)
......@@ -260,11 +265,13 @@ class GSettingsRangeTweak(_GSettingsTweak, _DependableMixin):
w = Gtk.HScale.new_with_range(_min, _max, options.get('adjustment_step', 1))
self.settings.bind(key_name, w.get_adjustment(), "value", Gio.SettingsBindFlags.DEFAULT)
self.widget = build_label_beside_widget(self.name, w)
build_label_beside_widget(self.name, w, hbox=self)
self.widget_for_size_group = w
class GSettingsSpinButtonTweak(_GSettingsTweak, _DependableMixin):
class GSettingsSpinButtonTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, schema_name, key_name, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
#returned variant is range:(min, max)
......@@ -275,11 +282,13 @@ class GSettingsSpinButtonTweak(_GSettingsTweak, _DependableMixin):
w.set_adjustment(adjustment)
w.set_digits(options.get('digits', 0))
self.settings.bind(key_name, adjustment, "value", Gio.SettingsBindFlags.DEFAULT)
self.widget = build_label_beside_widget(self.name, w)
build_label_beside_widget(self.name, w, hbox=self)
self.widget_for_size_group = w
class GSettingsComboEnumTweak(_GSettingsTweak, _DependableMixin):
class GSettingsComboEnumTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, name, schema_name, key_name, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
_type, values = self.settings.get_range(key_name)
......@@ -290,10 +299,9 @@ class GSettingsComboEnumTweak(_GSettingsTweak, _DependableMixin):
w.connect('changed', self._on_combo_changed)
self.combo = w
self.widget = build_label_beside_widget(name, w)
build_label_beside_widget(name, w, hbox=self)
self.widget_for_size_group = w
def _values_are_different(self):
#to stop bouncing back and forth between changed signals. I suspect there must be a nicer
#Gio.settings_bind way to fix this
......@@ -314,8 +322,9 @@ class GSettingsComboEnumTweak(_GSettingsTweak, _DependableMixin):
if self._values_are_different():
self.settings.set_string(self.key_name, val)
class GSettingsComboTweak(_GSettingsTweak, _DependableMixin):
class GSettingsComboTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, name, schema_name, key_name, key_options, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
#check key_options is iterable
......@@ -328,10 +337,11 @@ class GSettingsComboTweak(_GSettingsTweak, _DependableMixin):
self.settings.get_string(self.key_name),
*key_options)
self.combo.connect('changed', self._on_combo_changed)
self.widget = build_label_beside_widget(name, self.combo)
self.settings.connect('changed::'+self.key_name, self._on_setting_changed)
build_label_beside_widget(name, self.combo,hbox=self)
self.widget_for_size_group = self.combo
self.settings.connect('changed::'+self.key_name, self._on_setting_changed)
def _on_setting_changed(self, setting, key):
assert key == self.key_name
......@@ -364,8 +374,9 @@ class FileChooserButton(Gtk.FileChooserButton):
self.set_local_only(local_only)
self.set_action(Gtk.FileChooserAction.OPEN)
class GSettingsFileChooserButtonTweak(_GSettingsTweak, _DependableMixin):
class GSettingsFileChooserButtonTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, schema_name, key_name, local_only, mimetypes, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
self.settings.connect('changed::'+self.key_name, self._on_setting_changed)
......@@ -374,7 +385,7 @@ class GSettingsFileChooserButtonTweak(_GSettingsTweak, _DependableMixin):
self.filechooser.set_uri(self.settings.get_string(self.key_name))
self.filechooser.connect("file-set", self._on_file_set)
self.widget = build_label_beside_widget(self.name, self.filechooser)
build_label_beside_widget(self.name, self.filechooser, hbox=self)
self.widget_for_size_group = self.filechooser
def _values_are_different(self):
......@@ -388,8 +399,9 @@ class GSettingsFileChooserButtonTweak(_GSettingsTweak, _DependableMixin):
if uri and self._values_are_different():
self.settings.set_string(self.key_name, uri)
class DarkThemeSwitcher(Tweak):
class DarkThemeSwitcher(Gtk.Box, Tweak):
def __init__(self, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
Tweak.__init__(self, _("Enable dark theme for all applications"),
_("Enable the dark theme hint for all the applications in the session"),
**options)
......@@ -402,7 +414,9 @@ class DarkThemeSwitcher(Tweak):
title = _("Global Dark Theme")
description = _("Applications need to be restarted for change to take effect")
w.connect("notify::active", self._on_switch_changed)
self.widget = build_label_beside_widget(title, w, desc=description)
build_label_beside_widget(title, w, desc=description, hbox=self)
self.widget_for_size_group = None
def _on_switch_changed(self, switch, param):
active = switch.get_active()
......@@ -413,10 +427,12 @@ class DarkThemeSwitcher(Tweak):
except:
self.notify_error(_("Error writing setting"))
class Title(Tweak):
class Title(Gtk.Box, Tweak):
def __init__(self, name, desc, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
Tweak.__init__(self, name, desc, **options)
self.widget = Gtk.Label()
self.widget.set_markup("<b>"+name+"</b>")
self.widget.props.xalign = 0.0
widget = Gtk.Label()
widget.set_markup("<b>"+name+"</b>")
widget.props.xalign = 0.0
self.add(widget)
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