[pygtk] accelerator for an image button.
Neil Dugan
debian at butterflystitches.com.au
Sun Nov 4 17:51:47 WST 2007
Gian Mario Tagliaretti wrote:
> 2007/11/3, Neil Dugan <pygtk at butterflystitches.com.au>:
>
> Hi Neil,
>
>
>>I am trying to make an python/gtk+ app. One problem I am having is
>>attaching an accelerator to a image button.
>>
>>This is the code I am using to create the buttons.
>>
>>--- cut ---
>> def index_control(self):
>> hbox = gtk.HBox()
>> for stock in
>>[gtk.STOCK_GOTO_FIRST,gtk.STOCK_GO_BACK,gtk.STOCK_GO_FORWARD,gtk.STOCK_GOTO_LAST] :
>> image = gtk.Image()
>> image.set_from_stock(stock,gtk.ICON_SIZE_MENU)
>> button = gtk.Button()
>> button.set_image(image)
>> hbox.pack_start(button,False,False)
>> return hbox
>>--- cut ---
>>I can give the full source if needed.
>
>
> I don't see any code with accelerators here, btw here we go with a
> small example:
>
> import gtk
>
> w = gtk.Window()
> w.connect("destroy", gtk.main_quit)
> w.set_default_size(200, 300)
>
> b = gtk.Button(None, gtk.STOCK_QUIT)
> b.connect("clicked", gtk.main_quit)
>
> ag = gtk.AccelGroup()
> w.add_accel_group(ag)
>
> b.add_accelerator("clicked", ag, ord('q'), gtk.gdk.SHIFT_MASK,
> gtk.ACCEL_VISIBLE)
>
> w.add(b)
> w.show_all()
> gtk.main()
>
> cheers
Thanks for that. I didn't know about the add_accelerator() function.
I found the gtk.accelerator_parse() function, once I found out what
to parse (e.g. "<ALT>Left") it didn't take me long to get everything
working.
Regards Neil.
More information about the pygtk
mailing list