Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.50 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. from twisted.protocols.basic import Int32StringReceiver, StatefulStringProtocol
  8. import threading
  9. import sys, os
  10. from PyCEGUIOpenGLRenderer import OpenGLRenderer as Renderer
  11. import Queue
  12. import time
  13. path="datafiles\\"
  14. PATH_RESOURCES = './'
  15. queue=Queue.Queue(-1)
  16.  
  17. KEYMAP_ASCII = {8 : PyCEGUI.Key.Scan.Backspace,
  18.                 13 : PyCEGUI.Key.Scan.Return,
  19.                 27 : PyCEGUI.Key.Scan.Escape,
  20.                 127 : PyCEGUI.Key.Scan.Delete}
  21.  
  22. KEYMAP_GLUT = {GLUT_KEY_LEFT : PyCEGUI.Key.Scan.ArrowLeft,
  23.                GLUT_KEY_RIGHT : PyCEGUI.Key.Scan.ArrowRight,
  24.                GLUT_KEY_HOME : PyCEGUI.Key.Scan.Home,
  25.                GLUT_KEY_END : PyCEGUI.Key.Scan.End}
  26.  
  27. prot = None
  28.  
  29. def loginClicked(user, password):
  30.     global prot
  31.     prot.sendString('Login:')
  32.     prot.sendString(str(user))
  33.     prot.sendString(str(password))
  34.  
  35. def gotProtocol(proto):
  36.     global prot
  37.     prot = proto
  38.  
  39. class BaseApp(object):
  40.     def __init__(self):
  41.         super(BaseApp, self).__init__()
  42.         self.lastFrameTime=0
  43.         self.updateFPS = 0
  44.         return
  45.        
  46.     def initializeOpenGL(self):
  47.         glutInit()
  48.         glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA)
  49.         glutInitWindowSize(1280, 1024)
  50.         glutInitWindowPosition(-1,-1)
  51.         glutCreateWindow("")
  52.         glutSetCursor(GLUT_CURSOR_NONE)
  53.         return
  54.  
  55.     def initializeHandlers(self):
  56.         glutDisplayFunc(self.displayFunc)
  57.         glutReshapeFunc(self.reshapeFunc)
  58.         glutMouseFunc(self.mouseFunc)
  59.         glutMotionFunc(self.mouseMotionFunc)
  60.         glutPassiveMotionFunc(self.mouseMotionFunc)
  61.         glutKeyboardFunc(self.handlerKeyboard)
  62.         glutSpecialFunc(self.handlerKeyboardSpecial)
  63.  
  64.     def initializePyCEGUI(self):
  65.         Renderer.bootstrapSystem()
  66.         self.sys=PyCEGUI.System.getSingleton()
  67.         parser = PyCEGUI.System.getSingleton().getXMLParser()
  68.         if parser.isPropertyPresent("SchemaDefaultResourceGroup"):
  69.             parser.setProperty("SchemaDefaultResourceGroup", "schemas")    
  70.  
  71.     def initializeGUI(self):
  72.         PyCEGUI.SchemeManager.getSingleton().create(path+"VanillaSkin.scheme")
  73.         PyCEGUI.System.getSingleton().setDefaultFont("AnkeCalligraph")
  74.         PyCEGUI.System.getSingleton().setDefaultMouseCursor("Vanilla-Images", "MouseArrow")
  75.         layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("datafiles\\login.layout")
  76.         PyCEGUI.System.getSingleton().setGUISheet(layout)
  77.         loginWindow=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login")
  78.         self.submit=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Submit")
  79.         self.username=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Username")
  80.         self.password=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Password")
  81.         self.submit.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'login')
  82.         self.noUsername=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoUsername")
  83.         self.noUsernameOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoUsername/Ok")
  84.         self.noUsernameOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'noUsernameOkClicked')
  85.         self.noPassword=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoPassword")
  86.         self.noPasswordOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoPassword/Ok")
  87.         self.noPasswordOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'noPasswordOkClicked')
  88.         self.Incorrect=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Incorrect")
  89.         self.IncorrectOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Incorrect/Ok")
  90.         self.IncorrectOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'incorrectOkClicked')
  91.        
  92.     def Initialize(self):
  93.         self.initializeOpenGL()
  94.         self.initializeHandlers()
  95.         self.initializePyCEGUI()
  96.         self.initializeGUI()
  97.  
  98.     def displayFunc(self):
  99.         now = glutGet(GLUT_ELAPSED_TIME)
  100.         elapsed = (now - self.lastFrameTime) / 1000.0
  101.         self.lastFrameTime = now
  102.         self.updateFPS = self.updateFPS - elapsed
  103.         self.sys.injectTimePulse(elapsed)
  104.  
  105.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  106.         self.sys.renderGUI()
  107.         glutPostRedisplay()
  108.         glutSwapBuffers()
  109.  
  110.     def reshapeFunc(self, width, height):
  111.         glViewport(0, 0, width, height)
  112.         self.sys.notifyDisplaySizeChanged(PyCEGUI.Size(width, height))
  113.         return
  114.  
  115.     def mouseFunc(self, button, state, x, y):
  116.         if button == GLUT_LEFT_BUTTON:
  117.             if state == GLUT_UP:
  118.                 PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.LeftButton)
  119.             else:
  120.                 PyCEGUI.System.getSingleton().injectMouseButtonDown(PyCEGUI.LeftButton)
  121.  
  122.         elif button == GLUT_RIGHT_BUTTON:
  123.             if state == GLUT_UP:
  124.                 PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.RightButton)
  125.             else:
  126.                 PyCEGUI.System.getSingleton().injectMouseButtonDown(PyCEGUI.RightButton)
  127.  
  128.     def mouseMotionFunc(self, x, y):
  129.         PyCEGUI.System.getSingleton().injectMousePosition(x, y)
  130.  
  131.     def handlerAssistKeyboard(self, key):
  132.         try:
  133.             self.sys.injectKeyDown(KEYMAP_ASCII[key])
  134.         except KeyError:
  135.             return False
  136.         return True
  137.  
  138.     def handlerKeyboard(self, key, x, y):
  139.         k = ord(key)
  140.         if not self.handlerAssistKeyboard(k):
  141.             self.sys.injectChar(ord(key))
  142.         return
  143.  
  144.     def handlerKeyboardSpecial(self, key, x, y):
  145.         try:
  146.             self.sys.injectKeyDown(KEYMAP_GLUT[key])
  147.         except KeyError:
  148.             pass
  149.         return
  150.        
  151.     def run(self):
  152.         self.lastFrameTime = glutGet(GLUT_ELAPSED_TIME)
  153.         glutMainLoop()
  154.    
  155.     def a(self):
  156.         print "a"
  157.  
  158.     def login(self, args):
  159.         user=self.username.getText()
  160.         if user=="":
  161.             self.noUsername.setProperty("Visible", "True")
  162.         else:
  163.             password=self.password.getText()
  164.             if password=="":
  165.                 self.noPassword.setProperty("Visible", "True")
  166.             else:
  167.                 reactor.callFromThread(loginClicked, user, password)
  168.                 self.a()
  169.                
  170.                
  171.     def noUsernameOkClicked(self,args):
  172.         self.noUsername.setProperty("Visible", "False")
  173.        
  174.     def noPasswordOkClicked(self,args):
  175.         self.noPassword.setProperty("Visible", "False")
  176.        
  177.     def incorrectOkClicked(self,args):
  178.         self.Incorrect.setProperty("Visible", "False")
  179.  
  180. def inv():
  181.     print "inv"    
  182.    
  183. class EchoClient(StatefulStringProtocol,Int32StringReceiver):
  184.     def connectionMade(self):
  185.         pass
  186.  
  187.     def proto_init(self, data):
  188.         if data=="inv":
  189.             reactor.callInThread(inv)
  190.            
  191.         if data=="logged in":
  192.             print "logged in"
  193.         return 'init'
  194.  
  195.     def connectionLost(self, reason):
  196.         print "connection lost"
  197.  
  198. class twistedThread(threading.Thread):
  199.     def run(self):
  200.         creator = protocol.ClientCreator(reactor, EchoClient)
  201.         d = creator.connectTCP("localhost", 5000)
  202.         d.addCallback(gotProtocol)
  203.         reactor.run(False)
  204.        
  205. twistedThread().start()
  206. app=BaseApp()
  207. app.Initialize()
  208. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement