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
- from twisted.protocols.basic import Int32StringReceiver, StatefulStringProtocol
- import threading
- import sys, os
- from PyCEGUIOpenGLRenderer import OpenGLRenderer as Renderer
- import Queue
- path="datafiles\\"
- PATH_RESOURCES = './'
- queue=Queue.Queue(-1)
- KEYMAP_ASCII = {8 : PyCEGUI.Key.Scan.Backspace,
- 13 : PyCEGUI.Key.Scan.Return,
- 27 : PyCEGUI.Key.Scan.Escape,
- 127 : PyCEGUI.Key.Scan.Delete}
- KEYMAP_GLUT = {GLUT_KEY_LEFT : PyCEGUI.Key.Scan.ArrowLeft,
- GLUT_KEY_RIGHT : PyCEGUI.Key.Scan.ArrowRight,
- GLUT_KEY_HOME : PyCEGUI.Key.Scan.Home,
- GLUT_KEY_END : PyCEGUI.Key.Scan.End}
- prot = None
- def loginClicked(user, password):
- global prot
- prot.sendString('Login:')
- prot.sendString(str(user))
- prot.sendString(str(password))
- def gotProtocol(proto):
- global prot
- prot = proto
- class BaseApp(object):
- def __init__(self):
- super(BaseApp, self).__init__()
- self.lastFrameTime=0
- self.updateFPS = 0
- return
- def initializeOpenGL(self):
- glutInit()
- glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA)
- glutInitWindowSize(1280, 1024)
- glutInitWindowPosition(-1,-1)
- glutCreateWindow("")
- glutSetCursor(GLUT_CURSOR_NONE)
- return
- def initializeHandlers(self):
- glutDisplayFunc(self.displayFunc)
- glutReshapeFunc(self.reshapeFunc)
- glutMouseFunc(self.mouseFunc)
- glutMotionFunc(self.mouseMotionFunc)
- glutPassiveMotionFunc(self.mouseMotionFunc)
- glutKeyboardFunc(self.handlerKeyboard)
- glutSpecialFunc(self.handlerKeyboardSpecial)
- def initializePyCEGUI(self):
- Renderer.bootstrapSystem()
- self.sys=PyCEGUI.System.getSingleton()
- parser = PyCEGUI.System.getSingleton().getXMLParser()
- if parser.isPropertyPresent("SchemaDefaultResourceGroup"):
- parser.setProperty("SchemaDefaultResourceGroup", "schemas")
- def initializeGUI(self):
- PyCEGUI.SchemeManager.getSingleton().create(path+"VanillaSkin.scheme")
- PyCEGUI.System.getSingleton().setDefaultFont("AnkeCalligraph")
- PyCEGUI.System.getSingleton().setDefaultMouseCursor("Vanilla-Images", "MouseArrow")
- layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("datafiles\\login.layout")
- PyCEGUI.System.getSingleton().setGUISheet(layout)
- 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 Initialize(self):
- self.initializeOpenGL()
- self.initializeHandlers()
- self.initializePyCEGUI()
- self.initializeGUI()
- def displayFunc(self):
- now = glutGet(GLUT_ELAPSED_TIME)
- elapsed = (now - self.lastFrameTime) / 1000.0
- self.lastFrameTime = now
- self.updateFPS = self.updateFPS - elapsed
- self.sys.injectTimePulse(elapsed)
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- self.sys.renderGUI()
- glutPostRedisplay()
- glutSwapBuffers()
- def reshapeFunc(self, width, height):
- glViewport(0, 0, width, height)
- self.sys.notifyDisplaySizeChanged(PyCEGUI.Size(width, height))
- return
- 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 handlerAssistKeyboard(self, key):
- try:
- self.sys.injectKeyDown(KEYMAP_ASCII[key])
- except KeyError:
- return False
- return True
- def handlerKeyboard(self, key, x, y):
- k = ord(key)
- if not self.handlerAssistKeyboard(k):
- self.sys.injectChar(ord(key))
- return
- def handlerKeyboardSpecial(self, key, x, y):
- try:
- self.sys.injectKeyDown(KEYMAP_GLUT[key])
- except KeyError:
- pass
- return
- def run(self):
- global queue
- self.lastFrameTime = glutGet(GLUT_ELAPSED_TIME)
- while queue.empty==False:
- queue.get()
- callable()
- glutMainLoop()
- 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:
- reactor.callFromThread(loginClicked, user, password)
- def noUsernameOkClicked(self,args):
- self.noUsername.setProperty("Visible", "False")
- def noPasswordOkClicked(self,args):
- self.noPassword.setProperty("Visible", "False")
- def inv():
- print "inv"
- def loggedin():
- print "logged in"
- global queue
- queue.put(lambda:loginWindow.setProperty("Visible", "False"))
- class EchoClient(StatefulStringProtocol,Int32StringReceiver):
- def connectionMade(self):
- pass
- def proto_init(self, data):
- if data=="inv":
- reactor.callInThread(inv)
- if data=="logged in":
- reactor.callInThread(loggedin)
- def connectionLost(self, reason):
- print "connection lost"
- 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()
- class twistedThread(threading.Thread):
- def run(self):
- creator = protocol.ClientCreator(reactor, EchoClient)
- d = creator.connectTCP("localhost", 5000)
- d.addCallback(gotProtocol)
- reactor.run(False)
- twistedThread().start()
- while True:
- app=BaseApp()
- app.Initialize()
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement