Commit 967d7719 authored by John Stowers's avatar John Stowers

Convert tweak_desktop to new TweakGroup API

parent 73067b11
......@@ -84,24 +84,10 @@ class Tweak(object):
if self._notify_cb:
self._notify_cb(self, desc, error=False, btn=None, func=None, need_logout=need_logout)
class TweakGroup:
class TweakGroup(object):
def __init__(self, name, *tweaks):
self.name = name
self.tweaks = []
self._sg = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL)
self._sg.props.ignore_hidden = True
self.set_tweaks(*tweaks)
def set_tweaks(self, *tweaks):
self.tweaks += [t for t in tweaks if t.loaded]
for t in tweaks:
if not t.loaded:
continue
if t.widget_for_size_group:
self._sg.add_widget(t.widget_for_size_group)
self.tweaks = [t for t in tweaks if t.loaded]
class TweakModel(Gtk.ListStore):
(COLUMN_NAME,
......@@ -130,7 +116,7 @@ class TweakModel(Gtk.ListStore):
if 1:
tweak_files = [
os.path.splitext(os.path.split(f)[-1])[0]
for f in glob.glob(os.path.join(self._tweak_dir, "tweak_*.py"))]
for f in glob.glob(os.path.join(self._tweak_dir, "tweak_group_*.py"))]
else:
tweak_files = ["tweak_test"]
......@@ -152,7 +138,6 @@ class TweakModel(Gtk.ListStore):
mods = __import__("gtweak.tweaks", globals(), locals(), tweak_files, 0)
for mod in [getattr(mods, file_name) for file_name in tweak_files]:
groups.extend( getattr(mod, "TWEAK_GROUPS", []) )
tweaks.extend( getattr(mod, "TWEAKS", []) )
schemas = SchemaList()
......@@ -164,12 +149,6 @@ class TweakModel(Gtk.ListStore):
schemas.insert(i.key_name, i.schema_name)
except:
pass
for t in tweaks:
self.add_tweak_auto_to_group(t)
try:
schemas.insert(t.key_name, t.schema_name)
except:
pass
def add_tweak_group(self, tweakgroup):
if tweakgroup.name in self._tweak_group_names:
......@@ -180,18 +159,6 @@ class TweakModel(Gtk.ListStore):
self._tweak_group_names[tweakgroup.name] = tweakgroup
self._tweak_group_iters[tweakgroup.name] = _iter
def add_tweak_auto_to_group(self, tweak):
if not tweak.loaded:
return
name = tweak.group_name
try:
group = self._tweak_group_names[name]
except KeyError:
group = TweakGroup(name)
self.add_tweak_group(group)
group.set_tweaks(tweak)
def search_matches(self, txt):
tweaks = []
groups = []
......
......@@ -19,8 +19,7 @@ from gi.repository import Gtk
import gtweak
from gtweak.utils import AutostartManager
from gtweak.tweakmodel import TWEAK_GROUP_DESKTOP
from gtweak.widgets import GSettingsSwitchTweak, GSettingsComboEnumTweak, GSettingsFileChooserButtonTweak, GSettingsCheckTweak
from gtweak.widgets import ListBoxTweakGroup, GSettingsSwitchTweak, GSettingsComboEnumTweak, GSettingsFileChooserButtonTweak, GSettingsCheckTweak
class DesktopIconTweak(GSettingsSwitchTweak):
def __init__(self, **options):
......@@ -44,13 +43,16 @@ class DesktopIconTweak(GSettingsSwitchTweak):
self.nautilus.update_start_at_login(
self.settings.get_boolean(key))
dicons = DesktopIconTweak(group_name=TWEAK_GROUP_DESKTOP)
TWEAKS = (
dicons,
GSettingsCheckTweak("Computer","org.gnome.nautilus.desktop", "computer-icon-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml",group_name=TWEAK_GROUP_DESKTOP),
GSettingsCheckTweak("Home","org.gnome.nautilus.desktop", "home-icon-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml",group_name=TWEAK_GROUP_DESKTOP),
GSettingsCheckTweak("Network Servers","org.gnome.nautilus.desktop", "network-icon-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml",group_name=TWEAK_GROUP_DESKTOP),
GSettingsCheckTweak("Trash","org.gnome.nautilus.desktop", "trash-icon-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml",group_name=TWEAK_GROUP_DESKTOP),
GSettingsCheckTweak("Mounted Volumes","org.gnome.nautilus.desktop", "volumes-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml",group_name=TWEAK_GROUP_DESKTOP),
)
dicons = DesktopIconTweak()
TWEAK_GROUPS = [
ListBoxTweakGroup("Desktop",
dicons,
GSettingsCheckTweak("Computer","org.gnome.nautilus.desktop", "computer-icon-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml"),
GSettingsCheckTweak("Home","org.gnome.nautilus.desktop", "home-icon-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml"),
GSettingsCheckTweak("Network Servers","org.gnome.nautilus.desktop", "network-icon-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml"),
GSettingsCheckTweak("Trash","org.gnome.nautilus.desktop", "trash-icon-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml"),
GSettingsCheckTweak("Mounted Volumes","org.gnome.nautilus.desktop", "volumes-visible", depends_on=dicons, schema_filename="org.gnome.nautilus.gschema.xml"),
)
]
......@@ -132,37 +132,25 @@ class Window(Gtk.ApplicationWindow):
def load_model_data(self):
def _items_listbox(text):
def _make_items_listbox(text):
lbl = Gtk.Label(text, xalign=0.0)
lbl.set_name('row')
row = Gtk.ListBoxRow(name="tweak-category")
row.add(lbl)
return row
def _load_tweaks(group):
itere = self._model.get_tweakgroup_iter(group)
tweakgroup = self._model.get_value(itere, self._model.COLUMN_TWEAK)
box = Gtk.ListBox(name="tweak-group",
selection_mode=Gtk.SelectionMode.NONE)
for t in sorted(tweakgroup.tweaks, key=_sort_tweak_widgets_by_widget_type):
cssname = "tweak"
if isinstance(t, Title):
cssname = "tweak-title"
row = Gtk.ListBoxRow(name=cssname)
row.add(t)
box.add(row)
t.set_notify_cb(self._on_tweak_notify)
scroll = Gtk.ScrolledWindow()
scroll.add(box)
self.stack.add_named(scroll, group)
groups = self._model._tweak_group_names.keys()
groups = sorted(groups)
for g in groups:
row = _items_listbox(g)
row = _make_items_listbox(g)
self.listbox.add(row)
_load_tweaks(g)
tweakgroup = self._model.get_value(
self._model.get_tweakgroup_iter(g),
self._model.COLUMN_TWEAK)
scroll = Gtk.ScrolledWindow()
scroll.add(tweakgroup)
self.stack.add_named(scroll, g)
widget = self.listbox.get_row_at_index(0)
self.listbox.select_row (widget)
......
......@@ -20,7 +20,7 @@ import os.path
from gi.repository import GLib, Gtk, Gdk, Gio, Pango
from gtweak.tweakmodel import Tweak
from gtweak.tweakmodel import Tweak, TweakGroup
from gtweak.gsettings import GSettingsSetting, GSettingsFakeSetting, GSettingsMissingError
from gtweak.gtksettings import GtkSettingsManager
from gtweak.gshellwrapper import GnomeShellFactory
......@@ -211,6 +211,26 @@ class _DependableMixin(object):
sensitive = self._depends_how(settings,key_name)
self.set_sensitive(sensitive)
class ListBoxTweakGroup(Gtk.ListBox, TweakGroup):
def __init__(self, name, *tweaks):
Gtk.ListBox.__init__(self,
name="tweak-group",
selection_mode=Gtk.SelectionMode.NONE)
TweakGroup.__init__(self, name, *tweaks)
self._sg = Gtk.SizeGroup(
mode=Gtk.SizeGroupMode.HORIZONTAL)
self._sg.props.ignore_hidden = True
for t in self.tweaks:
cssname = "tweak"
if isinstance(t, Title):
cssname = "tweak-title"
row = Gtk.ListBoxRow(name=cssname)
row.add(t)
self.add(row)
if t.widget_for_size_group:
self._sg.add_widget(t.widget_for_size_group)
class GSettingsCheckTweak(Gtk.Box, _GSettingsTweak, _DependableMixin):
def __init__(self, name, schema_name, key_name, **options):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
......
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