|
Re: gtk.Window() and accelerator: msg#00096gnome.gtk+.python
Marcus Habermehl wrote: Please, remember that callbacks assigned in connect_group must return True. Otherwise GTK+ will segfault sooner or later. It is probably irrelevant to this example as it only calls gtk.main_quit(), but if you want to do other things in callback it must return some value. No, it's the code from my program, Snakememory, and I slightly modified it. In my program it is used in loop to create Alt-[0-5] accelerators for indicating response quality. Requirement of returning boolean value from accelerator callback is the requirement of GTK+ library. It will segfault otherwise at some random place (which is probably bad as extension modules shouldn't generate SIGSEGVs).
Here's the real unmodified code from my program: accelgroup = gtk.AccelGroup() for i in range(6): key, modifier = gtk.accelerator_parse('<Alt>%d' % i) accelgroup.connect_group(key, modifier, gtk.ACCEL_VISIBLE, lambda a,b,c,d,i=i: self.assess_quality(i)) self.view.recall_card_window.add_accel_group(accelgroup) This loop creates callbacks for key sequences Alt-0, Alt-1, ..., Alt-5 "'<Alt>%d' % i" is a usual string interploation.
a,b,c,d are GTK+ arguments for callback, see the documentation. I've named them a,b,c,d because I don't use them and therefore lazy to type proper names. "i=i" is used because otherwise "i" variable in all lambda callbacks will equal to the final value of "i" in the loop (5). See PEP 227 (nested scopes). self.assess_quality() does some computations using the user feedback and returns True. You can do whatever you want in your callback, the only requirement is to return true value for GTK+. Eugene -- Email: eugene @ renice.org Homepage: http://eugene.renice.org _______________________________________________ pygtk mailing list pygtk@xxxxxxxxxx http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | TreeView backgound image: 00096, vector |
|---|---|
| Next by Date: | Re: FileChooserDialog an FontSelectionDialog: 00096, Nemesis |
| Previous by Thread: | Re: Re: gtk.Window() and acceleratori: 00096, Marcus Habermehl |
| Next by Thread: | gtk.gdk.Event: 00096, Kenny Chamber |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |