[kupfer: 7/10] ui: Use GTK icon sizes 'kupfer-large' and 'kupfer-small'
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer: 7/10] ui: Use GTK icon sizes 'kupfer-large' and 'kupfer-small'
- Date: Thu, 31 Mar 2011 16:50:59 +0000 (UTC)
commit c4326af472c06ba9ee6fbc02bd6c57010658e541
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Thu Mar 31 18:49:22 2011 +0200
ui: Use GTK icon sizes 'kupfer-large' and 'kupfer-small'
Register our icons sizes with GTK and provide default values. This
also allows themes to override the sizes.
kupfer/icons.py | 10 ++++++++--
kupfer/ui/browser.py | 23 +++++++++++++++++------
2 files changed, 25 insertions(+), 8 deletions(-)
---
diff --git a/kupfer/icons.py b/kupfer/icons.py
index 5f5d4f2..9d20eac 100644
--- a/kupfer/icons.py
+++ b/kupfer/icons.py
@@ -11,6 +11,12 @@ from kupfer import config, pretty, scheduler
icon_cache = {}
+LARGE_SZ = 128
+SMALL_SZ = 24
+
+gtk.icon_size_register("kupfer-large", LARGE_SZ, LARGE_SZ)
+gtk.icon_size_register("kupfer-small", SMALL_SZ, SMALL_SZ)
+
def _icon_theme_changed(theme):
pretty.print_info(__name__, "Icon theme changed, clearing cache")
global icon_cache
@@ -44,7 +50,7 @@ scheduler.GetScheduler().connect("after-display", load_kupfer_icons)
def load_plugin_icon(plugin_name, icon_name, icon_data):
"Load icon from @icon_data into the name @icon_name"
- for size in (24, 128):
+ for size in (SMALL_SZ, LARGE_SZ):
pixbuf = get_pixbuf_from_data(icon_data, size, size)
gtk.icon_theme_add_builtin_icon(icon_name, size, pixbuf)
pretty.print_debug(__name__, "Loading icon", icon_name, "at", size,
@@ -128,7 +134,7 @@ class ComposedIcon (Icon):
def ComposedIconSmall(baseicon, emblem, **kwargs):
"""Create composed icon for leaves with emblem visible on browser list"""
ci = ComposedIcon(baseicon, emblem, **kwargs)
- ci.minimum_icon_size = 24
+ ci.minimum_icon_size = SMALL_SZ
return ci
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index 9c414c7..d1c278d 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -233,10 +233,12 @@ class LeafModel (object):
self.store.prepend(self._get_row(rankable))
def get_icon_size(self):
- return 24
+ return gtk.icon_size_lookup(gtk.icon_size_from_name("kupfer-small"))[0]
+
def get_icon(self, leaf):
sz = self.get_icon_size()
- return leaf.get_thumbnail(sz, sz) or leaf.get_pixbuf(sz)
+ if sz >= 8:
+ return leaf.get_thumbnail(sz, sz) or leaf.get_pixbuf(sz)
def get_label_markup(self, rankable):
leaf = rankable.object
@@ -278,13 +280,12 @@ class MatchView (gtk.Bin):
"""
__gtype_name__ = "MatchView"
- def __init__(self, icon_size):
+ def __init__(self):
gobject.GObject.__init__(self)
# object attributes
self.label_char_width = 25
self.preedit_char_width = 5
self.match_state = State.Wait
- self.icon_size = icon_size
self.object_stack = []
@@ -296,6 +297,10 @@ class MatchView (gtk.Bin):
self.cur_text = None
self.cur_match = None
+ @property
+ def icon_size(self):
+ return gtk.icon_size_lookup(gtk.icon_size_from_name("kupfer-large"))[0]
+
def _update_theme(self, *args):
# Style subtables to choose from
# fg, bg, text, base
@@ -560,19 +565,25 @@ class Search (gtk.Bin):
# number rows to skip when press PgUp/PgDown
self.page_step = 7
self.source = None
- self.icon_size = 128
self._old_win_position=None
self._has_search_result = False
self._initialized = False
# finally build widget
self.build_widget()
+ self.icon_size = None
+ self.on_style_set()
self.setup_empty()
+ self.connect("style-set", self.on_style_set)
+
+ def on_style_set(self, *args):
+ self.icon_size = \
+ gtk.icon_size_lookup(gtk.icon_size_from_name("kupfer-large"))[0]
def build_widget(self):
"""
Core initalization method that builds the widget
"""
- self.match_view = MatchView(self.icon_size)
+ self.match_view = MatchView()
self.table = gtk.TreeView(self.model.get_store())
self.table.set_headers_visible(False)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]