/usr/share/pyshared/gtweak/tweakmodel.py is in gnome-tweak-tool 3.4.0.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | # This file is part of gnome-tweak-tool.
#
# Copyright (c) 2011 John Stowers
#
# gnome-tweak-tool is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# gnome-tweak-tool is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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/>.
import logging
import glob
import os.path
import gtweak
from gi.repository import Gtk
TWEAK_GROUP_FONTS = _("Fonts")
TWEAK_GROUP_THEME = _("Theme")
TWEAK_GROUP_DESKTOP = _("Desktop")
TWEAK_GROUP_WINDOWS = _("Windows")
#translate this the same as the name of the file manager (nautilus)
TWEAK_GROUP_FILES = _("Files")
LOG = logging.getLogger(__name__)
class Tweak:
def __init__(self, name, description, **options):
self.name = name
self.description = description
self.group_name = options.get("group_name",_("Miscellaneous"))
self.loaded = True
self._search_cache = None
#FIXME: I would have rather done this as a GObject signal, but it
#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 = set([i.strip(" .,\n'\"").lower() for j in (
self.name.split(' '),self.description.split(' ')) for i in j])
return txt.strip().lower() in self._search_cache
def set_notify_cb(self, func):
self._notify_cb = func
def notify_action_required(self, desc, btn, func, error=False):
if self._notify_cb:
self._notify_cb(self, desc, error, btn, func)
def notify_error(self, desc):
if self._notify_cb:
self._notify_cb(self, desc, True, None, None)
def notify_info(self, desc):
if self._notify_cb:
self._notify_cb(self, desc, False, None, None)
class TweakGroup:
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]
for t in tweaks:
if t.widget_for_size_group:
self._sg.add_widget(t.widget_for_size_group)
class TweakModel(Gtk.ListStore):
(COLUMN_NAME,
COLUMN_TWEAK) = range(2)
def __init__(self):
super(TweakModel, self).__init__(str, object)
self._tweak_dir = gtweak.TWEAK_DIR
assert(os.path.exists(self._tweak_dir))
self.set_sort_column_id(self.COLUMN_NAME, Gtk.SortType.ASCENDING)
# map of tweakgroup.name -> tweakgroup
self._tweak_group_names = {}
@property
def tweaks(self):
return [t for row in self for t in row[TweakModel.COLUMN_TWEAK].tweaks]
@property
def tweak_groups(self):
return [row[TweakModel.COLUMN_TWEAK] for row in self]
def load_tweaks(self):
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"))]
else:
tweak_files = ["tweak_test"]
if not gtweak.ENABLE_TEST:
try:
tweak_files.remove("tweak_test")
except ValueError:
pass
groups = []
tweaks = []
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", []) )
for g in groups:
self.add_tweak_group(g)
for t in tweaks:
self.add_tweak_auto_to_group(t)
def add_tweak_group(self, tweakgroup):
if tweakgroup.name in self._tweak_group_names:
LOG.critical("Tweak group named: %s already exists" % tweakgroup.name)
return
self.append([tweakgroup.name, tweakgroup])
self._tweak_group_names[tweakgroup.name] = tweakgroup
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):
return [t for t in self.tweaks if t.search_matches(txt)]
|