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 Client(pb.Referenceable):
- def connect(self):
- #who = str(getpass.getuser()).upper()
- name = "USER" #raw_input("Username: ")
- client = self
- app = wx.App(False)
- frame = Interface()
- factory = pb.PBClientFactory(frame)
- from twisted.internet import reactor #test if this is really required (and why?!)
- reactor.registerWxApp(app)
- reactor.connectTCP("localhost", 1025, factory)
- def1 = factory.login(credentials.UsernamePassword(name, "none"), client)
- def1.addCallback(client.connection)
- reactor.run()
- def connection(self, userObj):
- #recieve and store avatar object remote reference
- self.user = userObj #the user object for this client instance...keep around!
- #print "got perspective/user ref:", self.user
- self.returnUser()
- def returnUser(self):
- print self.user
- return self.user
- def send(self, message, group):
- group.callRemote('send', message)
- class Interface(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self, None, -1, "Test Chat", size = (300, 400))
- 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 = (280, 380), name = 'Chat')
- chat = ChatBox(self)
- user = UserPanel(self)
- group = GroupPanel(self)
- self.AddPage(chat, 'Chat')
- self.AddPage(user, 'Users')
- self.AddPage(group, 'Groups')
- sizer = wx.BoxSizer()
- sizer.Add(self, 0, wx.EXPAND)
- self.SetSizer(sizer)
- self.Layout()
- #creates a space for notebook chat pages
- class ChatBox(wx.Notebook):
- def __init__(self, parent):
- wx.Notebook.__init__(self, parent, -1, size = (280, 380), style = wx.NB_RIGHT, name = 'Chat Box')
- groupN = "Example"
- #use this to make a new tab for each new chat:
- self.newChat(groupN)
- sizer = wx.BoxSizer()
- sizer.Add(self, 0, wx.EXPAND)
- self.SetSizer(sizer)
- self.Layout()
- def newChat(self, groupN):
- chat = ChatPanel(self)
- self.AddPage(chat, groupN)
- #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, 50))
- 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())
- print message
- #send to server
- client.send(message)
- self.ctrl.SetValue("")
- class UserPanel(wx.Panel):
- def __init__(self, parent):
- wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
- sizer = wx.BoxSizer(wx.VERTICAL)
- uList = ['test', 'another', 'something', 'else'] #client.returnUL()
- #self.userList = ['test', 'another', 'one more'] #ChatC().user.callRemote('userList')
- self.listbox = wx.ListBox(self, -1, size =(270, 380), style = wx.LB_HSCROLL)
- for userN in uList:
- self.listbox.Append(userN)
- sizer.Add(self.listbox, 0, wx.ALL|wx.EXPAND, 5)
- self.SetSizer(sizer)
- self.Layout()
- class GroupPanel(wx.Panel):
- def __init__(self, parent):
- wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
- sizer = wx.BoxSizer(wx.VERTICAL)
- #get group list from server
- gList = ['test', 'another', 'something', 'else'] # client.returnGL()
- #groupList = ['something', 'else', 'other']
- self.listbox = wx.ListBox(self, -1, size =(270, 380), style = wx.LB_HSCROLL)
- for groupN in gList:
- self.listbox.Append(groupN)
- sizer.Add(self.listbox, 0, wx.ALL|wx.EXPAND, 5)
- self.SetSizer(sizer)
- self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnClick, self.listbox)
- self.Layout()
- #does not work: TODO
- def OnClick(self, event):
- #get the name [groupN]
- groupN = event.GetText()
- #call joinGroup (server) with that name
- #add a tab to the ChatBox [ChatBox.newChat(groupN)]
- parent.chat.newChat(groupN)
- if __name__ == "__main__":
- Client().connect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement