Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.59 KB | None | 0 0
  1. #as this is multi-threaded, it currently must be exited by closing your terminal/resetting IDLE.
  2.  
  3. from direct.showbase.ShowBase import ShowBase
  4. import os, sys, string
  5. import PyCEGUI
  6. import PyCEGUIOpenGLRenderer
  7. from panda3d.core import PythonCallbackObject, CallbackNode, DataNode, loadPrcFileData
  8. from pandac.PandaModules import *
  9. import Queue
  10. from twisted.internet import reactor,protocol
  11. from twisted.protocols.basic import Int32StringReceiver, StatefulStringProtocol
  12. from twisted.words.protocols import irc
  13. import threading
  14.  
  15. queue=Queue.Queue(-1)
  16. prot = None
  17. chatProtocol=None
  18. user=None
  19. started=False
  20. msg=None
  21. username=None
  22. password=None
  23. boxItems=[]
  24. loadPrcFileData('', 'win-size 1280 768') #this size may not work for everyone. If it doesn't, feel free to change it, don't worry about changing it back.
  25. loadPrcFileData('', 'undecorated 1')
  26. loadPrcFileData('', 'win-origin 0 0')
  27. loadPrcFileData('', 'show-frame-rate-meter #t')
  28. loadPrcFileData('', 'sync-video #f')
  29. x=1
  30. logged=False
  31.  
  32. def loginClicked(user, password):
  33.     global prot
  34.     prot.sendString('Login:')
  35.     prot.sendString(str(user))
  36.     print user
  37.     prot.sendString(str(password))
  38.     print password
  39.    
  40. def gotProtocol(proto):
  41.     global prot
  42.     prot = proto
  43.    
  44. def chatProtocol(proto):
  45.     global chatProtocol
  46.     chatProtocol=proto
  47.    
  48. def loggedin():
  49.     global queue
  50.     global logged
  51.     logged=True
  52.     queue.put(lambda: PyCEGUI.WindowManager.getSingleton().destroyWindow("Root"))
  53.    
  54. def start():
  55.     global chatProtocol
  56.     global username
  57.     user=str(username)
  58.     global password
  59.     irc.IRCClient.setNick(chatProtocol, user)
  60.     chatProtocol.join("#spiritsword")
  61.     print "joined"
  62.  
  63. def messageSender():
  64.     global msg
  65.     global chatProtocol
  66.     msg=str(msg)
  67.     chatProtocol.msg("#spiritsword", msg)
  68.    
  69. def messageReceived():
  70.     global msg
  71.     global user
  72.     global queue
  73.     msg=user+": "+msg
  74.     queue.put(lambda: addMessage())
  75.    
  76. def addMessage():
  77.     global msg
  78.     global boxItems
  79.     listboxitem = PyCEGUI.ListboxTextItem(msg)
  80.     listboxitem.AutoDeleted = False
  81.     chatbox=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Chatbox")
  82.     chatbox.addItem(listboxitem)
  83.     boxItems.append(listboxitem)
  84.    
  85. def inv():
  86.     global queue
  87.     queue.put(lambda: PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Incorrect").setProperty("Visible", "True"))
  88.  
  89. class PandaCEGUI(object):
  90.     buttons = {
  91.         'mouse1': PyCEGUI.MouseButton.LeftButton,
  92.         'mouse2': PyCEGUI.MouseButton.RightButton,
  93.         'mouse3': PyCEGUI.MouseButton.MiddleButton,
  94.         'mouse1-up': PyCEGUI.MouseButton.LeftButton,
  95.         'mouse2-up': PyCEGUI.MouseButton.RightButton,
  96.         'mouse3-up': PyCEGUI.MouseButton.MiddleButton,
  97.         'wheel_up': PyCEGUI.MouseButton.NoButton,
  98.         'wheel_down': PyCEGUI.MouseButton.NoButton,
  99.     }
  100.    
  101.     keys = {
  102.         'a': (PyCEGUI.Key.Scan.A, 'a', 'A'),
  103.         'b': (PyCEGUI.Key.Scan.B, 'b', 'B'),
  104.         'c': (PyCEGUI.Key.Scan.C, 'c', 'C'),
  105.         'd': (PyCEGUI.Key.Scan.D, 'd', 'D'),
  106.         'e': (PyCEGUI.Key.Scan.E, 'e', 'E'),
  107.         'f': (PyCEGUI.Key.Scan.F, 'f', 'F'),
  108.         'g': (PyCEGUI.Key.Scan.G, 'g', 'G'),
  109.         'h': (PyCEGUI.Key.Scan.H, 'h', 'H'),
  110.         'i': (PyCEGUI.Key.Scan.I, 'i', 'I'),
  111.         'j': (PyCEGUI.Key.Scan.J, 'j', 'J'),
  112.         'k': (PyCEGUI.Key.Scan.K, 'k', 'K'),
  113.         'l': (PyCEGUI.Key.Scan.L, 'l', 'L'),
  114.         'm': (PyCEGUI.Key.Scan.M, 'm', 'M'),
  115.         'n': (PyCEGUI.Key.Scan.N, 'n', 'N'),
  116.         'o': (PyCEGUI.Key.Scan.O, 'o', 'O'),
  117.         'p': (PyCEGUI.Key.Scan.P, 'p', 'P'),
  118.         'q': (PyCEGUI.Key.Scan.Q, 'q', 'Q'),
  119.         'r': (PyCEGUI.Key.Scan.R, 'r', 'R'),
  120.         's': (PyCEGUI.Key.Scan.S, 's', 'S'),
  121.         't': (PyCEGUI.Key.Scan.T, 't', 'T'),
  122.         'u': (PyCEGUI.Key.Scan.U, 'u', 'U'),
  123.         'v': (PyCEGUI.Key.Scan.V, 'v', 'V'),
  124.         'w': (PyCEGUI.Key.Scan.W, 'w', 'W'),
  125.         'x': (PyCEGUI.Key.Scan.X, 'x', 'X'),
  126.         'y': (PyCEGUI.Key.Scan.Y, 'y', 'Y'),
  127.         'z': (PyCEGUI.Key.Scan.Z, 'z', 'Z'),
  128.  
  129.         '`': (PyCEGUI.Key.Scan.Grave, '`', '~'),
  130.         '0': (PyCEGUI.Key.Scan.Zero, '0', ')'),
  131.         '1': (PyCEGUI.Key.Scan.One, '1', '!'),
  132.         '2': (PyCEGUI.Key.Scan.Two, '2', '@'),
  133.         '3': (PyCEGUI.Key.Scan.Three, '3', '#'),
  134.         '4': (PyCEGUI.Key.Scan.Four, '4', '$'),
  135.         '5': (PyCEGUI.Key.Scan.Five, '5', '%'),
  136.         '6': (PyCEGUI.Key.Scan.Six, '6', '^'),
  137.         '7': (PyCEGUI.Key.Scan.Seven, '7', '&'),
  138.         '8': (PyCEGUI.Key.Scan.Eight, '8', '*'),
  139.         '9': (PyCEGUI.Key.Scan.Nine, '9', '('),
  140.         '-': (PyCEGUI.Key.Scan.Minus, '-', '_'),
  141.         '=': (PyCEGUI.Key.Scan.Equals, '=', '+'),
  142.  
  143.  
  144.         '[': (PyCEGUI.Key.Scan.LeftBracket, '[', '{'),
  145.         ']': (PyCEGUI.Key.Scan.RightBracket, ']', '}'),
  146.         '\\': (PyCEGUI.Key.Scan.Backslash, '\\', '|'),
  147.         ';': (PyCEGUI.Key.Scan.Semicolon, ';', ':'),
  148.  
  149.         "'": (PyCEGUI.Key.Scan.Apostrophe, "'", '"'),
  150.         ',': (PyCEGUI.Key.Scan.Comma, ',', '<'),
  151.         '.': (PyCEGUI.Key.Scan.Period, '.', '>'),
  152.         '/': (PyCEGUI.Key.Scan.Slash, '/', '?'),
  153.  
  154.         'f1': (PyCEGUI.Key.Scan.F1, '', ''),
  155.         'f2': (PyCEGUI.Key.Scan.F3, '', ''),
  156.         'f3': (PyCEGUI.Key.Scan.F3, '', ''),
  157.         'f4': (PyCEGUI.Key.Scan.F4, '', ''),
  158.         'f5': (PyCEGUI.Key.Scan.F5, '', ''),
  159.         'f6': (PyCEGUI.Key.Scan.F6, '', ''),
  160.         'f7': (PyCEGUI.Key.Scan.F7, '', ''),
  161.         'f8': (PyCEGUI.Key.Scan.F8, '', ''),
  162.         'f9': (PyCEGUI.Key.Scan.F9, '', ''),
  163.         'f10': (PyCEGUI.Key.Scan.F10, '', ''),
  164.         'f11': (PyCEGUI.Key.Scan.F11, '', ''),
  165.         'f12': (PyCEGUI.Key.Scan.F12, '', ''),
  166.  
  167.         'enter': (PyCEGUI.Key.Scan.Return, '\r', '\r'),
  168.         'tab': (PyCEGUI.Key.Scan.Tab, '\t', '\t'),
  169.         'space': (PyCEGUI.Key.Scan.Space, ' ', ' '),
  170.  
  171.         'escape': (PyCEGUI.Key.Scan.Escape, '', ''),
  172.         'backspace': (PyCEGUI.Key.Scan.Backspace, '', ''),
  173.  
  174.         'insert': (PyCEGUI.Key.Scan.Insert, '', ''),
  175.         'delete': (PyCEGUI.Key.Scan.Delete, '', ''),
  176.  
  177.         'home': (PyCEGUI.Key.Scan.Home, '', ''),
  178.         'end': (PyCEGUI.Key.Scan.End, '', ''),
  179.         'page_up': (PyCEGUI.Key.Scan.PageUp, '', ''),
  180.         'page_down': (PyCEGUI.Key.Scan.PageDown, '', ''),
  181.  
  182.         'arrow_left': (PyCEGUI.Key.Scan.ArrowLeft, '', ''),
  183.         'arrow_up': (PyCEGUI.Key.Scan.ArrowUp, '', ''),
  184.         'arrow_down': (PyCEGUI.Key.Scan.ArrowDown, '', ''),
  185.         'arrow_right': (PyCEGUI.Key.Scan.ArrowRight, '', ''),
  186.  
  187.         'num_lock': (PyCEGUI.Key.Scan.NumLock, '', ''),
  188.         'caps_lock': (PyCEGUI.Key.Scan.Capital, '', ''),
  189.         'scroll_lock': (PyCEGUI.Key.Scan.ScrollLock, '', ''),
  190.  
  191.         'lshift': (PyCEGUI.Key.Scan.LeftShift, '', ''),
  192.         'rshift': (PyCEGUI.Key.Scan.RightShift, '', ''),
  193.         'lcontrol': (PyCEGUI.Key.Scan.LeftControl, '', ''),
  194.         'rcontrol': (PyCEGUI.Key.Scan.RightControl, '', ''),
  195.         'lalt': (PyCEGUI.Key.Scan.LeftAlt, '', ''),
  196.         'ralt': (PyCEGUI.Key.Scan.RightAlt, '', ''),
  197.         }
  198.     hideSystemCursor = True
  199.     _renderingEnabled = True
  200.     _capsLock = False
  201.     _shiftCount = 0
  202.    
  203.     def __init__(self):
  204.         ceguiCB = PythonCallbackObject(self.renderCallback)
  205.         self.cbNode = CallbackNode("CEGUI")
  206.         self.cbNode.setDrawCallback(ceguiCB)
  207.         render2d.attachNewNode(self.cbNode)
  208.         base.accept('window-event', self.windowEvent)
  209.         PyCEGUIOpenGLRenderer.OpenGLRenderer.bootstrapSystem()
  210.         self.props = WindowProperties()
  211.         self.System = PyCEGUI.System.getSingleton()
  212.         self.WindowManager = PyCEGUI.WindowManager.getSingleton()
  213.         self.SchemeManager = PyCEGUI.SchemeManager.getSingleton()
  214.         self.FontManager = PyCEGUI.FontManager.getSingleton()
  215.  
  216.     def __del__(self):
  217.         PyCEGUIOpenGLRenderer.OpenGLRenderer.destroySystem()
  218.  
  219.     def initializeResources(self, resourcePath):
  220.         rp = self.System.getResourceProvider()
  221.         rp.setResourceGroupDirectory("schemes", resourcePath)
  222.         rp.setResourceGroupDirectory("imagesets", resourcePath)
  223.         rp.setResourceGroupDirectory("fonts", resourcePath)
  224.         rp.setResourceGroupDirectory("layouts", resourcePath)
  225.         rp.setResourceGroupDirectory("looknfeels", resourcePath)
  226.         rp.setResourceGroupDirectory("schemas", resourcePath)
  227.         PyCEGUI.Imageset.setDefaultResourceGroup("imagesets")
  228.         PyCEGUI.Font.setDefaultResourceGroup("fonts")
  229.         PyCEGUI.Scheme.setDefaultResourceGroup("schemes")
  230.         PyCEGUI.WidgetLookManager.setDefaultResourceGroup("looknfeels")
  231.         PyCEGUI.WindowManager.setDefaultResourceGroup("layouts")
  232.         parser = self.System.getXMLParser()
  233.         if parser.isPropertyPresent("SchemaDefaultResourceGroup"):
  234.             parser.setProperty("SchemaDefaultResourceGroup", "schemas")
  235.  
  236.     def enableInputHandling(self):
  237.         for button, cegui_name in self.buttons.iteritems():
  238.             base.accept(button, self.captureButton, [button, cegui_name])
  239.         base.mouseWatcherNode.setModifierButtons(ModifierButtons())
  240.         base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())
  241.         for key, keyTuple in self.keys.iteritems():
  242.             base.accept(key, self.captureKeys, [key, keyTuple])
  243.             base.accept(key + '-up', self.captureKeys, [key + '-up', keyTuple])
  244.             base.accept(key + '-repeat', self.captureKeys, [key, keyTuple])
  245.         if (self.hideSystemCursor):
  246.             self.props.setCursorHidden(True)
  247.             base.win.requestProperties(self.props)
  248.  
  249.     def disableInputHandling(self):
  250.         for button, name in self.buttons.iteritems():
  251.             base.ignore(button)
  252.         for key, keyTuple in self.keys.iteritems():
  253.             base.ignore(key)
  254.             base.ignore(key + '-up')
  255.             base.ignore(key + '-repeat')
  256.         if (self.hideSystemCursor):
  257.             self.props.setCursorHidden(False)
  258.             base.win.requestProperties(self.props)
  259.  
  260.     def enable(self):
  261.         self.enableInputHandling()
  262.         _renderingEnabled = True
  263.  
  264.     def disable(self):
  265.         self.disableInputHandling()
  266.         _renderingEnabled = False
  267.    
  268.     def captureKeys(self, key, keyTuple):
  269.         cegui_key = keyTuple[0]
  270.         key_ascii = keyTuple[1]
  271.         key_shift = keyTuple[2]
  272.         if key.find('shift') > 0:
  273.             if key.endswith('-up'):
  274.                 if self._shiftCount > 0:
  275.                     self._shiftCount -= 1
  276.             else:
  277.                 self._shiftCount += 1
  278.         elif key == 'caps_lock':
  279.             self._capsLock = not self._capsLock
  280.  
  281.         elif key.endswith('-up'):
  282.             self.System.injectKeyUp(cegui_key)
  283.         else:
  284.             self.System.injectKeyDown(cegui_key)
  285.             if key_ascii != '':
  286.                 if self._shiftCount > 0:
  287.                     if self._capsLock and key_ascii in string.lowercase:
  288.                         self.System.injectChar(ord(key_ascii))
  289.                     else:
  290.                         self.System.injectChar(ord(key_shift))
  291.                 elif self._capsLock and key_ascii in string.lowercase:
  292.                     self.System.injectChar(ord(key_shift))
  293.                 else:
  294.                     self.System.injectChar(ord(key_ascii))
  295.  
  296.     def captureButton(self, button, name):
  297.         if button == 'wheel_up':
  298.             self.System.injectMouseWheelChange(1)
  299.         elif button == 'wheel_down':
  300.             self.System.injectMouseWheelChange(-1)
  301.         elif button.endswith('-up'):
  302.             self.System.injectMouseButtonUp(self.buttons[button])
  303.         else:
  304.             self.System.injectMouseButtonDown(self.buttons[button])
  305.  
  306.     def windowEvent(self, window):
  307.         self.System.notifyDisplaySizeChanged(PyCEGUI.Size(window.getXSize(), window.getYSize()))
  308.  
  309.     def renderCallback(self, data):
  310.         self.queue()
  311.         if self._renderingEnabled:
  312.             dt = globalClock.getDt()
  313.             self.System.injectTimePulse(dt)
  314.             if base.mouseWatcherNode.hasMouse():
  315.                 x = base.win.getXSize() * (1 + base.mouseWatcherNode.getMouseX()) / 2
  316.                 y = base.win.getYSize() * (1 - base.mouseWatcherNode.getMouseY()) / 2
  317.                 self.System.injectMousePosition(x, y)
  318.             self.System.renderGUI()
  319.            
  320.     def queue(self):
  321.         global x
  322.         global username
  323.         global password
  324.         if x==0:
  325.             #must be called twice for some reason(bug?)
  326.             reactor.callFromThread(loginClicked, username, password)
  327.             reactor.callFromThread(loginClicked, username, password)
  328.             x=1
  329.         global queue
  330.         while not queue.empty():
  331.             callable=queue.get()
  332.             callable()
  333.             queue.task_done
  334.             global logged
  335.             if logged==True:
  336.                 layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("characters.layout")
  337.                 PyCEGUI.System.getSingleton().setGUISheet(layout)
  338.                 self.create=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Create")
  339.                 self.start=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Start")
  340.                 self.create.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'createCharacter')
  341.                 self.start.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'play')
  342.                 ###############################################
  343.                 self.human=self.loader.loadModel('./models/Human.x')
  344.                 self.human.reparentTo(self.render)
  345.                 self.human.setScale(9, 9, 9)
  346.                 self.human.setPos(-2, 50, 0)
  347.                 self.sword=self.loader.loadModel('./models/Sword.x')
  348.                 self.sword.reparentTo(self.human)
  349.                 self.sword.setScale(.03, .05, .05)
  350.                 self.sword.setPos(-.36, -.2, .57)
  351.                 self.sword.setHpr(-90,0,90)
  352.                 plight=PointLight('plight')
  353.                 plight.setColor(VBase4(1,1,1,1))
  354.                 plnp=self.render.attachNewNode(plight)
  355.                 plnp.setPos(7, 10, -2)
  356.                 render.setLight(plnp)
  357.                 ambientLight = AmbientLight('ambientLight')
  358.                 ambientLight.setColor(Vec4(0.2, 0.2, 0.2, 1))
  359.                 ambientLightNP = render.attachNewNode(ambientLight)
  360.                 render.setLight(ambientLightNP)
  361.                 ###################################################
  362.                 logged=False
  363.             return
  364.            
  365.     def play(self, args):
  366.         PyCEGUI.WindowManager.getSingleton().destroyWindow("Root")
  367.         layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("interface.layout")
  368.         PyCEGUI.System.getSingleton().setGUISheet(layout)
  369.         self.send=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Send")
  370.         self.send.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'sendMessage')
  371.         self.message=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Message")
  372.         self.chatbox=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Chatbox")
  373.         reactor.callFromThread(start)
  374.         global started
  375.         started=True
  376.        
  377.     def sendMessage(self, args):
  378.         global msg
  379.         global username
  380.         msg=self.message.getText()
  381.         self.message.setProperty("Text", "")
  382.         reactor.callInThread(messageSender)
  383.         msg=username+": "+msg
  384.         addMessage()
  385.  
  386. class MyApp(ShowBase, object):
  387.  
  388.     def __init__(self):
  389.         ShowBase.__init__(self)
  390.         self.CEGUI = PandaCEGUI()
  391.         self.CEGUI.initializeResources('./datafiles')
  392.         self.setupUI()
  393.         self.CEGUI.enable()
  394.  
  395.     def setupUI(self):
  396.         PyCEGUI.SchemeManager.getSingleton().create("VanillaSkin.scheme")
  397.         PyCEGUI.System.getSingleton().setDefaultFont("AnkeCalligraph")
  398.         PyCEGUI.System.getSingleton().setDefaultMouseCursor("Vanilla-Images", "MouseArrow")
  399.         layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("login.layout")
  400.         PyCEGUI.System.getSingleton().setGUISheet(layout)
  401.         self.loginWindow=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login")
  402.         self.submit=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Submit")
  403.         self.username=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Username")
  404.         self.password=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Password")
  405.         self.submit.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'login')
  406.         self.noUsername=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoUsername")
  407.         self.noUsernameOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoUsername/Ok")
  408.         self.noUsernameOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'noUsernameOkClicked')
  409.         self.noPassword=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoPassword")
  410.         self.noPasswordOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/NoPassword/Ok")
  411.         self.noPasswordOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'noPasswordOkClicked')
  412.         self.Incorrect=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Incorrect")
  413.         self.IncorrectOk=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Login/Incorrect/Ok")
  414.         self.IncorrectOk.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'incorrectOkClicked')
  415.  
  416.     def login(self, args):
  417.         self.username=self.username.getText()
  418.         if self.username=="":
  419.             self.noUsername.setProperty("Visible", "True")
  420.         else:
  421.             self.password=self.password.getText()
  422.             if password=="":
  423.                 self.noPassword.setProperty("Visible", "True")
  424.             else:
  425.                 global username
  426.                 username=self.username
  427.                 global x
  428.                 x=0
  429.                 global password
  430.                 password=self.password
  431.                
  432.     def noUsernameOkClicked(self,args):
  433.         self.noUsername.setProperty("Visible", "False")
  434.        
  435.     def noPasswordOkClicked(self,args):
  436.         self.noPassword.setProperty("Visible", "False")
  437.        
  438.     def incorrectOkClicked(self,args):
  439.         self.Incorrect.setProperty("Visible", "False")
  440.        
  441.     def createCharacter(self, args):
  442.         print "create"
  443.         PyCEGUI.WindowManager.getSingleton().destroyWindow("Root")
  444.        
  445.     def play(self, args):
  446.         PyCEGUI.WindowManager.getSingleton().destroyWindow("Root")
  447.         layout=PyCEGUI.WindowManager.getSingleton().loadWindowLayout("interface.layout")
  448.         PyCEGUI.System.getSingleton().setGUISheet(layout)
  449.         self.send=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Send")
  450.         self.send.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'sendMessage')
  451.         self.message=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Message")
  452.         self.chatbox=PyCEGUI.WindowManager.getSingleton().getWindow("Root/Chatbox")
  453.         reactor.callFromThread(start)
  454.         global started
  455.         started=True
  456.        
  457.     def sendMessage(self, args):
  458.         global msg
  459.         global username
  460.         msg=self.message.getText()
  461.         self.message.setProperty("Text", "")
  462.         reactor.callInThread(messageSender)
  463.         msg=username+": "+msg
  464.         addMessage()
  465.                
  466. class EchoClient(StatefulStringProtocol,Int32StringReceiver):
  467.     def connectionMade(self):
  468.         print "connected"
  469.  
  470.     def proto_init(self, data):
  471.         if data=="inv":
  472.             reactor.callInThread(inv)
  473.            
  474.         if data=="logged in":
  475.             reactor.callInThread(loggedin)
  476.         return 'init'
  477.  
  478.     def connectionLost(self, reason):
  479.         print "connection lost"
  480.        
  481. class chat(irc.IRCClient, protocol.ClientFactory):
  482.     def connectionMade(self):
  483.         irc.IRCClient.connectionMade(self)
  484.         print "connected"
  485.        
  486.     def connectionLost(self, reason):
  487.         pass
  488.        
  489.     def signedOn(self):
  490.         print "signed on"
  491.        
  492.     def joined(self, channel):
  493.         pass
  494.        
  495.     def privmsg(self, username, channel, message):
  496.         username = username.split('!', 1)[0]
  497.         global msg
  498.         global user
  499.         msg=message
  500.         user=username
  501.         reactor.callInThread(messageReceived)
  502.        
  503. class twistedThread(threading.Thread):
  504.     def run(self):
  505.         print "twisted thread"
  506.         creator = protocol.ClientCreator(reactor, EchoClient)
  507.         d = creator.connectTCP("localhost", 5000)
  508.         d.addCallback(gotProtocol)
  509.         e=protocol.ClientCreator(reactor, chat)
  510.         f= e.connectTCP("irc.mibbit.net", 6667)
  511.         f.addCallback(chatProtocol)
  512.         reactor.run(False)
  513.        
  514. twistedThread().start()
  515. app = MyApp()
  516. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement