Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import wx
  4.  
  5. import thread
  6. import os
  7. import sys
  8.  
  9. from twisted.words.protocols import irc
  10. from twisted.internet import protocol
  11. from twisted.internet import reactor
  12.  
  13. class MainFrame(wx.Frame):
  14.     """Class with the GUI and GUI functions"""
  15.     def __init__(self, parent,id):
  16.         """Displays the frame, creates the GUI"""
  17.        
  18.         self.mybot = MyBot()
  19.         #self.mybotfactory = MyBotFactory()
  20.        
  21.         wx.Frame.__init__(self, parent,id,'IRC Client', size=(410,475))
  22.         self.create_gui()
  23.        
  24.        
  25.        
  26.     def create_gui(self):
  27.         """Creates and shows the GUI"""
  28.         self.text_output=wx.TextCtrl(self,size=(400,400),pos=(5,5),
  29.                                      style=wx.TE_MULTILINE)
  30.         self.text_input=wx.TextCtrl(self,size=(400,-1),pos=(5,415))
  31.  
  32.         self.send_message=wx.Button(self,1,"Submit",size=(400,-1),pos=(5,445))
  33.  
  34. class MyBot(irc.IRCClient):
  35.  
  36.     def _get_nickname(self):
  37.         return self.factory.nickname
  38.  
  39.     nickname = property(_get_nickname)
  40.  
  41.     def signedOn(self):
  42.         self.join(self.factory.channel)
  43.  
  44.     def joined(self, channel):
  45.         print "*** Joined %s" % channel
  46.         self.myDict = {}
  47.  
  48.     def privmsg(self, user, channel, msg):
  49.         user = user.split('!')[0]
  50.  
  51. class MyBotFactory(protocol.ClientFactory):
  52.     protocol = MyBot
  53.  
  54.     def __init__(self, channel, nickname='davidg'):
  55.         self.channel = channel
  56.         self.nickname = nickname
  57.  
  58.     def clientConnectionLost(self, connector, reason):
  59.         print "Lost connection (%s), reconnecting." % (reason,)
  60.         connector.connect()
  61.  
  62.     def clientConnectionFailed(self, connector, reason):
  63.         print "Could not connect: %s" % (reason,)
  64.  
  65. def connect_irc():
  66.     network = 'irc.freenode.net'
  67.     reactor.connectTCP(network, 6667, MyBotFactory('#python-forum'))
  68.     reactor.run()
  69.  
  70. def start_window():
  71.     app = wx.PySimpleApp()
  72.     frame = MainFrame(parent=None, id=-1)
  73.     frame.Show()
  74.     app.MainLoop()
  75.  
  76. def main():
  77.     try:
  78.         thread.start_new_thread(connect_irc,())
  79.         thread.start_new_thread(start_window,())
  80.     except:
  81.         print "Error: unable to start thread"
  82.  
  83. if __name__ == "__main__":
  84.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement