Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/stock.py
diff options
context:
space:
mode:
Diffstat (limited to 'stock.py')
-rw-r--r--stock.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/stock.py b/stock.py
index 9ceb998..09f9724 100644
--- a/stock.py
+++ b/stock.py
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org>
+# Copyright (C) 2012-2013 S. Daniel Francis <francis@sugarlabs.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -25,16 +23,10 @@ icon_factory = gtk.IconFactory()
# Set the icon name for the stock items, this is used only in Sugar.
# Associate here every default stock id with an icon name if you need it.
-icons = {gtk.STOCK_ADD: 'list-add'}
+stock_items = {}
def register(name, label, accelerator, icon_name):
- if accelerator == None:
- keyval = 0
- mask = 0
- else:
- keyval, mask = gtk.accelerator_parse(accelerator)
- gtk.stock_add([(name, label, mask, keyval, '')])
if icon_name:
icon_source = gtk.IconSource()
icon_source.set_icon_name(icon_name)
@@ -42,7 +34,11 @@ def register(name, label, accelerator, icon_name):
icon.add_source(icon_source)
icon_factory.add(name, icon)
icon_factory.add_default()
- icons[name] = icon_name
+
+ iconset = gtk.icon_factory_lookup_default(name)
+ stock_items[name] = {'label': label,
+ 'accelerator': accelerator,
+ 'has_icon': iconset or None}
def overwrite_stock(stock_id, new_accelerator):
@@ -67,12 +63,25 @@ overwrite_stock(gtk.STOCK_REMOVE, '<Ctrl>R')
overwrite_stock(gtk.STOCK_SELECT_COLOR, '<Ctrl>L')
-def get_label(stock, underline):
- text = gtk.stock_lookup(stock)[1]
+def get_label(stock, underline=True):
+ text = stock_items[stock]['label']
if underline:
text = text.replace('_', '')
return text
def get_accelerator(stock):
- return gtk.stock_lookup(stock)[2:-1]
+ accelerator = stock_items[stock]['accelerator']
+ return gtk.accelerator_parse(accelerator) if accelerator is not None \
+ else (0, 0)
+
+
+for i in gtk.stock_list_ids():
+ # I am very noisy
+ # logger.debug(i)
+ info = gtk.stock_lookup(i)
+ iconset = gtk.icon_factory_lookup_default(i)
+ if info is not None:
+ stock_items[i] = {'label': info[1],
+ 'accelerator': gtk.accelerator_name(info[3], info[2]),
+ 'has_icon': iconset or None}