[gnome-tweak-tool] Don't crash if gnome-shell is not running/installed



commit 30f0f84d8eeb6452646c11e0e69f30c60bcfe370
Author: John Stowers <john stowers gmail com>
Date:   Wed Mar 27 12:30:12 2013 +0100

    Don't crash if gnome-shell is not running/installed
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696683

 gtweak/gshellwrapper.py                 |   32 +++++++++++++++++-------------
 gtweak/tweakmodel.py                    |    2 +-
 gtweak/tweaks/tweak_shell.py            |   23 ++++++++++-----------
 gtweak/tweaks/tweak_shell_extensions.py |    4 +++
 4 files changed, 34 insertions(+), 27 deletions(-)
---
diff --git a/gtweak/gshellwrapper.py b/gtweak/gshellwrapper.py
index 6999596..d102b34 100644
--- a/gtweak/gshellwrapper.py
+++ b/gtweak/gshellwrapper.py
@@ -167,21 +167,25 @@ class GnomeShell36(GnomeShell34):
 @gtweak.utils.singleton
 class GnomeShellFactory:
     def __init__(self):
-        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
+        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))
+            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
diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py
index 8e73307..1e83982 100644
--- a/gtweak/tweakmodel.py
+++ b/gtweak/tweakmodel.py
@@ -47,7 +47,7 @@ class Tweak:
         self.name = name
         self.description = description
         self.group_name = options.get("group_name",_("Miscellaneous"))
-        self.loaded = True
+        self.loaded = options.get("loaded", True)
         self.widget_sort_hint = None
 
         self._search_cache = None
diff --git a/gtweak/tweaks/tweak_shell.py b/gtweak/tweaks/tweak_shell.py
index 7a6d40d..7de10b0 100644
--- a/gtweak/tweaks/tweak_shell.py
+++ b/gtweak/tweaks/tweak_shell.py
@@ -30,10 +30,12 @@ from gtweak.gshellwrapper import GnomeShellFactory
 from gtweak.tweakmodel import Tweak, TweakGroup, TWEAK_GROUP_THEME, TWEAK_GROUP_SHELL, TWEAK_SORT_LAST
 from gtweak.widgets import FileChooserButton, GSettingsComboTweak, GSettingsComboEnumTweak, 
GSettingsSwitchTweak, build_label_beside_widget, build_horizontal_sizegroup, build_combo_box_text, 
UI_BOX_SPACING
 
+_shell = GnomeShellFactory().get_shell()
+_shell_loaded = _shell is not None
+
 class ShowWindowButtons(GSettingsComboTweak):
     def __init__(self, **options):
-        _shell = GnomeShellFactory().get_shell()
-        if _shell.mode in ['gdm', 'initial-setup', 'user']:
+        if (_shell is not None) and (_shell.mode in ['gdm', 'initial-setup', 'user']):
             schema = "org.gnome.shell.overrides"
             filename = "org.gnome.shell.gschema.xml"
         else:
@@ -48,6 +50,7 @@ class ShowWindowButtons(GSettingsComboTweak):
             (':maximize,close', _("Maximize and Close")),
             (':minimize,maximize,close', _("All"))),
             schema_filename=filename,
+            loaded=_shell_loaded,
             **options)
 
 class ShellThemeTweak(Tweak):
@@ -65,10 +68,7 @@ class ShellThemeTweak(Tweak):
 
         #check the shell is running and the usertheme extension is present
         error = _("Unknown error")
-        try:
-            self._shell = GnomeShellFactory().get_shell()
-        except:
-            self._shell = None
+        self._shell = _shell
 
         if self._shell is None:
             logging.warning("Shell not running", exc_info=True)
@@ -214,8 +214,7 @@ class StaticWorkspaceTweak(Tweak):
     NUM_WORKSPACES_SCHEMA = "org.gnome.desktop.wm.preferences"
     NUM_WORKSPACES_KEY = "num-workspaces"
 
