# -*- 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 pygtk; pygtk.require("2.0") import gtk import gnome.ui import os #TODO: only gobject if gtk2.6 is gone... try: from gobject import timeout_add except: from gtk import timeout_add from div_data import * from splash_set_lib import * ui_string = """ """ class gconf_gui_app: def __init__(self): self.__config = gconf_lib() self.__call_before_closed = None self.__do_call_before_close = False self.__current_splash_dir = self.__config.get_splash_dir() self.__cbox_sysdir_state = self.__config.get_cb_sysdir_state() def dummy(self): pass def show_pref_dialog(self, callback_func = None): if callback_func: self.__call_before_closed = callback_func self.__preferences_dialog() def __close_config_dialog(self, dialog_window, key_value_dirname): self.__config.set_splash_dir(key_value_dirname) # if self.__call_before_closed and key_value_dirname != self.__current_splash_dir: if self.__do_call_before_close: self.__call_before_closed() dialog_window.destroy() def __on_ok_fsel_dialog(self, splashdir_entry, new_dirname): if os.path.isfile(new_dirname) or not os.path.isdir(new_dirname): new_dirname = os.path.dirname(new_dirname) if os.path.isdir(new_dirname): splashdir_entry.set_text(new_dirname) os.chdir(new_dirname) self.__do_call_before_close = True def __on_toggle_pref_sysdir(self, check_button_obj): self.__do_call_before_close = True self.__config.set_cb_sysdir_state(check_button_obj.get_active()) def __do_file_dialog(self, splashdir_entry): fd = gtk.FileChooserDialog("Please choose a folder ...", None, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, # FILE_CHOOSER_ACTION_OPEN (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) fd.set_icon(gtk.gdk.pixbuf_new_from_file(SPLASH_SET_ICON)) response = fd.run() if response == gtk.RESPONSE_OK: selected = fd.get_filename(); self.__on_ok_fsel_dialog(splashdir_entry, selected) fd.destroy() def __preferences_dialog(self): pref_dialog = gtk.Dialog("Splashsetter Preferences", flags=gtk.DIALOG_NO_SEPARATOR) pref_dialog.set_border_width(10) pref_dialog.set_size_request(560, -1) pref_dialog.set_icon(gtk.gdk.pixbuf_new_from_file(SPLASH_SET_ICON)) """ ********** BEGIN frame for session/random options *********** """ sess_vbox = gtk.VBox(False, 0) info_label = gtk.Label("To use the \"Random Splash\" feature please add\n\"splash-set --random\" to \"Startup Programs\"") sess_prev_button = gtk.Button("Start the GNOME Session configuration ...") sess_prev_button.show() sess_prev_button.connect("clicked", lambda sess_prev_button: os.system("/usr/local/bin/gnome-session-properties &")) sess_vbox.pack_start(info_label, False, False, 5) sess_vbox.pack_start(sess_prev_button, False, False, 5) frame_session = gtk.Frame(" Random Splash ") frame_session.add(sess_vbox) """ ********** END frame for session/random options *********** """ """ ********** BEGIN frame for splashdir options *********** """ vbox_splashdir = gtk.VBox(True) hbox_splashdir = gtk.HBox() # second line of vbox ans used for the user set directory # create widgets entry_pref_splashdir = gtk.Entry() button_fselector = gtk.Button(stock=gtk.STOCK_OPEN) button_fselector.connect("clicked", lambda button_fselector_cb: self.__do_file_dialog(entry_pref_splashdir)) cbox_pref_sysdir = gtk.CheckButton("include the default GNOME splash screen directory") cbox_pref_sysdir.set_active(0) cbox_pref_sysdir.connect("toggled", self.__on_toggle_pref_sysdir) # ----- fill / set path_string = self.__config.get_splash_dir() if path_string: entry_pref_splashdir.set_text(path_string) else: entry_pref_splashdir.set_text(self.__splash_dir_default) if self.__config.get_cb_sysdir_state(): cbox_pref_sysdir.set_active(True) # ----- hbox_splashdir.pack_start(entry_pref_splashdir, True, True, 4) hbox_splashdir.pack_start(button_fselector, False, False) vbox_splashdir.pack_start(hbox_splashdir) vbox_splashdir.pack_start(cbox_pref_sysdir) frame_spacer = gtk.Frame() frame_spacer.set_border_width(10) frame_spacer.set_shadow_type(gtk.SHADOW_NONE) frame_spacer.add(vbox_splashdir) frame_splashdir = gtk.Frame(" Load splash screens from directory... ") frame_splashdir.add(frame_spacer) """ ********** END frame for splashdir options *********** """ """ ********** BEGIN action_area-widgets *********** """ close_button = gtk.Button(stock=gtk.STOCK_CLOSE) close_button.connect("clicked", lambda close_button: self.__close_config_dialog(pref_dialog, entry_pref_splashdir.get_text())) """ ********** END action_area-widgets *********** """ """ pack widget above into the dialog """ pref_dialog.vbox.pack_start(frame_session, False, False, 10) pref_dialog.vbox.pack_start(frame_splashdir, False, False, 10) pref_dialog.action_area.pack_start(close_button, True, True, 0) pref_dialog.show_all() class splash_set_gui_app(gnome.ui.App, splash_set_app): def __init__(self): gnome.program_init(GNOME_APP_ID, SCRIPT_VERSION) gnome.ui.App.__init__(self, GNOME_APP_ID, SCRIPT_NAME) splash_set_app.__init__(self) self.__def_thumb_size = 120 #self.set_decorated(False) self.ui = gtk.UIManager() self.ui.add_ui_from_string(ui_string) def run_gui(self): self.set_icon(gtk.gdk.pixbuf_new_from_file(SPLASH_SET_ICON)) self.connect('destroy', gtk.main_quit) self.__create_menubar_toolbar() self.__toolbar.connect("style_changed", self.__toolbar_workaround) self.__statusbar = gtk.Statusbar() self.__statusbar.set_has_resize_grip(True) self.__statusbar.show() self.__scrolledwin = gtk.ScrolledWindow() self.__scrolledwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.__scrolledwin.show() adjustment = gtk.Adjustment() self.__iconlist = gnome.ui.IconList(self.__def_thumb_size+10, adjustment, 0) self.__iconlist.show() self.__iconlist.connect("select_icon", self.__select_handler) self.__scrolledwin.add(self.__iconlist) self.__preview_img = gtk.Image() self.__preview_img.show() # preview area: pv_label = gtk.Label("Currently active splash screen:") pv_label.show() pv_scrolledwin = gtk.ScrolledWindow() pv_scrolledwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) pv_scrolledwin.show() pv_viewport = gtk.Viewport() pv_viewport.set_shadow_type(gtk.SHADOW_NONE) pv_viewport.show() pv_vbox = gtk.VBox() pv_vbox.show() pv_vbox.pack_start(pv_label, False, False, 4) pv_vbox.pack_start(self.__preview_img, False, False) pv_viewport.add(pv_vbox); pv_scrolledwin.add(pv_viewport); # pv_vbox.pack_start(pv_scrolledwin, True, True, 2) self.__hpaned = gtk.HPaned() self.__hpaned.show() self.__hpaned.add1(self.__scrolledwin) self.__hpaned.add2(pv_scrolledwin) #self.set_menus(self.__menubar) #self.set_toolbar(self.__toolbar) self.set_statusbar(self.__statusbar) self.set_contents(self.__hpaned) self.__build_iconlist() self.__hpaned.set_position((self.__def_thumb_size*2)+50) # set_icon_width_or_so --> self.__iconlist = gnome.ui.IconList(self.__def_thumb_size+10, adjustment, 0) self.set_default_size((self.__def_thumb_size*2)+500,460) self.show() gtk.main() # yery dirty but i hope this can be removed in the future ... def __toolbar_workaround(self, x1 = None, x2 = None): if self.__toolbar.get_style() == 2: # 2 is text below icons but is also set if "both-horiz" == 3 should be. config = gconf_lib() tc_or = config.get_string("/desktop/gnome/interface/toolbar_style") if (tc_or == "both-horiz"): self.__toolbar.set_style(gtk.TOOLBAR_BOTH_HORIZ) def __create_menubar_toolbar(self): ag = gtk.ActionGroup('WindowActions') my_actions = [ ('FileMenu', None, '_File'), ( "a_Quit", gtk.STOCK_QUIT, '_Quit', 'Q', 'Quit application', gtk.main_quit ), ('EditMenu', None, '_Edit'), ( "a_Undo", gtk.STOCK_UNDO, '_Undo', 'Z', None, self.__revert_to_current_splash), ( "a_Preferences", gtk.STOCK_PREFERENCES, 'Prefere_nces', None, None, self.__show_preferences), ('ViewMenu', None, '_View'), ( "a_Refresh", gtk.STOCK_REFRESH, '_Refresh', 'R', 'Refresh', self.__build_iconlist ), ('HelpMenu', None, '_Help'), ( "a_About", gtk.STOCK_ABOUT, '_About', None, None, self.__show_about ) ] ag.add_actions(my_actions) self.ui.insert_action_group(ag, 0) self.add_accel_group(self.ui.get_accel_group()) self.__menu = self.ui.get_widget('/Menubar') self.set_menus(self.__menu) self.__toolbar = self.ui.get_widget('/Toolbar') self.set_toolbar(self.__toolbar) def __build_iconlist(self, gtk_action_obj=None): self.load_config() self.__iconlist.clear() self.__iconlist.set_icon_width(self.__def_thumb_size+10); self.splash_screen_list = self.get_splash_screens() if self.splash_screen_list != []: __index = 0 for splash_screen in self.splash_screen_list: thumbnail = gtk.gdk.pixbuf_new_from_file(splash_screen) thumbnail = thumbnail.scale_simple(self.__def_thumb_size, self.__def_thumb_size, gtk.gdk.INTERP_BILINEAR) icon_name = os.path.basename(splash_screen) self.__iconlist.append_pixbuf(thumbnail, icon_name, icon_name) found_idx = self.__iconlist.find_icon_from_filename(os.path.basename(self.active_splash)) self.allow_set_splash_now = False if (found_idx >= 0): self.__iconlist.select_icon(found_idx) self.__preview_img.set_from_file(self.active_splash) self.allow_set_splash_now = True def __select_handler(self, iconlist_obj, icon_idx, gdk_event_object): self.active_splash = self.splash_screen_list[icon_idx] if self.allow_set_splash_now: self.set_splash() else: self.allow_set_splash_now = True __context_id = self.__statusbar.get_context_id("Mouseover Image") __cur_status_id = self.__statusbar.push(__context_id, self.active_splash + " activated") self.__preview_img.set_from_file(self.active_splash) def __revert_to_current_splash(self, gtk_action_obj): self.allow_set_splash_now = True found_idx = self.__iconlist.find_icon_from_filename(os.path.basename(self.get_original_splash())) if (found_idx >= 0): self.__iconlist.select_icon(found_idx) else: self.active_splash = self.get_original_splash() self.__preview_img.set_from_file(self.get_original_splash()) self.set_splash() def __show_about(self, gtk_action_obj): pixbuf = gtk.gdk.pixbuf_new_from_file(SPLASH_SET_ABOUT_PIX) gnome_about = gnome.ui.About(SCRIPT_NAME, SCRIPT_VERSION, SCRIPT_COPYRIGHT, SCRIPT_DESCR, SCRIPT_AUTHORS, SCRIPT_DOCU, SCRIPT_TRANS, pixbuf) gnome_about.set_icon(gtk.gdk.pixbuf_new_from_file(SPLASH_SET_ICON)) gnome_about.show() def __config_callback(self): timeout_add(100, self.__build_iconlist) def __show_preferences(self, gtk_action_obj): config_gui = gconf_gui_app() config_gui.show_pref_dialog(self.__config_callback)