From 2710dffb1772dbbf608e940c8532b1d9f12c6595 Mon Sep 17 00:00:00 2001 From: Stephen Watson Date: Tue, 9 May 2006 18:49:33 +0000 Subject: [PATCH] rox.settings now uses rox.session to communicate with ROX-Session and the duplicate Options work has been removed from rox.session (Stephen Watson). git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/ROX-Lib2@4570 66de3db3-b00d-0410-b41b-f4738ad19bea --- python/rox/session.py | 38 +------------------------------- python/rox/settings.py | 60 ++++++++++---------------------------------------- 2 files changed, 13 insertions(+), 85 deletions(-) diff --git a/python/rox/session.py b/python/rox/session.py index 5b1316b..f9f184e 100644 --- a/python/rox/session.py +++ b/python/rox/session.py @@ -19,7 +19,7 @@ import rox from rox.options import OptionGroup, Option from rox import OptionsBox, g import rox.xxmlrpc -import gobject +# import gobject try: import dbus @@ -109,42 +109,6 @@ def running(): return session_service in services -class Setting(Option): - """A Setting is an Option whose value is communicated with ROX-Session - instead of being stored in the program's options.""" - - def __init__(self, name, default, group=None): - """Initialize the option. Unlike the normal Option the value - is available immediatley (provided ROX-Session is running).""" - Option.__init__(self, name, default, group) - self.store = False # Do not let OptionGroup this write to file - - self.is_string = isinstance(default, basestring) - self.proxy = get_settings() - try: - type, value = self.proxy.GetSetting(name) - except: - self._set(default) - else: - self._set(value, notify = False) - - def _set(self, value, notify = True): - Option._set(self, value) - if not notify: return - - def set(obj, value): - # Changing the theme will make GTK try to rebuild all - # its top-levels. Included destroyed ones that Python's - # GC holds a reference to still. Drop them now... - import gc; gc.collect() - if obj.is_string: - obj.proxy.SetString(obj.name, value) - else: - obj.proxy.SetInt(obj.name, obj.int_value) - - gobject.idle_add(set, self, value) - - # Test routine if __name__=='__main__': print 'Session running? %s' % running() diff --git a/python/rox/settings.py b/python/rox/settings.py index 1273879..c5406b5 100644 --- a/python/rox/settings.py +++ b/python/rox/settings.py @@ -10,6 +10,7 @@ import os import rox from rox.options import OptionGroup, Option from rox import OptionsBox +import rox.session import gobject gconf = None @@ -19,57 +20,11 @@ _warned_connect = False _warned_norox = False def get_xsettings(): - """Returns ROX-Session's Settings dbus interface. + """Returns ROX-Session's Settings dbus/xxmlrpc interface. Called automatically if and when necessary """ - global _warned_import - global _warned_connect - global _warned_norox - try: - import dbus - except ImportError: - if not _warned_import: - rox.alert("Failed to import dbus module. You probably need " - "to install a package with a name like 'python2.3-dbus'" - "or 'python2.4-dbus'.\n" - "D-BUS can also be downloaded from http://freedesktop.org.") - _warned_import = True - return None - - try: - if (hasattr(dbus, 'SessionBus')): - bus = dbus.SessionBus() - else: - bus = dbus.Bus(dbus.Bus.TYPE_SESSION) - except: - if not _warned_connect: - rox.alert('Failed to connect to D-BUS session bus. This probably ' - "means that you're running an old version of ROX-Session " - '(or not using ROX-Session at all). Settings cannot be set ' - "using this program until a newer version of ROX-Session is " - "running.") - _warned_connect = True - return None - - try: - if hasattr(bus, 'get_service'): - rox_session = bus.get_service('net.sf.rox.Session') - rox_settings = rox_session.get_object('/Settings', - 'net.sf.rox.Session.Settings') - else: - rox_settings = dbus.Interface(bus.get_object('net.sf.rox.Session', - '/Settings'), - 'net.sf.rox.Session.Settings') - except: - if not _warned_norox: - rox.alert("ROX-Session doesn't appear to be running (or " - "you are running an old version). Changing many of " - "these settings will have no effect.") - _warned_norox = True - return None - - return rox_settings + return rox.session.get_settings() def get_gconf(): """Get GConf connection. @@ -225,3 +180,12 @@ class BoolSetting(Setting): Setting.__init__(self, name, default, settings, theme, gconf_key) def make_gconf_value(self): return self.int_value != 0 + +# Test routine +if __name__=='__main__': + setobj=get_xsettings() + print 'object=', setobj + v='Gtk/KeyThemeName' + print '%s = %s' % (v, setobj.GetSetting(v)) + v='Net/ThemeName' + print '%s = %s' % (v, setobj.GetSetting(v)) -- 2.11.4.GIT