diff options
Diffstat (limited to 'sugar/sweetener/stock.py')
-rw-r--r-- | sugar/sweetener/stock.py | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/sugar/sweetener/stock.py b/sugar/sweetener/stock.py index a6451a7..28f3956 100644 --- a/sugar/sweetener/stock.py +++ b/sugar/sweetener/stock.py @@ -19,12 +19,12 @@ import logging logger = logging.getLogger('stock') -import gtk +from gi.repository import Gtk -icon_factory = gtk.IconFactory() +icon_factory = Gtk.IconFactory() # Set the icon name for the stock items, this is used only in Sugar. -icons = {gtk.STOCK_ADD: 'list-add'} +icons = {Gtk.STOCK_ADD: 'list-add'} def register(name, label, accelerator, icon_name): @@ -32,12 +32,19 @@ 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() @@ -45,33 +52,35 @@ def register(name, label, accelerator, icon_name): 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_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, '<Alt>Return') -overwrite_stock(gtk.STOCK_ADD, '<Ctrl>A') -overwrite_stock(gtk.STOCK_REMOVE, '<Ctrl>R') -overwrite_stock(gtk.STOCK_SELECT_COLOR, '<Ctrl>L') +overwrite_stock(Gtk.STOCK_FULLSCREEN, '<Alt>Return') +overwrite_stock(Gtk.STOCK_ADD, '<Ctrl>A') +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] + 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 |