class AttachmentBrowserPluginWidget(gtk.HBox, WindowSidePaneWidget): '''Wrapper aroung the L{FileBrowserIconView} that adds the buttons for zoom / open folder / etc. ... ''' icon_size = uistate_property('icon_size', DEFAULT_ICON_ZOOM) def __init__(self, extension, opener, preferences): gtk.HBox.__init__(self) self.extension = extension # XXX self.opener = opener self.uistate = extension.uistate self.preferences = preferences use_thumbs = self.preferences.setdefault('use_thumbnails', True) # Hidden setting self.iconview = FileBrowserIconView(opener, self.icon_size, use_thumbs) self.add(ScrolledWindow(self.iconview, shadow=gtk.SHADOW_NONE)) self.buttonbox = gtk.VBox() self.pack_end(self.buttonbox, False) open_folder_button = IconButton(gtk.STOCK_OPEN, relief=False) open_folder_button.connect('clicked', self.on_open_folder) self.buttonbox.pack_start(open_folder_button, False) refresh_button = IconButton(gtk.STOCK_REFRESH, relief=False) refresh_button.connect('clicked', lambda o: self.on_refresh_button()) self.buttonbox.pack_start(refresh_button, False) zoomin = IconButton(gtk.STOCK_ZOOM_IN, relief=False) zoomout = IconButton(gtk.STOCK_ZOOM_OUT, relief=False) zoomin.connect('clicked', lambda o: self.on_zoom_in()) zoomout.connect('clicked', lambda o: self.on_zoom_out()) self.buttonbox.pack_end(zoomout, False) self.buttonbox.pack_end(zoomin, False) self.zoomin_button = zoomin self.zoomout_button = zoomout self.set_icon_size(self.icon_size) self.iconview.connect('folder-changed', lambda o: self.extension._refresh_statusbar()) def embed_closebutton(self, button): if button: self.buttonbox.pack_start(button, False) self.buttonbox.reorder_child(button, 0) else: for widget in self.buttonbox.get_children(): if hasattr(widget, 'window_close_button'): self.buttonbox.remove(widget) return True def on_open_folder(self, o): # Callback for the "open folder" button from zim.fs import Dir self.opener.open_dir(Dir(self.iconview.folder.path)) self.iconview.refresh() def on_refresh_button(self): self.iconview.refresh() self.extension._refresh_statusbar() # XXX def on_zoom_in(self): self.set_icon_size( min((self.icon_size * 2, THUMB_SIZE_LARGE))) # 16 > 32 > 64 > 128 > 256 def on_zoom_out(self): self.set_icon_size( max((self.icon_size / 2, MIN_ICON_ZOOM))) # 16 < 32 < 64 < 128 < 256 def set_icon_size(self, icon_size): self.iconview.set_icon_size(icon_size) self.zoomin_button.set_sensitive(False) self.zoomout_button.set_sensitive(False) self.zoomin_button.set_sensitive(icon_size < THUMB_SIZE_LARGE) self.zoomout_button.set_sensitive(icon_size > MIN_ICON_ZOOM) self.icon_size = icon_size # Do this last - avoid store state after fail
class AttachmentBrowserPluginWidget(Gtk.HBox, WindowSidePaneWidget): '''Wrapper aroung the L{FileBrowserIconView} that adds the buttons for zoom / open folder / etc. ... ''' title = _('Atta_chments') # T: label for attachment browser pane icon_size = uistate_property('icon_size', DEFAULT_ICON_ZOOM) def __init__(self, extension, opener, preferences): GObject.GObject.__init__(self) self.extension = extension # XXX self.opener = opener self.uistate = extension.uistate self.preferences = preferences self._close_button = None self.iconview = FileBrowserIconView(opener, self.icon_size) self.add(ScrolledWindow(self.iconview, shadow=Gtk.ShadowType.NONE)) self.on_preferences_changed() self.preferences.connect('changed', self.on_preferences_changed) self.buttonbox = Gtk.VBox() self.pack_end(self.buttonbox, False, True, 0) open_folder_button = IconButton(Gtk.STOCK_OPEN, relief=False) open_folder_button.connect('clicked', self.on_open_folder) self.buttonbox.pack_start(open_folder_button, False, True, 0) refresh_button = IconButton(Gtk.STOCK_REFRESH, relief=False) refresh_button.connect('clicked', lambda o: self.on_refresh_button()) self.buttonbox.pack_start(refresh_button, False, True, 0) zoomin = IconButton(Gtk.STOCK_ZOOM_IN, relief=False) zoomout = IconButton(Gtk.STOCK_ZOOM_OUT, relief=False) zoomin.connect('clicked', lambda o: self.on_zoom_in()) zoomout.connect('clicked', lambda o: self.on_zoom_out()) self.buttonbox.pack_end(zoomout, False, True, 0) self.buttonbox.pack_end(zoomin, False, True, 0) self.zoomin_button = zoomin self.zoomout_button = zoomout self.set_icon_size(self.icon_size) self.iconview.connect('folder-changed', lambda o: self.update_title()) def on_preferences_changed(self, *a): self.iconview.set_use_thumbnails(self.preferences['use_thumbnails']) self.iconview.set_thumbnail_svg(self.preferences['thumbnail_svg']) def set_folder(self, folder): self.iconview.set_folder(folder) self.update_title() def update_title(self): n = len(self.iconview.get_model()) self.set_title(ngettext('%i Atta_chment', '%i Atta_chments', n) % n) # T: Label for the statusbar, %i is the number of attachments for the current page def set_embeded_closebutton(self, button): if self._close_button: self.buttonbox.remove(self._close_button) if button is not None: self.buttonbox.pack_start(button, False, True, 0) self.buttonbox.reorder_child(button, 0) self._close_button = button return True def on_open_folder(self, o): # Callback for the "open folder" button open_folder_prompt_create(self, self.iconview.folder) self.iconview.refresh() def on_refresh_button(self): self.iconview.refresh() self.update_title() def on_zoom_in(self): self.set_icon_size(min((self.icon_size * 2, THUMB_SIZE_LARGE))) # 16 > 32 > 64 > 128 > 256 def on_zoom_out(self): self.set_icon_size(max( (self.icon_size / 2, MIN_ICON_ZOOM))) # 16 < 32 < 64 < 128 < 256 def set_icon_size(self, icon_size): self.iconview.set_icon_size(icon_size) self.zoomin_button.set_sensitive(False) self.zoomout_button.set_sensitive(False) self.zoomin_button.set_sensitive(icon_size < THUMB_SIZE_LARGE) self.zoomout_button.set_sensitive(icon_size > MIN_ICON_ZOOM) self.icon_size = icon_size # Do this last - avoid store state after fail