# -*- coding: UTF-8 -*- # # Copyright (c) 2004 Franz Klammer # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # import os import gconf from div_data import * import thread import time #TODO: only gobject if gtk2.6 is gone... try: from gobject import timeout_add except: from gtk import timeout_add class gconf_lib: def __init__(self): self.__my_conf_path = "/apps/"+GNOME_APP_ID self.__gconf_client = gconf.client_get_default() self.__splash_dir_default = "/usr/local/share/pixmaps/splash/" self.__splash_dir_default = "/usr/local/share/pixmaps/splashsetter/splash/" self.__splash_cb_sysdir_state = True self.__gconf_session_key_path = "/apps/gnome-session/options/splash_image" self.__gconf_client.add_dir(self.__my_conf_path, gconf.CLIENT_PRELOAD_NONE) self.__pre_configure() # there must be an better solution, or? def __pre_configure(self): entries_set = self.__gconf_client.all_entries(self.__my_conf_path) entries = [] for e in entries_set: entries.append(os.path.basename(e.get_key())) if not ("splash_dir" in entries): self.set_splash_dir(self.__splash_dir_default) if not ("use_sysdir" in entries): self.set_cb_sysdir_state(True) def get_splash_dir(self): return self.__gconf_client.get_string(self.__my_conf_path+"/splash_dir") #return self.get_config("string", "splash_dir", self.__splash_dir_default) def get_current_splash_screen(self): return self.__gconf_client.get_string("/apps/gnome-session/options/splash_image") def get_cb_sysdir_state(self): return self.__gconf_client.get_bool(self.__my_conf_path+"/use_sysdir") def set_cb_sysdir_state(self, new_state): return self.__gconf_client.set_bool(self.__my_conf_path+"/use_sysdir", new_state) def set_splash_image(self, new_splash_image): self.__gconf_client.set_string(self.__gconf_session_key_path, new_splash_image) def set_splash_dir(self, key_value): self.__gconf_client.set_string(self.__my_conf_path+"/splash_dir", key_value) def get_string(self, gconf_key): return self.__gconf_client.get_string(gconf_key) def get_config(self, key_type, key_name, default_value = "__nodefault__"): if key_type == "string": c_keyval = self.__gconf_client.get_string(self.__my_conf_path+"/"+key_name) if not c_keyval: self.__gconf_client.set_string(self.__my_conf_path+"/"+key_name, default_value) c_keyval = default_value return c_keyval class splash_set_app: def __init__(self): # init variables self.active_splash = "" # init4info self.__original_splash = "" # load_config self.__splash_system_dir = "/usr/local/share/pixmaps/splash/" self.__search_in_system_dir = True self.__splash_home_dir = "~/.splash/" self.splash_screen_list = [] self.allow_set_splash_now = False self.__config = gconf_lib() def __gnome_session_needs_a_gui_workaround(self): def stop_workaround(): gtk.main_quit() try: import gtk wwin = gtk.Window() wwin.set_decorated(False) wwin.set_size_request(1,1) wwin.show() timeout_add(2000, stop_workaround) gtk.main() except: pass def set_random_splash(self): import random self.load_config() splash_screen_list = self.get_splash_screens() screens_avail = len(splash_screen_list)-1 if (screens_avail > 0): new_number = random.randint(0, screens_avail) if (screens_avail == 1): if (splash_screen_list[new_number] == self.__original_splash): new_number = int(not new_number) else: while self.__original_splash == splash_screen_list[new_number]: new_number = random.randint(0, screens_avail) self.active_splash = splash_screen_list[new_number] self.set_splash() else: print "There is only one splash screen available!" self.__gnome_session_needs_a_gui_workaround() def load_config(self): self.__search_in_system_dir = self.__config.get_cb_sysdir_state() self.__splash_search_dir = self.__config.get_splash_dir() if self.__splash_search_dir[-1:] != "/": self.__splash_search_dir += "/" if not self.__original_splash: self.__original_splash = self.__config.get_current_splash_screen() self.active_splash = self.__original_splash def get_original_splash(self): return self.__original_splash def get_splash_screens(self): splashlist = [] if self.__search_in_system_dir: splashlist = self.__load_splash_file_list(self.__splash_system_dir, splashlist) if os.path.isdir(self.__splash_search_dir) and (self.__splash_search_dir != self.__splash_system_dir): splashlist = self.__load_splash_file_list(self.__splash_search_dir, splashlist) if os.path.isdir(self.__splash_home_dir): splashlist = self.__load_splash_file_list(self.__splash_home_dir, splashlist) return splashlist def set_splash(self): print "new splash:",self.active_splash self.__config.set_splash_image(self.active_splash) def __load_splash_file_list(self, path, splashlist): os.chdir(path) dirlist = os.listdir(".") for valid_file in dirlist: if os.path.isfile(valid_file): try: if valid_file.split(".").pop() == "png": splashlist.append(path+valid_file) except: pass return splashlist