Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2007-07-03 15:08:36 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2007-07-03 15:08:36 (GMT)
commit4df052e5de8a37d694a28bbdb7ce7bf5a9281f41 (patch)
treeec1ec36f9bb7b06b8593adbb16bb9d048bd3c1d3 /sugar
parent13885e621b689eec1baab16ccc81384f0790ad3e (diff)
Return None when no element is active and use theme: for marking icons from the theme.
Diffstat (limited to 'sugar')
-rw-r--r--sugar/graphics/combobox.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/sugar/graphics/combobox.py b/sugar/graphics/combobox.py
index 49fa527..b3a6e5f 100644
--- a/sugar/graphics/combobox.py
+++ b/sugar/graphics/combobox.py
@@ -46,11 +46,23 @@ class ComboBox(gtk.ComboBox):
def do_get_property(self, pspec):
if pspec.name == 'value':
- action_id, text, icon_name, is_separator = self.get_active_item()
- return action_id
+ row = self.get_active_item()
+ if not row:
+ return None
+ return row[0]
else:
return gtk.ComboBox.do_get_property(self, pspec)
+ def _get_real_name_from_theme(self, name):
+ icon_theme = gtk.icon_theme_get_default()
+ width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
+ info = icon_theme.lookup_icon(name, width, height)
+ if not info:
+ raise ValueError("Icon '" + name + "' not found.")
+ fname = info.get_filename()
+ del info
+ return fname
+
def append_item(self, action_id, text, icon_name=None):
if not self._icon_renderer and icon_name:
self._icon_renderer = gtk.CellRendererPixbuf()
@@ -65,11 +77,9 @@ class ComboBox(gtk.ComboBox):
if icon_name:
width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
- if os.path.isfile(icon_name):
- pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_name, width, height)
- else:
- icon_theme = gtk.icon_theme_get_default()
- pixbuf = icon_theme.load_icon(icon_name, width, 0)
+ if icon_name[0:6] == "theme:":
+ icon_name = self._get_real_name_from_theme(icon_name[6:])
+ pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_name, width, height)
else:
pixbuf = None
@@ -84,8 +94,13 @@ class ComboBox(gtk.ComboBox):
index = 0
row = self._model.iter_nth_child(None, index)
+ if not row:
+ return None
return self._model[row]
+ def remove_all(self):
+ self._model.clear()
+
def _is_separator(self, model, row):
action_id, text, icon_name, is_separator = model[row]
return is_separator