Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.88 KB | None | 0 0
  1. from OpenGL.GL import *
  2. from OpenGL.GLU import *
  3. from OpenGL.GLUT import *
  4. import PyCEGUI
  5. import PyCEGUIOpenGLRenderer
  6. from twisted.internet import reactor,protocol
  7. path="datafiles\\"
  8.  
  9. class BaseApp(object, protocol.Protocol):
  10.     def __init__(self):
  11.         glutInit(sys.argv)
  12.         glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA)
  13.         glutInitWindowSize(1280, 1024)
  14.         glutInitWindowPosition(100, 100)
  15.         glutCreateWindow("")
  16.         glutSetCursor(GLUT_CURSOR_NONE)
  17.  
  18.         glutDisplayFunc(self.displayFunc)
  19.         glutReshapeFunc(self.reshapeFunc)
  20.         glutMouseFunc(self.mouseFunc)
  21.         glutMotionFunc(self.mouseMotionFunc)
  22.         glutPassiveMotionFunc(self.mouseMotionFunc)
  23.         glutKeyboardFunc(self.keyFunc)
  24.  
  25.         PyCEGUIOpenGLRenderer.OpenGLRenderer.bootstrapSystem()
  26.  
  27.     def __del__(self):
  28.         PyCEGUIOpenGLRenderer.OpenGLRenderer.destroySystem()
  29.  
  30.     def initialiseResources(self):
  31.         rp = PyCEGUI.System.getSingleton().getResourceProvider()
  32.  
  33.         parser = PyCEGUI.System.getSingleton().getXMLParser()
  34.         if parser.isPropertyPresent("SchemaDefaultResourceGroup"):
  35.             parser.setProperty("SchemaDefaultResourceGroup", "schemas")    
  36.  
  37.     def setupUI(self):
  38.         PyCEGUI.SchemeManager.getSingleton().create(path+"VanillaSkin.scheme")
  39.         PyCEGUI.System.getSingleton().setDefaultFont("DejaVuSans-10")
  40.         PyCEGUI.System.getSingleton().setDefaultMouseCursor("Vanilla-Images", "MouseArrow")
  41.         layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("C:\\users\\chris\\desktop\\ceed\\ceed\\datafiles\\mine7.layout")
  42.         PyCEGUI.System.getSingleton().setGUISheet(layout)
  43.         PyCEGUI.System.getSingleton().getGUISheet().addChildWindow(layout)
  44.         self.loginWindow=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login")
  45.         self.submit=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Submit")
  46.         self.username=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Username")
  47.         self.password=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Password")
  48.         self.submit.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'login')
  49.  
  50.     def run(self):
  51.         self.initialiseResources()
  52.         self.setupUI()
  53.  
  54.         self.lastFrameTime = glutGet(GLUT_ELAPSED_TIME)
  55.         self.updateFPS = 0
  56.         glutMainLoop()
  57.  
  58.     def displayFunc(self):
  59.         thisTime = glutGet(GLUT_ELAPSED_TIME)
  60.         elapsed = (thisTime - self.lastFrameTime) / 1000.0
  61.         self.lastFrameTime = thisTime
  62.         self.updateFPS = self.updateFPS - elapsed
  63.  
  64.         PyCEGUI.System.getSingleton().injectTimePulse(elapsed)
  65.  
  66.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  67.         PyCEGUI.System.getSingleton().renderGUI()
  68.         glutPostRedisplay()
  69.         glutSwapBuffers()
  70.  
  71.     def reshapeFunc(self, width, height):
  72.         glViewport(0, 0, width, height)
  73.         glMatrixMode(GL_PROJECTION)
  74.         glLoadIdentity()
  75.         gluPerspective(60.0, width / height, 1.0, 50.0)
  76.         glMatrixMode(GL_MODELVIEW)
  77.         PyCEGUI.System.getSingleton().notifyDisplaySizeChanged(PyCEGUI.Size(width, height))
  78.  
  79.     def mouseFunc(self, button, state, x, y):
  80.         if button == GLUT_LEFT_BUTTON:
  81.             if state == GLUT_UP:
  82.                 PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.LeftButton)
  83.             else:
  84.                 PyCEGUI.System.getSingleton().injectMouseButtonDown(PyCEGUI.LeftButton)
  85.  
  86.         elif button == GLUT_RIGHT_BUTTON:
  87.             if state == GLUT_UP:
  88.                 PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.RightButton)
  89.             else:
  90.                 PyCEGUI.System.getSingleton().injectMouseButtonDown(PyCEGUI.RightButton)
  91.  
  92.     def mouseMotionFunc(self, x, y):
  93.         PyCEGUI.System.getSingleton().injectMousePosition(x, y)
  94.  
  95.     def keyFunc(self, key, x,y):
  96.         PyCEGUI.System.getSingleton().injectChar(ord(key))
  97.  
  98.     def login(self, args):
  99.         user=self.username.getText()
  100.         if user=="":
  101.             print "Please enter your username"
  102.         else:
  103.             password=self.password.getText()
  104.             if password=="":
  105.                 print "Please enter your password"
  106.             else:
  107.                 user="'" + user + "'"
  108.  
  109. class EchoClient(protocol.Protocol):
  110.    
  111.     def connectionMade(self):
  112.         self.transport.write("connected")
  113.  
  114. class EchoFactory(protocol.ClientFactory):
  115.     protocol = EchoClient
  116.  
  117.     def clientConnectionFailed(self, connector, reason):
  118.         print "Connection failed - goodbye!"
  119.         reactor.stop()
  120.    
  121.     def clientConnectionLost(self, connector, reason):
  122.         print "Connection lost - goodbye!"
  123.         reactor.stop()
  124.  
  125. def main():
  126.     f = EchoFactory()
  127.     reactor.connectTCP("localhost", 8000, f)
  128.     reactor.run()
  129.  
  130. if __name__ == '__main__':
  131.     main()
  132.     app = BaseApp()
  133.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement