Commit b948854d authored by John Stowers's avatar John Stowers

Generalise a getter/setter tweak

parent 2033f305
......@@ -17,35 +17,22 @@
import os.path
from gi.repository import GLib, Gtk
from gi.repository import GLib
import gtweak
from gtweak.tweakmodel import Tweak
from gtweak.utils import XSettingsOverrides, walk_directories, make_combo_list_with_default
from gtweak.widgets import ListBoxTweakGroup, GSettingsComboTweak, GSettingsSwitchTweak, Title, build_label_beside_widget
from gtweak.widgets import ListBoxTweakGroup, GSettingsComboTweak, GSettingsSwitchTweak, GetterSetterSwitchTweak, Title
class PrimaryPasteTweak(Gtk.Box, Tweak):
class PrimaryPasteTweak(GetterSetterSwitchTweak):
def __init__(self, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
name = _("Middle-click Paste")
description = ""
Tweak.__init__(self, name, description, **options)
self._xsettings = XSettingsOverrides()
GetterSetterSwitchTweak.__init__(self, _("Middle-click Paste"), **options)
sw = Gtk.Switch()
sw.set_active(self._xsettings.get_enable_primary_paste())
sw.connect("notify::active", self._on_toggled)
build_label_beside_widget(
name,
sw,
hbox=self)
def get_active(self):
return self._xsettings.get_enable_primary_paste()
def _on_toggled(self, sw, pspec):
self._xsettings.set_enable_primary_paste(sw.get_active())
def set_active(self, v):
self._xsettings.set_enable_primary_paste(v)
class KeyThemeSwitcher(GSettingsComboTweak):
def __init__(self, **options):
......
......@@ -20,34 +20,22 @@ from gi.repository import Gtk, Gio
from gtweak.gsettings import GSettingsSetting, GSettingsMissingError, GSettingsFakeSetting
from gtweak.gshellwrapper import GnomeShellFactory
from gtweak.tweakmodel import Tweak, TWEAK_GROUP_TOPBAR, TWEAK_GROUP_WORKSPACES, TWEAK_GROUP_POWER
from gtweak.widgets import ListBoxTweakGroup, GSettingsComboEnumTweak, GSettingsSwitchTweak, GSettingsCheckTweak, adjust_schema_for_overrides, build_label_beside_widget, build_horizontal_sizegroup, UI_BOX_SPACING, Title
from gtweak.widgets import ListBoxTweakGroup, GSettingsComboEnumTweak, GSettingsSwitchTweak, GSettingsCheckTweak, GetterSetterSwitchTweak, adjust_schema_for_overrides, build_label_beside_widget, build_horizontal_sizegroup, UI_BOX_SPACING, Title
from gtweak.utils import XSettingsOverrides
_shell = GnomeShellFactory().get_shell()
_shell_loaded = _shell is not None
class ApplicationMenuTweak(Gtk.Box, Tweak):
class ApplicationMenuTweak(GetterSetterSwitchTweak):
def __init__(self, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
name = _("Show Application Menu")
description = ""
Tweak.__init__(self, name, description, **options)
self._xsettings = XSettingsOverrides()
GetterSetterSwitchTweak.__init__(self, _("Show Application Menu"), **options)
sw = Gtk.Switch()
sw.set_active(self._xsettings.get_shell_shows_app_menu())
sw.connect("notify::active", self._on_toggled)
build_label_beside_widget(
name,
sw,
hbox=self)
def get_active(self):
return self._xsettings.get_shell_shows_app_menu()
def _on_toggled(self, sw, pspec):
self._xsettings.set_shell_shows_app_menu(sw.get_active())
def set_active(self, v):
self._xsettings.set_shell_shows_app_menu(v)
class StaticWorkspaceTweak(Gtk.Box, Tweak):
......
......@@ -415,6 +415,26 @@ class GSettingsFileChooserButtonTweak(Gtk.Box, _GSettingsTweak, _DependableMixin
if uri and self._values_are_different():
self.settings.set_string(self.key_name, uri)
class GetterSetterSwitchTweak(Gtk.Box, Tweak):
def __init__(self, name, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
Tweak.__init__(self, name, options.get("description",""), **options)
sw = Gtk.Switch()
sw.set_active(self.get_active())
sw.connect("notify::active", self._on_toggled)
build_label_beside_widget(name, sw, hbox=self)
def _on_toggled(self, sw, pspec):
self.set_active(sw.get_active())
def get_active(self):
raise NotImplementedError()
def set_active(self, v):
raise NotImplementedError()
class DarkThemeSwitcher(Gtk.Box, Tweak):
def __init__(self, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
......
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