-    _shell = GnomeShellFactory().get_shell()
-    if _shell.mode in ['gdm', 'initial-setup', 'user']:
+    if (_shell is not None) and (_shell.mode in ['gdm', 'initial-setup', 'user']):
         DYNAMIC_SCHEMA = "org.gnome.shell.overrides"
         DYNAMIC_SCHEMA_FILENAME = "org.gnome.shell.gschema.xml"
     else:
@@ -259,7 +258,7 @@ class StaticWorkspaceTweak(Tweak):
 sg = build_horizontal_sizegroup()
 
 TWEAKS = (
-    ShellThemeTweak(group_name=TWEAK_GROUP_THEME),
+    ShellThemeTweak(group_name=TWEAK_GROUP_THEME, loaded=_shell_loaded),
 )
 
 TWEAK_GROUPS = (
@@ -267,13 +266,13 @@ TWEAK_GROUPS = (
             TWEAK_GROUP_SHELL,
             GSettingsSwitchTweak("org.gnome.desktop.interface", "clock-show-date", 
schema_filename="org.gnome.desktop.interface.gschema.xml"),
             GSettingsSwitchTweak("org.gnome.desktop.interface", "clock-show-seconds", 
schema_filename="org.gnome.desktop.interface.gschema.xml"),
-            GSettingsSwitchTweak("org.gnome.shell.calendar", "show-weekdate", 
schema_filename="org.gnome.shell.gschema.xml"),
+            GSettingsSwitchTweak("org.gnome.shell.calendar", "show-weekdate", 
schema_filename="org.gnome.shell.gschema.xml", loaded=_shell_loaded),
             ShowWindowButtons(size_group=sg),
             GSettingsSwitchTweak("org.gnome.settings-daemon.plugins.power", 
"lid-close-suspend-with-external-monitor"),
             GSettingsComboEnumTweak("org.gnome.settings-daemon.plugins.power", "lid-close-battery-action", 
size_group=sg),
             GSettingsComboEnumTweak("org.gnome.settings-daemon.plugins.power", "lid-close-ac-action", 
size_group=sg),
             GSettingsComboEnumTweak("org.gnome.settings-daemon.plugins.power", "button-power", 
size_group=sg),
             GSettingsComboEnumTweak("org.gnome.settings-daemon.plugins.xrandr", "default-monitors-setup", 
size_group=sg),
-            GSettingsSwitchTweak("org.gnome.shell.overrides", "workspaces-only-on-primary", 
schema_filename="org.gnome.shell.gschema.xml"),
-            StaticWorkspaceTweak(size_group=sg)),
+            GSettingsSwitchTweak("org.gnome.shell.overrides", "workspaces-only-on-primary", 
schema_filename="org.gnome.shell.gschema.xml", loaded=_shell_loaded),
+            StaticWorkspaceTweak(size_group=sg, loaded=_shell_loaded)),
 )
diff --git a/gtweak/tweaks/tweak_shell_extensions.py b/gtweak/tweaks/tweak_shell_extensions.py
index fb90923..f4bee16 100644
--- a/gtweak/tweaks/tweak_shell_extensions.py
+++ b/gtweak/tweaks/tweak_shell_extensions.py
@@ -121,6 +121,8 @@ class _ShellExtensionInstallerTweak(Tweak):
         self.widget = build_label_beside_widget(self.name, hb)
         self.widget_for_size_group = hb
 
+        self.loaded = self._shell is not None
+
     def _on_file_set(self, chooser):
         f = chooser.get_filename()
 
@@ -193,6 +195,8 @@ class ShellExtensionTweakGroup(TweakGroup):
         #check the shell is running
         try:
             shell = GnomeShellFactory().get_shell()
+            if shell is None:
+                raise Exception("Shell not running or DBus service not available")
 
             #add the extension installer
             extension_tweaks.append(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]