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.py38
1 files changed, 25 insertions, 13 deletions
diff --git a/stock.py b/stock.py
index 4f3b213..8e281c9 100644
--- a/stock.py
+++ b/stock.py
@@ -1,7 +1,4 @@
-#!/usr/bin/env python
-# -*- 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
@@ -24,14 +21,10 @@ import gtk
icon_factory = gtk.IconFactory()
+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)
@@ -40,6 +33,12 @@ def register(name, label, accelerator, icon_name):
icon_factory.add(name, icon)
icon_factory.add_default()
+ 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):
info = list(gtk.stock_lookup(stock_id))
@@ -64,12 +63,25 @@ overwrite_stock(gtk.STOCK_REMOVE, '<Shift>Delete')
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}