# 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/>.importos.path

defsingleton(cls):""" Singleton decorator that works with GObject derived types. The 'recommended' python one - http://wiki.python.org/moin/PythonDecoratorLibrary#Singleton does not (interacts badly with GObjectMeta """instances={}defgetinstance():ifclsnotininstances:instances[cls]=cls()returninstances[cls]returngetinstance

""" Turns a list of values into a list of value,name (where name is the display name a user will see in a combo box). If a value is opt is equal to that supplied in default the display name for that value is modified to "value <i>(default)</i>" @opts: a list of value @returns: a list of 2-tuples (value, name) """

@singletonclassXSettingsOverrides:VARIANT_TYPES={'Gtk/ShellShowsAppMenu':GLib.Variant.new_int32,'Gtk/EnablePrimaryPaste':GLib.Variant.new_int32,}def__init__(self):self._settings=Gio.Settings('org.gnome.settings-daemon.plugins.xsettings')self._variant=self._settings.get_value("overrides")def_dup_variant_as_dict(self):items={}forkinself._variant.keys():try:#variant override doesnt support .items()v=self._variant[k]items[k]=self.VARIANT_TYPES[k](v)exceptKeyError:passreturnitemsdef_dup_variant(self):returnGLib.Variant('a{sv}',self._dup_variant_as_dict())def_set_override(self,name,v):items=self._dup_variant_as_dict()items[name]=self.VARIANT_TYPES[name](v)n=GLib.Variant('a{sv}',items)self._settings.set_value('overrides',n)def_get_override(self,name,default):try:returnself._variant[name]exceptKeyError:returndefault#while I could store meta type information in the VARIANT_TYPES#dict, its easiest to do default value handling and missing value#checks in dedicated functionsdefset_shell_shows_app_menu(self,v):self._set_override('Gtk/ShellShowsAppMenu',int(v))defget_shell_shows_app_menu(self):