From 2ced1e49f93096d70907b2ddea22839ee6dd218b Mon Sep 17 00:00:00 2001 From: Zsolt Foldvari Date: Fri, 5 Oct 2007 15:04:27 +0000 Subject: [PATCH] Create custom cell renderer for image labels in GalleryTab for better control. svn: r9085 --- ChangeLog | 4 ++++ src/DisplayTabs/_GalleryTab.py | 36 ++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 39dd04967..78c6ec8e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-10-05 Zsolt Foldvari + * src/DisplayTabs/_GalleryTab.py (build_interface): Create custom cell + renderer for better control. + 2007-07-23 Johan Gonqvist * src/plugins/Calendar.py: first day of calendar is an option. diff --git a/src/DisplayTabs/_GalleryTab.py b/src/DisplayTabs/_GalleryTab.py index ef65ca04c..e31383515 100644 --- a/src/DisplayTabs/_GalleryTab.py +++ b/src/DisplayTabs/_GalleryTab.py @@ -35,6 +35,7 @@ import urlparse # #------------------------------------------------------------------------- import gtk +import pango import os #------------------------------------------------------------------------- @@ -145,27 +146,46 @@ class GalleryTab(ButtonTab): self.iconmodel.connect_after('row-deleted', self._update_internal_list) def build_interface(self): - + """Setup the GUI. + + It includes an IconView placed inside of a ScrolledWindow. + + """ + item_width = 125 + + # create the model used with the icon view self._build_icon_model() + # build the icon view self.iconlist = gtk.IconView() self.iconlist.set_pixbuf_column(0) - self.iconlist.set_text_column(1) + # set custom text cell renderer for better control + text_renderer = gtk.CellRendererText() + text_renderer.set_property('xalign', 0.5) + text_renderer.set_property('yalign', 0.0) + text_renderer.set_property('wrap-mode', pango.WRAP_WORD_CHAR) + text_renderer.set_property('wrap-width', item_width) + text_renderer.set_property('alignment', pango.ALIGN_CENTER) + self.iconlist.pack_end(text_renderer) + self.iconlist.set_attributes(text_renderer, text=1) + + # set basic properties of the icon view self.iconlist.set_margin(12) - try: - # This is only available for pygtk 2.8 - self.iconlist.set_reorderable(True) - except AttributeError: - pass - self.iconlist.set_item_width(125) self.iconlist.set_spacing(24) + self.iconlist.set_reorderable(True) + self.iconlist.set_item_width(item_width) self.iconlist.set_selection_mode(gtk.SELECTION_SINGLE) + + # connect the signals self.iconlist.connect('selection-changed', self._selection_changed) self.iconlist.connect('button_press_event', self.double_click) self._connect_icon_model() + # create the scrolled window scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + + # put everything together scroll.add(self.iconlist) self.pack_start(scroll, True)