Commit 8b8222e7 authored by Jeremy Bicha's avatar Jeremy Bicha 🎹

cleanup: Apply some suggestions from pep8

parent 6f4d911d
......@@ -28,25 +28,28 @@ import gtweak
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option("-t", "--test", action="store_true",
help="Enable test and debug code")
help="Enable test and debug code")
parser.add_option("-l", "--load", action="store_true",
help="Load all tweaks")
help="Load all tweaks")
parser.add_option("-p", "--prefix",
help="Installation prefix (for gsettings schema, themes, etc)", metavar="[/, /usr]")
help="Installation prefix (for gsettings schema, themes, etc)",
metavar="[/, /usr]")
parser.add_option("-v", "--verbose", action="store_true",
help="Print the names of settings modified")
help="Print the names of settings modified")
parser.add_option("-d", "--debug", action="store_true",
help="Enable debug output")
help="Enable debug output")
options, args = parser.parse_args()
try:
from gtweak.defs import GSETTINGS_SCHEMA_DIR, TWEAK_DIR, DATA_DIR, PKG_DATA_DIR, LOCALE_DIR, LIBEXEC_DIR
from gtweak.defs import GSETTINGS_SCHEMA_DIR, TWEAK_DIR, DATA_DIR, \
PKG_DATA_DIR, LOCALE_DIR, LIBEXEC_DIR
_defs_present = True
except ImportError:
GSETTINGS_SCHEMA_DIR = TWEAK_DIR = DATA_DIR = PKG_DATA_DIR = LOCALE_DIR = LIBEXEC_DIR = ""
GSETTINGS_SCHEMA_DIR = TWEAK_DIR = DATA_DIR = PKG_DATA_DIR = \
LOCALE_DIR = LIBEXEC_DIR = ""
_defs_present = False
#the supplied prefix always beats the contents of defs
# the supplied prefix always beats the contents of defs
if options.prefix or not _defs_present:
_prefix = options.prefix or "/usr"
DATA_DIR = os.path.join(_prefix, "share")
......@@ -68,9 +71,9 @@ if __name__ == '__main__':
gtweak.VERBOSE = options.verbose
if options.debug:
level=logging.DEBUG
level = logging.DEBUG
else:
level=logging.WARNING
level = logging.WARNING
logging.basicConfig(format="%(levelname)-8s: %(message)s", level=level)
locale.setlocale(locale.LC_ALL, None)
......@@ -80,4 +83,3 @@ if __name__ == '__main__':
app = GnomeTweakTool()
exit_status = app.run(None)
sys.exit(exit_status)
......@@ -29,11 +29,12 @@ from gtweak.utils import SchemaList
from gtweak.gshellwrapper import GnomeShellFactory
from gtweak.utils import DisableExtension
class GnomeTweakTool(Gtk.Application):
def __init__(self):
GLib.set_application_name(_("GNOME Tweak Tool"))
Gtk.Application.__init__(self,application_id="org.gnome.TweakTool")
Gtk.Application.__init__(self, application_id="org.gnome.TweakTool")
self.win = None
def do_activate(self):
......@@ -75,8 +76,8 @@ class GnomeTweakTool(Gtk.Application):
self.add_action(quit_action)
def reset_cb(self, action, parameter):
dialog = Gtk.MessageDialog(self.win,0, Gtk.MessageType.QUESTION,
Gtk.ButtonsType.OK_CANCEL, _("Reset to Defaults"))
dialog = Gtk.MessageDialog(self.win, 0, Gtk.MessageType.QUESTION,
Gtk.ButtonsType.OK_CANCEL, _("Reset to Defaults"))
dialog.format_secondary_text(_("Reset all tweak settings to the original default state?"))
response = dialog.run()
if response == Gtk.ResponseType.OK:
......@@ -100,11 +101,13 @@ class GnomeTweakTool(Gtk.Application):
if _shell.mode == "user":
about_comment = _("GNOME Shell") + " %s" % _shell.version
else:
about_comment = (_("GNOME Shell") + " %s " + _("(%s mode)")) % (_shell.version, _shell.mode)
about_comment = (_("GNOME Shell") + " %s " + _("(%s mode)")) % \
(_shell.version, _shell.mode)
else:
about_comment = _("GNOME Shell is not running")
about_comment += "\n" + _("GTK+") + " %d.%d.%d" % (Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version())
about_comment += "\n" + _("GTK+") + " %d.%d.%d" % \
(Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version())
aboutdialog.set_comments(about_comment)
aboutdialog.set_copyright("Copyright \xc2\xa9 2011 - 2013 John Stowers.")
......@@ -123,4 +126,3 @@ class GnomeTweakTool(Gtk.Application):
def quit_cb(self, action, parameter):
self.quit()
......@@ -23,13 +23,14 @@ gi.require_version("Soup", "2.4")
from gi.repository import GObject
from gi.repository import Soup
class ExtensionsDotGnomeDotOrg(GObject.GObject):
__gsignals__ = {
"got-extensions": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE,
(GObject.TYPE_PYOBJECT,)),
(GObject.TYPE_PYOBJECT,)),
"got-extension-info": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE,
(GObject.TYPE_PYOBJECT,GObject.TYPE_STRING)),
(GObject.TYPE_PYOBJECT, GObject.TYPE_STRING)),
}
def __init__(self, shell_version_tuple):
......@@ -41,7 +42,7 @@ class ExtensionsDotGnomeDotOrg(GObject.GObject):
def _query_extensions_finished(self, msg, url):
if msg.status_code == 200:
#server returns a list of extensions which may contain duplicates, dont know
# server returns a list of extensions which may contain duplicates, dont know
resp = json.loads(msg.response_body.data)
print(resp)
for e in resp["extensions"]:
......@@ -57,15 +58,15 @@ class ExtensionsDotGnomeDotOrg(GObject.GObject):
ver = self._shell_version_tuple
if ver[1] % 2:
#if this is a development version (odd) then query the full version
# if this is a development version (odd) then query the full version
url += "shell_version=%d.%d.%d&" % ver
else:
#else query in point releases up to the current version, and filter duplicates
#from the reply
url += "shell_version=%d.%d&" % (ver[0],ver[1])
for i in range(1,ver[2]+1):
url += "shell_version=%d.%d.%d&" % (ver[0],ver[1], i)
#non-paginated
# else query in point releases up to the current version
# and filter duplicates from the reply
url += "shell_version=%d.%d&" % (ver[0], ver[1])
for i in range(1, ver[2]+1):
url += "shell_version=%d.%d.%d&" % (ver[0], ver[1], i)
# non-paginated
url += "n_per_page=-1"
logging.debug("Query URL: %s" % url)
......@@ -87,8 +88,8 @@ class ExtensionsDotGnomeDotOrg(GObject.GObject):
def get_download_url(self, extinfo):
url = "https://extensions.gnome.org/download-extension/%s.shell-extension.zip?version_tag=%d"
#version tag is the pk in the shell_version_map
#url = url % (extinfo["uuid"],
# version tag is the pk in the shell_version_map
# url = url % (extinfo["uuid"],
if __name__ == "__main__":
......@@ -104,14 +105,14 @@ if __name__ == "__main__":
logging.basicConfig(format="%(levelname)-8s: %(message)s", level=logging.DEBUG)
e = ExtensionsDotGnomeDotOrg((3,4,1))
e = ExtensionsDotGnomeDotOrg((3, 4, 1))
e.connect("got-extensions", _got_ext)
e.connect("got-extension-info", _got_ext_info)
e.query_extensions()
#e.query_extensions((3,4,0))
#e.query_extensions((3,3,2))
# e.query_extensions((3, 4, 0))
# e.query_extensions((3, 3, 2))
e.query_extension_info("user-theme@gnome-shell-extensions.gcampax.github.com")
Gtk.main()
......@@ -28,9 +28,11 @@ _SCHEMA_CACHE = {}
_GSETTINGS_SCHEMAS = set(Gio.Settings.list_schemas())
_GSETTINGS_RELOCATABLE_SCHEMAS = set(Gio.Settings.list_relocatable_schemas())
class GSettingsMissingError(Exception):
pass
class _GSettingsSchema:
def __init__(self, schema_name, schema_dir=None, schema_filename=None, **options):
if not schema_dir:
......@@ -72,19 +74,20 @@ class _GSettingsSchema:
if schema_name == schema.getAttribute("id"):
for key in schema.getElementsByTagName("key"):
name = key.getAttribute("name")
#summary is 'compulsory', description is optional
#... in theory, but we should not barf on bad schemas ever
# summary is 'compulsory', description is optional
#in theory, but we should not barf on bad schemas ever
try:
summary = key.getElementsByTagName("summary")[0].childNodes[0].data
except:
summary = ""
logging.info("Schema missing summary %s (key %s)" % (os.path.basename(schema_path),name))
logging.info("Schema missing summary %s (key %s)" %
(os.path.basename(schema_path), name))
try:
description = key.getElementsByTagName("description")[0].childNodes[0].data
except:
description = ""
#if missing translations, use the untranslated values
# if missing translations, use the untranslated values
self._schema[name] = dict(
summary=translation.gettext(summary) if translation else summary,
description=translation.gettext(description) if translation else description
......@@ -96,6 +99,7 @@ class _GSettingsSchema:
def __repr__(self):
return "<gtweak.gsettings._GSettingsSchema: %s>" % self._schema_name
class GSettingsFakeSetting:
def __init__(self):
pass
......@@ -111,6 +115,7 @@ class GSettingsFakeSetting:
pass
return noop
class GSettingsSetting(Gio.Settings):
def __init__(self, schema_name, schema_dir=None, schema_path=None, **options):
......@@ -181,7 +186,7 @@ class GSettingsSetting(Gio.Settings):
self[key] = vals
return True
except ValueError:
#not present
# not present
pass
def setting_is_in_list(self, key, value):
......
......@@ -25,6 +25,7 @@ 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)
......@@ -36,7 +37,7 @@ class _ShellProxy:
'org.gnome.Shell',
None)
#GNOME Shell > 3.5 added a separate extension interface
# GNOME Shell > 3.5 added a separate extension interface
self.proxy_extensions = Gio.DBusProxy.new_sync(
d, 0, None,
'org.gnome.Shell',
......@@ -44,7 +45,7 @@ class _ShellProxy:
'org.gnome.Shell.Extensions',
None)
#GNOME Shell > 3.7.2 added the Mode to the DBus API
# 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()
......@@ -57,7 +58,7 @@ class _ShellProxy:
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
# 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()
......@@ -78,6 +79,7 @@ class _ShellProxy:
def version(self):
return self._version
class GnomeShell:
EXTENSION_STATE = {
......@@ -155,6 +157,7 @@ class GnomeShell34(GnomeShell32):
def uninstall_extension(self, uuid):
return self._proxy.proxy.UninstallExtension('(s)', uuid)
class GnomeShell36(GnomeShell34):
def list_extensions(self):
......@@ -164,7 +167,9 @@ class GnomeShell36(GnomeShell34):
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)
self._proxy.proxy_extensions.InstallRemoteExtension('(s)', uuid,
result_handler=reply_handler, error_handler=error_handler, user_data=user_data)
@gtweak.utils.singleton
class GnomeShellFactory:
......@@ -172,14 +177,15 @@ class GnomeShellFactory:
try:
proxy = _ShellProxy()
settings = GSettingsSetting("org.gnome.shell")
v = list(map(int,proxy.version.split(".")))
v = list(map(int, proxy.version.split(".")))
if v >= [3,5,0]:
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
......
......@@ -23,6 +23,7 @@ import gtweak
from gtweak.tweakmodel import TweakModel
from gtweak.tweakview import TweakView
class MainWindow:
def __init__(self):
builder = Gtk.Builder()
......@@ -39,4 +40,3 @@ class MainWindow:
builder.get_object('overview_sw').add(view.treeview)
view.run()
......@@ -154,4 +154,3 @@ class TweakModel(Gtk.ListStore):
def get_tweakgroup_iter(self, name):
return self._tweak_group_iters[name]
......@@ -14,4 +14,3 @@
#
# 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/>.
......@@ -212,7 +212,7 @@ class _StartupTweak(Gtk.ListBoxRow, Tweak):
df.get_name(),
df.get_description(),
**options)
grid = Gtk.Grid(column_spacing=10)
icn = df.get_icon()
......
......@@ -349,4 +349,3 @@ class LogoutNotification:
'org.gnome.SessionManager',
None)
proxy.Logout('(u)', 0)
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