Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from OpenGL.GL import *
- from OpenGL.GLU import *
- from OpenGL.GLUT import *
- import PyCEGUI
- import PyCEGUIOpenGLRenderer
- from twisted.internet import reactor,protocol
- path="datafiles\\"
- class BaseApp(object, protocol.Protocol):
- def __init__(self):
- glutInit(sys.argv)
- glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA)
- glutInitWindowSize(1280, 1024)
- glutInitWindowPosition(100, 100)
- glutCreateWindow("")
- glutSetCursor(GLUT_CURSOR_NONE)
- glutDisplayFunc(self.displayFunc)
- glutReshapeFunc(self.reshapeFunc)
- glutMouseFunc(self.mouseFunc)
- glutMotionFunc(self.mouseMotionFunc)
- glutPassiveMotionFunc(self.mouseMotionFunc)
- glutKeyboardFunc(self.keyFunc)
- PyCEGUIOpenGLRenderer.OpenGLRenderer.bootstrapSystem()
- def __del__(self):
- PyCEGUIOpenGLRenderer.OpenGLRenderer.destroySystem()
- def initialiseResources(self):
- rp = PyCEGUI.System.getSingleton().getResourceProvider()
- parser = PyCEGUI.System.getSingleton().getXMLParser()
- if parser.isPropertyPresent("SchemaDefaultResourceGroup"):
- parser.setProperty("SchemaDefaultResourceGroup", "schemas")
- def setupUI(self):
- PyCEGUI.SchemeManager.getSingleton().create(path+"VanillaSkin.scheme")
- PyCEGUI.System.getSingleton().setDefaultFont("DejaVuSans-10")
- PyCEGUI.System.getSingleton().setDefaultMouseCursor("Vanilla-Images", "MouseArrow")
- layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("C:\\python27\\game\\datafiles\\login.layout")
- PyCEGUI.System.getSingleton().setGUISheet(layout)
- self.loginWindow=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login")
- self.submit=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Submit")
- self.username=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Username")
- self.password=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Password")
- self.submit.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'login')
- self.noUsername=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoUsername")
- self.noUsernameOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoUsername/Ok")
- self.noUsernameOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'noUsernameOkClicked')
- self.noPassword=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoPassword")
- self.noPasswordOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoPassword/Ok")
- self.noPasswordOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'noPasswordOkClicked')
- def run(self):
- self.initialiseResources()
- self.setupUI()
- self.lastFrameTime = glutGet(GLUT_ELAPSED_TIME)
- self.updateFPS = 0
- glutMainLoop()
- def displayFunc(self):
- thisTime = glutGet(GLUT_ELAPSED_TIME)
- elapsed = (thisTime - self.lastFrameTime) / 1000.0
- self.lastFrameTime = thisTime
- self.updateFPS = self.updateFPS - elapsed
- PyCEGUI.System.getSingleton().injectTimePulse(elapsed)
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- PyCEGUI.System.getSingleton().renderGUI()
- glutPostRedisplay()
- glutSwapBuffers()
- def reshapeFunc(self, width, height):
- glViewport(0, 0, width, height)
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- gluPerspective(60.0, width / height, 1.0, 50.0)
- glMatrixMode(GL_MODELVIEW)
- PyCEGUI.System.getSingleton().notifyDisplaySizeChanged(PyCEGUI.Size(width, height))
- def mouseFunc(self, button, state, x, y):
- if button == GLUT_LEFT_BUTTON:
- if state == GLUT_UP:
- PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.LeftButton)
- else:
- PyCEGUI.System.getSingleton().injectMouseButtonDown(PyCEGUI.LeftButton)
- elif button == GLUT_RIGHT_BUTTON:
- if state == GLUT_UP:
- PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.RightButton)
- else:
- PyCEGUI.System.getSingleton().injectMouseButtonDown(PyCEGUI.RightButton)
- def mouseMotionFunc(self, x, y):
- PyCEGUI.System.getSingleton().injectMousePosition(x, y)
- def keyFunc(self, key, x,y):
- PyCEGUI.System.getSingleton().injectChar(ord(key))
- def login(self, args):
- user=self.username.getText()
- if user=="":
- self.noUsername.setProperty("Visible", "True")
- else:
- password=self.password.getText()
- if password=="":
- self.noPassword.setProperty("Visible", "True")
- else:
- user="'" + user + "'"
- def noUsernameOkClicked(self,args):
- self.noUsername.setProperty("Visible", "False")
- def noPasswordOkClicked(self,args):
- self.noPassword.setProperty("Visible", "False")
- class EchoClient(protocol.Protocol):
- def connectionMade(self):
- self.transport.write("connected")
- def send(self, message):
- self.transport.write(message)
- class EchoFactory(protocol.ClientFactory):
- protocol = EchoClient
- def clientConnectionFailed(self, connector, reason):
- print "Connection failed - goodbye!"
- reactor.stop()
- def clientConnectionLost(self, connector, reason):
- print "Connection lost - goodbye!"
- reactor.stop()
- def twistedThread():
- reactor.connectTCP("localhost",8000)
- reactor.run()
- def CEGUIThread():
- app.run()
- if __name__ == '__main__':
- app=BaseApp()
- reactor.callFromThread(twistedThread)
- reactor.callFromThread(CEGUIThread)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement