NEVER MIND I AM A HUGE BUTTGUY. The event stuff should go under the class's 
__init__ method. :)

On Tuesday, February 25, 2014 4:43:32 PM UTC+2, Henré Botha wrote:
>
> Ok, here's another related question. Code here: 
> http://pastebin.com/xPCeXz6M
>
> If I write a class definition containing event stuff, I expect the 
> instantiation of that class to be the thing that causes the event handlers 
> to be defined. Instead, it seems they get defined immediately. In my code 
> example, the program will print "AFTER CLASS DEF" on any keypress, even if 
> I instantiate the class after the second function definition.
>
> This is annoying. It seems to make it tricky to factor out things like 
> menus or whatever into separate classes, because those classes won't allow 
> the event handler definitions to be created on instantiation of whatever 
> class.
>
> Or am I wrong?
>
> On Tuesday, February 25, 2014 12:03:39 PM UTC+2, Petr Viktorin wrote:
>>
>> On Python 3 you can use nonlocal, like so: 
>>
>> def main(): 
>>     select = 0 
>>
>>     @window.event 
>>     def on_key_press(symbol, mods): 
>>         nonlocal select 
>>         if symbol == key.DOWN: 
>>             select += 1 
>>
>>
>> On Tue, Feb 25, 2014 at 10:03 AM, Henré Botha <[email protected]> 
>> wrote: 
>> > Ah, thanks Petr! I didn't know assignments re-designate scope. I'll try 
>> your solutions tonight. I'm on Python 3, but I have to say your two 
>> proposed 2.x hacks don't strike me as valid. We'll see, I guess :P 
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups "pyglet-users" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to [email protected]. 
>> > To post to this group, send email to [email protected]. 
>> > Visit this group at http://groups.google.com/group/pyglet-users. 
>> > For more options, visit https://groups.google.com/groups/opt_out. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to