Hi
I'm trying to understand the behaviour of decorators like
@self.window.event.
Sometimes the decorators accumulate and sometimes they replace each other
and
I really don't understand the logic. I know that decorators are a feature
of Python and not just Pyglet but since a lot of the Pyglet tutorials and
example code I have
read encourages their use I think it would appropriate to ask this here.
Sometimes it seems like only the most recent decoration is applied, so if I
write
window = pyglet.window.Window(width = 800, height = 640, caption = "Pyglet
Experiment")
@window.event
def on_key_press(key, modifiers):
print('A key was pressed')
if key == pyglet.window.key._1:
print("Change Things")
change_things(window)
elif key == pyglet.window.key._2:
print("Change Things 2")
change_things2(window)
print()
def change_things(window):
@window.event
def on_key_press(symbol, modifiers):
print('Ole!')
def change_things2(window):
@window.event
def on_key_press(symbol, modifiers):
print('Zamzam!')
And then press a key other than '1' or '2', the program prints
A key was pressed
(followed by a new line)
Then by pressing '1' or '2' I can accumulate lines like
'Ole' or 'Zamzam', which are presented in reverse order
(the 'A key was pressed' comes last).
However if I add this
change_things(window)
after all the code above, this line seems to override the earlier
on_key_press,
so whenever I press a button (any button including '1' or '2' I get a
single line of 'Ole'.
Clearly there is something about decorators that I just don't get.
Help would be appreciated, including links to general Python explanations
not exclusively
related to Pyglet.
--
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 https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.