FIFE forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

FIFE 0.4.0 has been released on 15th of January, 2017!

Author Topic: Question about pychan demo  (Read 2208 times)

Auree

  • Newbie
  • Posts: 3
    • View Profile
Question about pychan demo
« on: March 14, 2009, 10:08:43 pm »

Hello everybody!
I'm looking into pychan_demo code and I have some questions about it. Sorry if they are stupid, I'm not a great python programmer. At least yet =)
So, here's the code (puchan_test.py):
Code: [Select]
class DemoApplication(basicapplication.ApplicationBase):
def __init__(self):
super(DemoApplication,self).__init__()

pychan.init(self.engine,debug=True)
pychan.setupModalExecution(self.mainLoop,self.breakFromMainLoop)

self.gui = pychan.loadXML('gui/demoapp.xml')

eventMap = {
'creditsLink'  : self.showCredits,
'closeButton'  : self.quit,
'demoList' : self.selectExample,
'slider': self.test_slider
}
self.gui.mapEvents(eventMap)
credits = self.gui.findChild(name="creditsLink")
credits.setEnterCallback(lambda w : credits._setText("CREDITS"))
credits.capture(lambda : credits._setText("Credits"), event_name="mouseExited")
My questions are about three last lines.
1) Why credits.setEnterCallback is used if it is deprecated? And btw why is it deprecated?
2) Why do we use lambda for credits._setText?
3) Why do we use credits.setEnterCallback and credits.capture instead of handling these events in eventMap?

I will have more questions soon. Please tell me if this forum is a correct place to ask.
I will appreciate any advice =)
Thank you!
Logged

phoku

  • Developer
  • Full Member
  • *
  • Posts: 102
    • View Profile
    • IZ dev blog
Re: Question about pychan demo
« Reply #1 on: March 15, 2009, 05:22:12 am »

Hi there :-)

I used the setEnterCallback simply to test whether the deprecated code path actually works. The pychan demo is part demo code, part testing code - to see that all documented (even if deprecated) techniques work.

The setEnterCallback is deprecated since with Widget.capture/mapEvents there's already a function available to handle the events and it's better to have only one way to do things (python philosophy, also easier to debug).

The lambda is there since we can't simply write credits.capture(credits._setText("Credits"),event_name = "mouseExited") since the callback needs to be a function, and the above line would result in calling credits._setText.

For this kind of case you can use the pychan.tools.callbackWithArguments function or define a function somewhere else.

Also the pychan demo is a bit old, as I haven't worked on pychan for some time now.
I personally like using the forum for questions and answers, for a quicker response the IRC channel is also very very useful.

- phoku

Logged