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.


Is the "i" the returning value in your example?

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).



Because there are some things in your example that I not understand.

key, modifier = gtk.accelerator_parse('<Alt>%d' % i)

Why %d instead d and what is % i?

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.


accelgroup.connect_group(key, modifier, gtk.ACCEL_VISIBLE, lambda a,b,c,d,i=i: self.assess_quality(i))

Are a,b,c,d,i widgets in your script? And why =i? I supposing
self.assess_quality(i) is a function from you that returns the needed
value for GTK+. I'm right?

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   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to