Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import wx
- import thread
- import os
- import sys
- from twisted.words.protocols import irc
- from twisted.internet import protocol
- from twisted.internet import reactor
- class MainFrame(wx.Frame):
- """Class with the GUI and GUI functions"""
- def __init__(self, parent,id):
- """Displays the frame, creates the GUI"""
- self.mybot = MyBot()
- #self.mybotfactory = MyBotFactory()
- wx.Frame.__init__(self, parent,id,'IRC Client', size=(410,475))
- self.create_gui()
- def create_gui(self):
- """Creates and shows the GUI"""
- self.text_output=wx.TextCtrl(self,size=(400,400),pos=(5,5),
- style=wx.TE_MULTILINE)
- self.text_input=wx.TextCtrl(self,size=(400,-1),pos=(5,415))
- self.send_message=wx.Button(self,1,"Submit",size=(400,-1),pos=(5,445))
- class MyBot(irc.IRCClient):
- def _get_nickname(self):
- return self.factory.nickname
- nickname = property(_get_nickname)
- def signedOn(self):
- self.join(self.factory.channel)
- def joined(self, channel):
- print "*** Joined %s" % channel
- self.myDict = {}
- def privmsg(self, user, channel, msg):
- user = user.split('!')[0]
- class MyBotFactory(protocol.ClientFactory):
- protocol = MyBot
- def __init__(self, channel, nickname='davidg'):
- self.channel = channel
- self.nickname = nickname
- def clientConnectionLost(self, connector, reason):
- print "Lost connection (%s), reconnecting." % (reason,)
- connector.connect()
- def clientConnectionFailed(self, connector, reason):
- print "Could not connect: %s" % (reason,)
- def connect_irc():
- network = 'irc.freenode.net'
- reactor.connectTCP(network, 6667, MyBotFactory('#python-forum'))
- reactor.run()
- def start_window():
- app = wx.PySimpleApp()
- frame = MainFrame(parent=None, id=-1)
- frame.Show()
- app.MainLoop()
- def main():
- try:
- thread.start_new_thread(connect_irc,())
- thread.start_new_thread(start_window,())
- except:
- print "Error: unable to start thread"
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement