/usr/lib/python2.7/dist-packages/gtweak/gshellwrapper.py is in gnome-tweak-tool 3.22.0-1.
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | # 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 os.path
import json
import logging
from gi.repository import Gio
from gi.repository import GLib
import gtweak.utils
from gtweak.gsettings import GSettingsSetting
class _ShellProxy:
def __init__(self):
d = Gio.bus_get_sync(Gio.BusType.SESSION, None)
self.proxy = Gio.DBusProxy.new_sync(
d, 0, None,
'org.gnome.Shell',
'/org/gnome/Shell',
'org.gnome.Shell',
None)
#GNOME Shell > 3.5 added a separate extension interface
self.proxy_extensions = Gio.DBusProxy.new_sync(
d, 0, None,
'org.gnome.Shell',
'/org/gnome/Shell',
'org.gnome.Shell.Extensions',
None)
#GNOME Shell > 3.7.2 added the Mode to the DBus API
val = self.proxy.get_cached_property("Mode")
if val is not None:
self._mode = val.unpack()
else:
js = 'global.session_mode'
result, output = self.proxy.Eval('(s)', js)
if result and output:
self._mode = json.loads(output)
else:
logging.warning("Error getting shell mode via Eval JS")
self._mode = "user"
#GNOME Shell > 3.3 added the Version to the DBus API and disabled execute_js
val = self.proxy.get_cached_property("ShellVersion")
if val is not None:
self._version = val.unpack()
else:
js = 'const Config = imports.misc.config; Config.PACKAGE_VERSION'
result, output = self.proxy.Eval('(s)', js)
if result and output:
self._version = json.loads(output)
else:
logging.critical("Error getting shell version via Eval JS")
self._version = "0.0.0"
@property
def mode(self):
return self._mode
@property
def version(self):
return self._version
class GnomeShell:
EXTENSION_STATE = {
"ENABLED" : 1,
"DISABLED" : 2,
"ERROR" : 3,
"OUT_OF_DATE" : 4,
"DOWNLOADING" : 5,
"INITIALIZED" : 6,
}
EXTENSION_TYPE = {
"SYSTEM" : 1,
"PER_USER" : 2
}
DATA_DIR = os.path.join(GLib.get_user_data_dir(), "gnome-shell")
EXTENSION_DIR = os.path.join(GLib.get_user_data_dir(), "gnome-shell", "extensions")
def __init__(self, shellproxy, shellsettings):
self._proxy = shellproxy
self._settings = shellsettings
def _execute_js(self, js):
result, output = self._proxy.proxy.Eval('(s)', js)
if not result:
raise Exception(output)
return output
def restart(self):
self._execute_js('global.reexec_self();')
def reload_theme(self):
self._execute_js('const Main = imports.ui.main; Main.loadTheme();')
def uninstall_extension(self, uuid):
pass
@property
def mode(self):
return self._proxy.mode
@property
def version(self):
return self._proxy.version
class GnomeShell32(GnomeShell):
EXTENSION_ENABLED_KEY = "enabled-extensions"
SUPPORTS_EXTENSION_PREFS = False
def list_extensions(self):
return self._proxy.proxy.ListExtensions()
def extension_is_active(self, state, uuid):
return state == GnomeShell.EXTENSION_STATE["ENABLED"] and \
self._settings.setting_is_in_list(self.EXTENSION_ENABLED_KEY, uuid)
def enable_extension(self, uuid):
self._settings.setting_add_to_list(self.EXTENSION_ENABLED_KEY, uuid)
def disable_extension(self, uuid):
self._settings.setting_remove_from_list(self.EXTENSION_ENABLED_KEY, uuid)
class GnomeShell34(GnomeShell32):
SUPPORTS_EXTENSION_PREFS = True
def restart(self):
logging.warning("Restarting Shell Not Supported")
def reload_theme(self):
logging.warning("Reloading Theme Not Supported")
def uninstall_extension(self, uuid):
return self._proxy.proxy.UninstallExtension('(s)', uuid)
class GnomeShell36(GnomeShell34):
def list_extensions(self):
return self._proxy.proxy_extensions.ListExtensions()
def uninstall_extension(self, uuid):
return self._proxy.proxy_extensions.UninstallExtension('(s)', uuid)
def install_remote_extension(self, uuid, reply_handler, error_handler, user_data):
self._proxy.proxy_extensions.InstallRemoteExtension('(s)', uuid, result_handler=reply_handler, error_handler=error_handler, user_data=user_data)
@gtweak.utils.singleton
class GnomeShellFactory:
def __init__(self):
try:
proxy = _ShellProxy()
settings = GSettingsSetting("org.gnome.shell")
v = map(int,proxy.version.split("."))
if v >= [3,5,0]:
self.shell = GnomeShell36(proxy, settings)
elif v >= [3,3,2]:
self.shell = GnomeShell34(proxy, settings)
elif v >= [3,1,4]:
self.shell = GnomeShell32(proxy, settings)
else:
logging.warn("Shell version not supported")
self.shell = None
logging.debug("Shell version: %s", str(v))
except:
self.shell = None
logging.warn("Shell not installed or running")
def get_shell(self):
return self.shell
if __name__ == "__main__":
gtweak.GSETTINGS_SCHEMA_DIR = "/usr/share/glib-2.0/schemas/"
logging.basicConfig(format="%(levelname)-8s: %(message)s", level=logging.DEBUG)
s = GnomeShellFactory().get_shell()
print "Shell Version: %s" % s.version
print s.list_extensions()
print s == GnomeShellFactory().get_shell()
|