[pygtk] Key event handling and Pythons lake of switch statement
Niklas Koep
niklas.koep at gmail.com
Mon Jan 28 21:39:33 WST 2013
Just to quote the Python
docs<http://docs.python.org/2/tutorial/controlflow.html#if-statements>
on
the subject: "An if ... elif ... elif ... sequence is a substitute for the
switch or case statements found in other languages."
Regards
2013/1/27 David Ripton <dripton at ripton.net>
> On 01/27/2013 03:24 PM, Christian Mallwitz wrote:
>
> Where in C you would have something along the lines of:
>>
>> switch (event->keyval) {
>> case GDK_Left: ...
>> case GDK_BackSpace: ...
>> ...
>> }
>>
>> What is your preferred code style to handle that in Python? How about
>> more than one keyval triggering the same action?
>>
>
> If it's a small number of cases, just use if/elif. (With "or" for the
> multiple value case.)
>
> If it's a large number of cases, you can use a dict, with functions or
> methods as the values.
>
> --
> David Ripton dripton at ripton.net
>
> ______________________________**_________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/**listinfo/pygtk<http://www.daa.com.au/mailman/listinfo/pygtk>
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20130128/98a553a2/attachment.html>
More information about the pygtk
mailing list