From 5ceda38732c57211d3f38e6cbbd7b8a521a0a9e5 Mon Sep 17 00:00:00 2001 From: Daniel Francis Date: Wed, 03 Oct 2012 00:23:16 +0000 Subject: Start sugarizing; use Gtk3 --- (limited to 'desktop/sweetener/stock.py') 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, 'S') -overwrite_stock(gtk.STOCK_ZOOM_IN, 'plus') -overwrite_stock(gtk.STOCK_ZOOM_OUT, 'minus') -overwrite_stock(gtk.STOCK_ZOOM_100, '0') +overwrite_stock(Gtk.STOCK_SAVE_AS, 'S') +overwrite_stock(Gtk.STOCK_ZOOM_IN, 'plus') +overwrite_stock(Gtk.STOCK_ZOOM_OUT, 'minus') +overwrite_stock(Gtk.STOCK_ZOOM_100, '0') # Key accelerator will be F11 on desktops and return on Sugar. -overwrite_stock(gtk.STOCK_FULLSCREEN, 'F11') -overwrite_stock(gtk.STOCK_ADD, 'A') -overwrite_stock(gtk.STOCK_REMOVE, 'Delete') -overwrite_stock(gtk.STOCK_SELECT_COLOR, 'L') +overwrite_stock(Gtk.STOCK_FULLSCREEN, 'F11') +overwrite_stock(Gtk.STOCK_ADD, 'A') +overwrite_stock(Gtk.STOCK_REMOVE, 'Delete') +overwrite_stock(Gtk.STOCK_SELECT_COLOR, '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 -- cgit v0.9.1