Cytosine
01-05-2008 20:46:31
Hello,
The link to the example code points to a blank edit page. I'd love to contribute my code, but I admit I'm having problems getting my Tut7 to work (otherwise I wouldn't need it!) If anyone can help me get through this, I promise I'll post the working result.
So far I've only made it as far as the end of the 'quit' button section. No matter where I click I keep receiving this error:
According to tut7 in the Converting and Injecting Mouse Events section I'm supposed to "Add the following function near the top of your source code, just before the TutorialListener class:", but that doesn't make sense to me since there is nothing 'before' the class definition itself. Should I create a new class for the 'convertButton' definition?
Here's my code so far:
I'm using Python-Ogre 1.1 with Python 2.5.1
Please let me know what else you might need.
Thanks.
--Cyto
The link to the example code points to a blank edit page. I'd love to contribute my code, but I admit I'm having problems getting my Tut7 to work (otherwise I wouldn't need it!) If anyone can help me get through this, I promise I'll post the working result.

So far I've only made it as far as the end of the 'quit' button section. No matter where I click I keep receiving this error:
Traceback (most recent call last):
File "Basic_07.py", line 97, in <module>
ta.go()
File "C:\tools\Python2.5.1\lib\site-packages\ogre\renderer\OGRE\sf_OIS.py", line 64, in go
self.root.startRendering()
File "Basic_07.py", line 18, in frameStarted
self.Mouse.capture()
File "Basic_07.py", line 31, in mousePressed
CEGUI.System.getSingleton().injectMouseButtonDown(convertButton(id))
NameError: global name 'convertButton' is not defined
According to tut7 in the Converting and Injecting Mouse Events section I'm supposed to "Add the following function near the top of your source code, just before the TutorialListener class:", but that doesn't make sense to me since there is nothing 'before' the class definition itself. Should I create a new class for the 'convertButton' definition?
Here's my code so far:
mport SampleFramework as sf
import ogre.renderer.OGRE as ogre
import ogre.io.OIS as OIS
import ogre.gui.CEGUI as CEGUI
class TutorialListener(sf.FrameListener, OIS.MouseListener, OIS.KeyListener):
def __init__(self, renderWindow, camera):
sf.FrameListener.__init__(self, renderWindow, camera, True, True)
OIS.MouseListener.__init__(self)
OIS.KeyListener.__init__(self)
self.cont = True
self.Mouse.setEventCallback(self)
self.Keyboard.setEventCallback(self)
def frameStarted(self, evt):
self.Keyboard.capture()
self.Mouse.capture()
return self.cont and not self.Keyboard.isKeyDown(OIS.KC_ESCAPE)
def quit(self, evt):
self.cont = False
return True
# MouseListener
def mouseMoved(self, evt):
CEGUI.System.getSingleton().injectMouseMove(evt.get_state().X.rel, evt.get_state().Y.rel)
return True
def mousePressed(self, evt, id):
CEGUI.System.getSingleton().injectMouseButtonDown(convertButton(id))
return True
def mouseReleased(self, evt, id):
CEGUI.System.getSingleton().injectMouseButtonUp(convertButton(id))
return True
# KeyListener
def keyPressed(self, evt):
ceguiSystem = CEGUI.System.getSingleton()
ceguiSystem.injectKeyDown(evt.key)
ceguiSystem.injectChar(evt.text)
return True
def keyReleased(self, evt):
CEGUI.System.getSingleton().injectKeyUp(evt.key)
return True
def convertButton(oisID):
if oisID == OIS.MB_Left:
return CEGUI.LeftButton
elif oisID == OIS.MB_Right:
return CEGUI.RightButton
elif oisID == OIS.MB_Middle:
return CEGUI.MiddleButton
else:
return CEGUI.LeftButton
class TutorialApplication(sf.Application):
def __del__(self):
if self.system:
del self.system
if self.renderer:
del self.renderer
def _createScene(self):
self.renderer = CEGUI.OgreCEGUIRenderer(self.renderWindow, ogre.RENDER_QUEUE_OVERLAY, False, 3000, self.sceneManager)
self.system = CEGUI.System(self.renderer)
CEGUI.SchemeManager.getSingleton().loadScheme("TaharezLookSkin.scheme")
self.system.setDefaultMouseCursor("TaharezLook", "MouseArrow")
self.system.setDefaultFont("BlueHighway-12")
windowManager = CEGUI.WindowManager.getSingleton()
sheet = windowManager.createWindow("DefaultGUISheet", "CEGUIDemo/Sheet")
quitButton = windowManager.createWindow("TaharezLook/Button", "CEGUIDemo/QuitButton")
quitButton.setText("Quit")
quitButton.setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0)))
sheet.addChildWindow(quitButton)
self.system.setGUISheet(sheet)
def _createFrameListener(self):
self.frameListener = TutorialListener(self.renderWindow, self.camera)
self.frameListener.showDebugOverlay(True)
self.root.addFrameListener(self.frameListener)
windowManager = CEGUI.WindowManager.getSingleton()
quitButton = windowManager.getWindow("CEGUIDemo/QuitButton")
quitButton.subscribeEvent(CEGUI.PushButton.EventClicked, self, "quit")
if __name__ == '__main__':
try:
ta = TutorialApplication()
ta.go()
except ogre.OgreException, e:
print e
I'm using Python-Ogre 1.1 with Python 2.5.1
Please let me know what else you might need.
Thanks.
--Cyto