Mercurial > fife-parpg
comparison clients/pychan_demo/pychan_test.py @ 350:7ea98190a75e
Allow objects with an __call__ attribute used as event callbacks.
Tested in pychan demo.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 04 Sep 2009 06:40:50 +0000 |
parents | 48c99636453e |
children |
comparison
equal
deleted
inserted
replaced
349:493f7492f0ba | 350:7ea98190a75e |
---|---|
74 """ | 74 """ |
75 if self.widget: | 75 if self.widget: |
76 self.widget.hide() | 76 self.widget.hide() |
77 self.widget = None | 77 self.widget = None |
78 | 78 |
79 class TextSetter(object): | |
80 def __init__(self,text): | |
81 self.text = text | |
82 def __call__(self,widget): | |
83 widget.text = self.text | |
84 | |
79 class DemoApplication(basicapplication.ApplicationBase): | 85 class DemoApplication(basicapplication.ApplicationBase): |
80 def __init__(self): | 86 def __init__(self): |
81 # Let the ApplicationBase initialise FIFE | 87 # Let the ApplicationBase initialise FIFE |
82 super(DemoApplication,self).__init__() | 88 super(DemoApplication,self).__init__() |
83 | 89 |
99 self.gui.mapEvents(eventMap) | 105 self.gui.mapEvents(eventMap) |
100 | 106 |
101 # A simple hover-effect for the credits label | 107 # A simple hover-effect for the credits label |
102 credits = self.gui.findChild(name="creditsLink") | 108 credits = self.gui.findChild(name="creditsLink") |
103 # setEnterCallback is deprecated - we use it here to test it. | 109 # setEnterCallback is deprecated - we use it here to test it. |
104 credits.setEnterCallback(lambda w : credits._setText(u"CREDITS")) | 110 credits.setEnterCallback(TextSetter(u"CREDITS")) |
105 # Note that we can't simply write: | 111 # Note that we can't simply write: |
106 # credits.capture(credits._setText(u"Credits"), event_name="mouseExited") | 112 # credits.capture(credits._setText(u"Credits"), event_name="mouseExited") |
107 # that's because that would call credits._setText _NOW_ and we want to call | 113 # that's because that would call credits._setText _NOW_ and we want to call |
108 # it later. | 114 # it later. |
109 credits.capture(lambda : credits._setText(u"Credits"), event_name="mouseExited") | 115 credits.capture(lambda : credits._setText(u"Credits"), event_name="mouseExited") |