How to handle Events in another Python Script using PyCEGUI
Posted: Wed Apr 13, 2011 15:28
Hi, everybody:
I'm new to python but I try to do something using PyOgre and PyCEGUI. My problem is: I want to put the window events handler in another python script file, just like using lua script when I use C++ CEGUI. Here is what I do to implement :
in my demo.py:
the first line in this function I just setup CEGUI and set resource location etc.
then I execute a python file using execfile
in my events handler file -- gui_logic.py:
I don't want to be implement these in a class but the subscribeEvent function takes
three arguments so... anyway when I launch the demo, it successfully load the layoutfile which I checked in log file.
Here is my problem: when I clicked the button, the program crashed! I don't know why because the log files and Eclipse(I use Eclipse and PyDev) give me no error track information!
So I really want to know how to handler CEGUI window events in another python script file just like lua does! I can easily use tolua++ handle a big part of my Class function in a lua script but now in Python I really don't know how to do.
Any advice will be appreciated!
I'm new to python but I try to do something using PyOgre and PyCEGUI. My problem is: I want to put the window events handler in another python script file, just like using lua script when I use C++ CEGUI. Here is what I do to implement :
in my demo.py:
Code: Select all
def _createScene(self):
mygui = MYGUI.getSingleton()
execfile('gui_logic.py')
the first line in this function I just setup CEGUI and set resource location etc.
then I execute a python file using execfile
in my events handler file -- gui_logic.py:
Code: Select all
class GuiLogic:
def btn_clicked(self, args):
button = MYGUI.getSingleton().getWindow("Root/BgImg/QuitBtn")
button.setText("HAHA")
return True
def subscribe(self):
MYGUI.getSingleton().loadWindow("Root")
button = MYGUI.getSingleton().getWindow("Root/BgImg/QuitBtn")
button.subscribeEvent(CEGUI.PushButton.EventClicked,
self,
"btn_clicked")
if __name__=='__main__':
GuiLogic().subscribe()
I don't want to be implement these in a class but the subscribeEvent function takes
three arguments so... anyway when I launch the demo, it successfully load the layoutfile
Code: Select all
13/04/2011 23:07:37 (Std) ---- Successfully completed loading of GUI layout from 'Root.layout' ----
Here is my problem: when I clicked the button, the program crashed! I don't know why because the log files and Eclipse(I use Eclipse and PyDev) give me no error track information!
So I really want to know how to handler CEGUI window events in another python script file just like lua does! I can easily use tolua++ handle a big part of my Class function in a lua script but now in Python I really don't know how to do.
Any advice will be appreciated!