def _select_icon(self, type): filesel = gtk.FileChooserDialog( "Select applet icon:", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_APPLY, gtk.RESPONSE_OK), None) filesel.set_default_response(gtk.RESPONSE_OK) img_filter = gtk.FileFilter() img_filter.set_name(_("Supported image types")) img_filter.add_pixbuf_formats() filesel.add_filter(img_filter) if type == "empty": filesel.set_filename(self.config['icon_empty']) else: filesel.set_filename(self.config['icon_full']) if filesel.run() == gtk.RESPONSE_OK and filesel.get_filename(): image = IconFactory().load_image(filesel.get_filename(), 24) if image != None: if type == "empty": self.config['icon_empty'] = filesel.get_filename() self.widgets['empty_button'].set_image(image) else: self.config['icon_full'] = filesel.get_filename() self.widgets['full_button'].set_image(image) filesel.destroy()
def add(self, vfs_uris, action=None): retval = None for vfs_uri in vfs_uris: uri = vfs_uri.as_uri() path = vfs_uri.as_string() name = uri.get_basename() mime_type = "" pixbuf = None # check for existence: if not uri.query_exists(): continue # check for duplicates duplicate = False iter = self.store.get_iter_first() while iter: store_uri = self.store.get_value(iter, COL_URI) if vfs_uri.equals(store_uri): duplicate = True break iter = self.store.iter_next(iter) if duplicate: continue # check for desktop item if name.endswith(".desktop"): file = vfs.File.for_uri(path) if file is None or not file.exists(): continue entry = fdo.DesktopEntry.for_file (file) name = entry.get_name() icon_name = entry.get_icon() if entry.key_exists("Icon") else "application-x-executable" mime_type = "" type = gio.FILE_TYPE_REGULAR if icon_name: icon_info = gtk.icon_theme_get_default().lookup_icon(icon_name, self.icon_size, 0) icon_uri = icon_info.get_filename() if icon_info else icon_name pixbuf = IconFactory().load_icon(icon_uri, self.icon_size) if pixbuf: pixbuf.add_alpha (True, '\0', '\0', '\0') else: # get file info try: fileinfo = uri.query_info(','.join([ gio.FILE_ATTRIBUTE_STANDARD_TYPE, gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, gio.FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, gio.FILE_ATTRIBUTE_STANDARD_IS_BACKUP])) if fileinfo.get_is_hidden() or fileinfo.get_is_backup(): continue type = fileinfo.get_file_type() mime_type = fileinfo.get_content_type() except: continue # get pixbuf for icon pixbuf = Thumbnailer(path, mime_type).get_icon(self.icon_size) if pixbuf: pixbuf.add_alpha (True, '\0', '\0', '\0') # create monitor try: monitor = Monitor(vfs_uri) monitor.connect("deleted", self._deleted_cb) except: monitor = None # add to store iter = self.store.append([vfs_uri, monitor, type, name, mime_type, pixbuf, None]) if self.store.iter_is_valid(iter): self.emit("item-created", iter) else: print "ERROR in STACK: iter is NOK (stacks_backend.py)" # return pixbuf later? if pixbuf: retval = pixbuf # restructure of dialog needed return (retval is not None)
def add(self, vfs_uris, action=None): retval = None for vfs_uri in vfs_uris: uri = vfs_uri.as_uri() path = vfs_uri.as_string() name = uri.get_basename() mime_type = "" pixbuf = None # check for existence: if not uri.query_exists(): continue # check for duplicates duplicate = False iter = self.store.get_iter_first() while iter: store_uri = self.store.get_value(iter, COL_URI) if vfs_uri.equals(store_uri): duplicate = True break iter = self.store.iter_next(iter) if duplicate: continue # check for desktop item if name.endswith(".desktop"): file = vfs.File.for_uri(path) if file is None or not file.exists(): continue entry = fdo.DesktopEntry.for_file(file) name = entry.get_name() icon_name = entry.get_icon() if entry.key_exists( "Icon") else "application-x-executable" mime_type = "" type = gio.FILE_TYPE_REGULAR if icon_name: icon_info = gtk.icon_theme_get_default().lookup_icon( icon_name, self.icon_size, 0) icon_uri = icon_info.get_filename( ) if icon_info else icon_name pixbuf = IconFactory().load_icon(icon_uri, self.icon_size) if pixbuf: pixbuf.add_alpha(True, '\0', '\0', '\0') else: # get file info try: fileinfo = uri.query_info(','.join([ gio.FILE_ATTRIBUTE_STANDARD_TYPE, gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, gio.FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, gio.FILE_ATTRIBUTE_STANDARD_IS_BACKUP ])) if fileinfo.get_is_hidden() or fileinfo.get_is_backup(): continue type = fileinfo.get_file_type() mime_type = fileinfo.get_content_type() except: continue # get pixbuf for icon pixbuf = Thumbnailer(path, mime_type).get_icon(self.icon_size) if pixbuf: pixbuf.add_alpha(True, '\0', '\0', '\0') # create monitor try: monitor = Monitor(vfs_uri) monitor.connect("deleted", self._deleted_cb) except: monitor = None # add to store iter = self.store.append( [vfs_uri, monitor, type, name, mime_type, pixbuf, None]) if self.store.iter_is_valid(iter): self.emit("item-created", iter) else: print "ERROR in STACK: iter is NOK (stacks_backend.py)" # return pixbuf later? if pixbuf: retval = pixbuf # restructure of dialog needed return (retval is not None)
def applet_set_full_icon(self, pixbuf): size = self.get_size() icon = IconFactory().load_icon(self.config['icon_full'], size) if self.config['composite_icon'] \ and isinstance(icon, gtk.gdk.Pixbuf) \ and isinstance(pixbuf, gtk.gdk.Pixbuf): pixbuf = IconFactory().scale_to_bounded(pixbuf, 0.9 * size) cx = (size-pixbuf.get_width())/2 cy = (size-pixbuf.get_height())/2 trans = gdk.Pixbuf( pixbuf.get_colorspace(), True, pixbuf.get_bits_per_sample(), size, size) trans.fill(0x00000000) pixbuf.composite( trans, cx, cy, pixbuf.get_width(), pixbuf.get_height(), cx, cy, 1, 1, gtk.gdk.INTERP_BILINEAR, 255) icon.composite( trans, 0,0, size, size, 0, 0, 1, 1, gtk.gdk.INTERP_BILINEAR, 255) icon = trans if icon: self.set_icon_pixbuf(icon)
def applet_set_empty_icon(self): icon = IconFactory().load_icon(self.config['icon_empty'], self.get_size()) if icon: self.set_icon_pixbuf(icon)
def __init__(self, applet): GladeWindow.__init__(self) self.applet = applet self.backend_type = applet.backend.get_type() config = get_config_dict(self.applet.client, self.applet.get_uid()) self.config = config preferences = ALL_PREFS if self.backend_type == BACKEND_TYPE_FILE: pass elif self.backend_type == BACKEND_TYPE_FOLDER: pass elif self.backend_type == BACKEND_TYPE_PLUGGER: preferences -= PREF_BACKEND_FOLDER elif self.backend_type == BACKEND_TYPE_TRASHER: preferences -= PREF_BACKEND_FOLDER preferences -= PREF_FILE_OPERATIONS else: print "Stacks Config: Backend type unkown\nCannot continue." return None # PAGE 1 if (preferences & PREF_BACKEND_FOLDER) == 0: page = self.widgets['main_notebook'].page_num(self.widgets['page1']) self.widgets['main_notebook'].remove_page(page) else: file_backend_mode = False folder_backend_mode = False if self.backend_type == BACKEND_TYPE_FILE: file_backend_mode = True elif self.backend_type == BACKEND_TYPE_FOLDER: folder_backend_mode = True self.widgets['file_backend_button'].set_active(file_backend_mode) self.widgets['folder_backend_button'].set_active(folder_backend_mode) self.widgets['location_label'].set_sensitive(folder_backend_mode) self.widgets['folder_location_entry'].set_sensitive(folder_backend_mode) self.widgets['backendselect_button'].set_sensitive(folder_backend_mode) if folder_backend_mode: self.widgets['folder_location_entry'].set_text(config['backend'].as_string()) else: self.widgets['folder_location_entry'].set_text("file://" + os.path.expanduser("~")) # PAGE 2 if (preferences | LAYOUT_PREFS) == 0: page = self.widgets['main_notebook'].page_num(self.widgets['page2']) self.widgets['main_notebook'].remove_page(page) if (preferences & PREF_APPLET_ICON) == 0: self.widgets['icons_label'].set_sensitive(False) self.widgets['icons_hbbox'].set_sensitive(False) else: # get empty icon try: empty_image = IconFactory().load_image(config['icon_empty'], 24) self.widgets['empty_button'].set_image(empty_image) except: pass # get full icon try: full_image = IconFactory().load_image(config['icon_full'], 24) self.widgets['full_button'].set_image(full_image) except: pass if (preferences & PREF_COMPOSITE_ICON) == 0: self.widgets['composite_label'].set_sensitive(False) self.widgets['composite_hbox'].set_sensitive(False) else: # get composite self.widgets['composite_checkb'].set_active(config['composite_icon']) if (preferences & PREF_ICON_SIZE) == 0: self.widgets['iconsize_label'].set_sensitive(False) self.widgets['iconsize_spin'].set_sensitive(False) else: # get icon size self.widgets['iconsize_spin'].set_value(config['icon_size']) if (preferences) == 0: self.widgets['layout_combobox'].set_sensitive(False) else: self.widgets['layout_combobox'].set_active(config['gui_type']-1) if config['gui_type'] == 2: self.widgets['layout_settings_button'].set_sensitive(True) self.widgets['dimension_label'].hide_all() self.widgets['dimension_hbox'].hide_all() else: self.widgets['layout_settings_button'].set_sensitive(False) self.widgets['dimension_label'].show_all() self.widgets['dimension_hbox'].show_all() if (preferences & PREF_DIMENSION) == 0: self.widgets['dimension_label'].set_sensitive(False) self.widgets['dimension_hbox'].set_sensitive(False) else: # get dimension self.widgets['cols_entry'].set_text(str(config['cols'])) self.widgets['rows_entry'].set_text(str(config['rows'])) if (preferences & PREF_TITLE) == 0: self.widgets['title_label'].set_sensitive(False) self.widgets['title_entry'].set_sensitive(False) self.widgets['title_sep'].set_sensitive(False) else: self.widgets['title_entry'].set_text( self.applet.backend.get_title()) if (preferences & PREF_ITEM_COUNT) == 0: self.widgets['count_label'].set_sensitive(False) self.widgets['count_hbox'].set_sensitive(False) else: self.widgets['count_checkbx'].set_active(config['item_count']) # PAGE 3 if (preferences | BEHAVE_PREFS) == 0: page = self.widgets['main_notebook'].page_num(self.widgets['page3']) self.widgets['main_notebook'].remove_page(page) if (preferences & PREF_FILE_OPERATIONS) == 0: self.widgets['operations_label'].set_sensitive(False) self.widgets['operations_info_label'].set_sensitive(False) self.widgets['operations_hbox'].set_sensitive(False) else: # get file oprations actions = config['fileops'] if actions > 0: if (actions & gtk.gdk.ACTION_COPY) == 0: self.widgets['copy_check'].set_active(False) if (actions & gtk.gdk.ACTION_MOVE) == 0: self.widgets['move_check'].set_active(False) if (actions & gtk.gdk.ACTION_LINK) == 0: self.widgets['link_check'].set_active(False) if (preferences & PREF_BROWSING) == 0: self.widgets['browse_enabled'].set_sensitive(False) else: # get browsing self.widgets['browse_enabled'].set_active(config['browsing']) # get close_on_focusout self.widgets['close_on_focusout_enabled'].set_active(config['close_on_focusout']) # get sort methode self.widgets['arange_by_combobox'].set_active(config['sort_methode']-1) # get sort methode self.widgets['sort_direction_combobox'].set_active(config['sort_direction']-1) # get sort folders before files self.widgets['sort_folders_before_files'].set_active(config['sort_folders_before_files'])