Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- from twisted.internet import wxreactor
- #wxreactor.install()
- from twisted.spread import pb
- from twisted.internet import reactor, threads
- from twisted.cred import credentials
- import getpass
- class ChatC(pb.Referenceable):
- def connect(self):
- # who = str(getpass.getuser()).upper()
- name = raw_input("Username: ")
- factory = pb.PBClientFactory()
- #open connection
- reactor.connectTCP("localhost", 1025, factory)
- def1 = factory.login(credentials.UsernamePassword(name, "none"), client=self)
- def1.addCallback(self.joinGroup)
- #factory.getRootObject().addCallback(self.joinGroup)
- reactor.run()
- def joinGroup(self, user):
- #recieve and store avatar object remote reference
- print "got perspective/user ref:", user
- self.user = user #the user object for this client instance...keep around!
- groupN = raw_input('Group Name: ')
- g = user.callRemote('joinGroup', groupN)
- print "joined group!"
- g.addCallback(self.chat)
- #need to wait for user input and execute remote_print from server at the same time.
- #threads? stackless? stdio?
- def chat(self, group):
- #take input from GUI
- d = threads.deferToThread(self.write)
- d.addCallback(lambda message: group.callRemote('send', message))
- d.addCallback(self.chat)
- # message = self.write()
- #send to server
- # s = group.callRemote('send', message)
- # s.addCallback(self.chat)
- def write(self):
- message = raw_input(": ")
- return message
- def remote_print(self, message):
- print "(S) %s" % (message)
- # self.chat(groupObj)
- def end(self):
- reactor.stop()
- # def userList(self):
- # #list of online users
- # #accept selections
- # pass
- # INTERFACE
- # [http://wiki.wxpython.org/wxPythonAndTwisted]
- #class Interface(wx.Frame):
- # def __init__(self):
- # wx.Frame.__init__(self, None, -1, "Test Chat", size = (400, 200))
- # panel = wx.Panel(self)
- # notebook = Notebook(panel)
- # sizer = wx.BoxSizer(wx.VERTICAL)
- # sizer.Add(notebook, 1, wx.EXPAND, 5)
- # panel.SetSizer(sizer)
- # self.Layout()
- # self.Show()
- #class Notebook(wx.Notebook):
- # def __init__(self, parent):
- # wx.Notebook.__init__(self, parent, -1, size = (380, 180), name = 'Chat')
- # self.AddPage(ChatPanel(self), 'Chat')
- # self.AddPage(ControlPanel(self), 'Controls')
- # #create a generic tab creation function linked to click-on-online user/joining new groups
- # #add tab(s) to chat tab
- # sizer = wx.BoxSizer()
- # sizer.Add(self, 0, wx.EXPAND)
- # self.SetSizer(sizer)
- # self.Layout()
- # #add readonly and message entry textboxes to every chat tab
- #class ChatPanel(wx.Panel):
- # def __init__(self, parent):
- # wx.Panel.__init__(self, parent = parent, id=wx.ID_ANY)
- # sizer = wx.BoxSizer(wx.VERTICAL)
- # self.text = wx.TextCtrl(self, style = wx.TE_MULTILINE | wx.TE_READONLY)
- # self.ctrl = wx.TextCtrl(self, style = wx.TE_PROCESS_ENTER, size=(200, 25))
- # sizer.Add(self.text, 5, wx.EXPAND)
- # sizer.Add(self.ctrl, 0, wx.EXPAND)
- # self.SetSizer(sizer)
- # self.ctrl.Bind(wx.EVT_TEXT_ENTER, self.send)
- # self.Layout()
- ## connect to client's remote_print and write methods
- # def send(self, event):
- # message = str(self.ctrl.GetValue())
- # self.ctrl.SetValue("")
- #class ControlPanel(wx.Panel):
- # def __init__(self, parent):
- # wx.Panel.__init__(self, parent = parent, id=wx.ID_ANY)
- # sizer = wx.BoxSizer(wx.VERTICAL)
- # self.userList = [] #ChatC().user.callRemote('userList')
- # self.listCtrl = wx.ListCtrl(self, size=(-1,100))
- # self.listCtrl.InsertColumn(0, '')
- # self.listCtrl.InsertColumn(1, 'User')
- #
- # i = 0
- # for user in self.userList:
- # line = i
- # self.list_ctrl.InsertStringItem(i, line)
- # self.list_ctrl.SetStringItem(i, 1, name)
- # self.list_ctrl.SetStringItem(i, 2, "online")
- # i += 1
- #
- # sizer.Add(self.listCtrl, 0, wx.ALL|wx.EXPAND, 5)
- # self.SetSizer(sizer)
- # self.Layout()
- if __name__ == "__main__":
- # app = wx.App(False)
- # frame = Interface()
- # frame.Show()
- ChatC().connect()
- # app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement