diff options
author | Daniel Francis <francis@sugarlabs.org> | 2012-10-03 00:23:16 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2012-10-03 00:23:16 (GMT) |
commit | 5ceda38732c57211d3f38e6cbbd7b8a521a0a9e5 (patch) | |
tree | 7fa653cb7ccc6d8c4fc9c34967f3b5dd66dbd726 /desktop/sweetener/stock.py | |
parent | e1a599bb8508e1a0607e052a2f086289844dee60 (diff) |
Start sugarizing; use Gtk3
Diffstat (limited to 'desktop/sweetener/stock.py')
-rw-r--r-- | desktop/sweetener/stock.py | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/desktop/sweetener/stock.py b/desktop/sweetener/stock.py index 4f3b213..b92666d 100644 --- a/desktop/sweetener/stock.py +++ b/desktop/sweetener/stock.py @@ -20,9 +20,9 @@ import logging logger = logging.getLogger('stock') -import gtk +from gi.repository import Gtk -icon_factory = gtk.IconFactory() +icon_factory = Gtk.IconFactory() def register(name, label, accelerator, icon_name): @@ -30,46 +30,54 @@ def register(name, label, accelerator, icon_name): keyval = 0 mask = 0 else: - keyval, mask = gtk.accelerator_parse(accelerator) - gtk.stock_add([(name, label, mask, keyval, '')]) + keyval, mask = Gtk.accelerator_parse(accelerator) + logger.debug(keyval) + logger.debug(mask) + item = Gtk.StockItem.new() + item.stock_id = name + item.label = label + item.modifier = mask + item.keyval = keyval + Gtk.stock_add([item]) if icon_name: - icon_source = gtk.IconSource() + icon_source = Gtk.IconSource() icon_source.set_icon_name(icon_name) - icon = gtk.IconSet() + icon = Gtk.IconSet() icon.add_source(icon_source) icon_factory.add(name, icon) icon_factory.add_default() def overwrite_stock(stock_id, new_accelerator): - info = list(gtk.stock_lookup(stock_id)) - keyval, mask = gtk.accelerator_parse(new_accelerator) - info[2] = mask - info[3] = keyval + info = Gtk.stock_lookup(stock_id) + keyval, mask = Gtk.accelerator_parse(new_accelerator) + info.modifier = mask + info.keyval = keyval logger.debug(str(info)) - gtk.stock_add([(info[0], info[1], info[2], info[3], info[4])]) + Gtk.stock_add([info]) # Here we overwrite the key accelerators for some stock ids. # Feel free to add here any other stock id if you need it at your activity, # and send us a patch. -overwrite_stock(gtk.STOCK_SAVE_AS, '<Shift><Ctrl>S') -overwrite_stock(gtk.STOCK_ZOOM_IN, '<Ctrl>plus') -overwrite_stock(gtk.STOCK_ZOOM_OUT, '<Ctrl>minus') -overwrite_stock(gtk.STOCK_ZOOM_100, '<Ctrl>0') +overwrite_stock(Gtk.STOCK_SAVE_AS, '<Shift><Ctrl>S') +overwrite_stock(Gtk.STOCK_ZOOM_IN, '<Ctrl>plus') +overwrite_stock(Gtk.STOCK_ZOOM_OUT, '<Ctrl>minus') +overwrite_stock(Gtk.STOCK_ZOOM_100, '<Ctrl>0') # Key accelerator will be F11 on desktops and <Alt>return on Sugar. -overwrite_stock(gtk.STOCK_FULLSCREEN, 'F11') -overwrite_stock(gtk.STOCK_ADD, '<Ctrl>A') -overwrite_stock(gtk.STOCK_REMOVE, '<Shift>Delete') -overwrite_stock(gtk.STOCK_SELECT_COLOR, '<Ctrl>L') +overwrite_stock(Gtk.STOCK_FULLSCREEN, 'F11') +overwrite_stock(Gtk.STOCK_ADD, '<Ctrl>A') +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] + text = Gtk.stock_lookup(stock)[1] if underline: text = text.replace('_', '') return text def get_accelerator(stock): - return gtk.stock_lookup(stock)[2:-1] + stock_id = Gtk.stock_lookup(stock) + return stock_id.modifier, stock_id.keyval |