def set_background(path): # Note that the path is not unlinked, because gconf and xfconf set bg # asynchronously, so there's no way of knowing when the image will # actually be used if 'gsettings' in conf.bg_set_methods: ## GSettings - newer GNOME, Unity # Using gi.repository.Gio here directly is tricky alongside gimp's gtk2 from subprocess import call from urllib import quote call([ 'gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri', 'file://{0}'.format(quote(path)) ]) if 'gconf' in conf.bg_set_methods: ## Gconf - older GNOME, XFCE/nautilus and such try: import gconf gconf = gconf.client_get_default() gconf.set_string( '/desktop/gnome/background/picture_filename', path ) except ImportError: pass if 'xfconf' in conf.bg_set_methods: ## Xfconf (via dbus interface) - XFCE/xfdesktop try: import dbus except ImportError: pass else: try: xfconf = dbus.Interface( dbus.SessionBus().get_object( 'org.xfce.Xfconf', '/org/xfce/Xfconf' ), dbus_interface='org.xfce.Xfconf' ) for k,v in xfconf.GetAllProperties('xfce4-desktop', '/backdrop').iteritems(): if k.endswith('/image-path'): xfconf.SetProperty('xfce4-desktop', k, path) except dbus.exceptions.DBusException: pass # no property/object/interface/etc if 'enlightenment' in conf.bg_set_methods: ## E17+ edbus interface try: import dbus except ImportError: pass else: try: edbus = dbus.SessionBus().get_object( 'org.enlightenment.wm.service', '/org/enlightenment/wm/RemoteObject' ) dxc, dyc = edbus.GetVirtualCount(dbus_interface='org.enlightenment.wm.Desktop') edbus = dbus.Interface( edbus, dbus_interface='org.enlightenment.wm.Desktop.Background' ) for dx, dy in it.product(xrange(dxc), xrange(dyc)): edbus.Add(0, dx, dy, path) except dbus.exceptions.DBusException: pass # no property/object/interface/etc if 'x-root-window' in conf.bg_set_methods: ## Paint X root window via pygtk pb = gdk.pixbuf_new_from_file(path) pm, mask = pb.render_pixmap_and_mask() win = gdk.get_default_root_window() win.set_back_pixmap(pm, False) win.clear() win.draw_pixbuf(gdk.GC(win), pb, 0, 0, 0, 0, -1, -1)
def __save_preferences(self): logging.debug("state of files: %s" % self.__files) # retrieve from GUI min_length = self.minlength.get_value_as_int() max_length = self.maxlength.get_value_as_int() blank_symbol = self.blanksymbol.get_text() dictionary_file = self.__files["dictionary"] dictionary_command = self.dictionarycommand.get_text() custom_alphabet = self.customalphabet.get_active() custom_alphabet_file = self.__files["alphabet"] dictionary_type = None if self.filedictionary.get_active(): dictionary_type = "file" elif self.aspelldictionary.get_active(): dictionary_type = "command" dict_server = self.dicthost.get_text() dict_port = int_of_string(self.dictport.get_text(), 0, 2628) dict_db = self.__dict_database show_defs = self.showdefinitions.get_active() # debug logging.debug("saved configuration to gconf:") logging.debug(("min_length", min_length)) logging.debug(("max_length", max_length)) logging.debug(("blank_symbol", blank_symbol)) logging.debug(("dictionary_file", dictionary_file)) logging.debug(("dictionary_command", dictionary_command)) logging.debug(("custom_alphabet", custom_alphabet)) logging.debug(("custom_alphabet_file", custom_alphabet_file)) logging.debug(("dictionary_type", dictionary_type)) logging.debug(("dict_server", dict_server)) logging.debug(("dict_port", dict_port)) logging.debug(("dict_db", dict_db)) logging.debug(("show_defs", show_defs)) # save config from os.path import join gconf = self.__gconf gconf.set_int(join(GCONF_GENERAL, "min_length"), min_length) gconf.set_int(join(GCONF_GENERAL, "max_length"), max_length) gconf.set_string(join(GCONF_GENERAL, "blank_symbol"), blank_symbol) gconf.set_string(join(GCONF_GENERAL, "dictionary_file"), dictionary_file) gconf.set_string(join(GCONF_GENERAL, "dictionary_command"), dictionary_command) gconf.set_bool(join(GCONF_GENERAL, "custom_alphabet"), custom_alphabet) gconf.set_string(join(GCONF_GENERAL, "custom_alphabet_file"), custom_alphabet_file) gconf.set_string(join(GCONF_GENERAL, "dictionary_type"), dictionary_type) gconf.set_string(join(GCONF_GENERAL, "dict_host"), dict_server) gconf.set_int(join(GCONF_GENERAL, "dict_port"), dict_port) gconf.set_string(join(GCONF_GENERAL, "dict_db"), dict_db) gconf.set_bool(join(GCONF_GENERAL, "show_definitions"), show_defs)