def __init__(self, parent=None) : QWidget.__init__(self, parent) self.ui = Ui_sonicIRC() self.ui.setupUi(self) self.ui.plainTextEdit.setReadOnly(True) QObject.connect(self.ui.lineEdit, SIGNAL("returnPressed()"), self.textappend) self.ui.lineEdit.tabPressed.connect(self.completeText) self.threads = [] for x in range(len(conf.hosts)) : self.threads.append(sonicIRCConnection()) self.connect(self.ui.listWidget, SIGNAL("currentTextChanged(const QString&)"), self.selectchannel) self.connect(self.threads[x], SIGNAL("newmessage"), self.textset) self.connect(self.threads[x], SIGNAL("/names"), self.ui.listWidget_2.addItem) self.connect(self.threads[x], SIGNAL("SelfJoin"), self.selfjoin) self.connect(self.threads[x], SIGNAL("SelfPart"), self.removeChannel) self.connect(self.threads[x], SIGNAL("NewJoin"), self.newjoin) self.connect(self.threads[x], SIGNAL("NewPart"), self.newpart) self.connect(self.threads[x], SIGNAL("SayHey"), self.sayhey) self.connect(self.threads[x], SIGNAL("NickChange"), self.nickchange)
class sonicIRCWindow(QMainWindow) : def __init__(self, parent=None) : QWidget.__init__(self, parent) self.ui = Ui_sonicIRC() self.ui.setupUi(self) self.ui.plainTextEdit.setReadOnly(True) QObject.connect(self.ui.lineEdit, SIGNAL("returnPressed()"), self.textappend) self.ui.lineEdit.tabPressed.connect(self.completeText) self.threads = [] for x in range(len(conf.hosts)) : self.threads.append(sonicIRCConnection()) self.connect(self.ui.listWidget, SIGNAL("currentTextChanged(const QString&)"), self.selectchannel) self.connect(self.threads[x], SIGNAL("newmessage"), self.textset) self.connect(self.threads[x], SIGNAL("/names"), self.ui.listWidget_2.addItem) self.connect(self.threads[x], SIGNAL("SelfJoin"), self.selfjoin) self.connect(self.threads[x], SIGNAL("SelfPart"), self.removeChannel) self.connect(self.threads[x], SIGNAL("NewJoin"), self.newjoin) self.connect(self.threads[x], SIGNAL("NewPart"), self.newpart) self.connect(self.threads[x], SIGNAL("SayHey"), self.sayhey) self.connect(self.threads[x], SIGNAL("NickChange"), self.nickchange) def newconnection(self, host, port, channels) : conf.hosts.append(host) conf.ports.append(int(port)) conf.channels[host] = channels x = len(self.threads) self.threads.append(sonicIRCConnection()) self.connect(self.ui.listWidget, SIGNAL("currentTextChanged(const QString&)"), self.selectchannel) self.connect(self.threads[x], SIGNAL("newmessage"), self.textset) self.connect(self.threads[x], SIGNAL("/names"), self.ui.listWidget_2.addItem) self.connect(self.threads[x], SIGNAL("SelfJoin"), self.selfjoin) self.connect(self.threads[x], SIGNAL("SelfPart"), self.removeChannel) self.connect(self.threads[x], SIGNAL("NewJoin"), self.newjoin) self.connect(self.threads[x], SIGNAL("NewPart"), self.newpart) self.connect(self.threads[x], SIGNAL("SayHey"), self.sayhey) self.connect(self.threads[x], SIGNAL("NickChange"), self.nickchange) def completeText(self) : text = str(self.ui.lineEdit.text()) if text != "" : channel = self.ui.listWidget.item(self.ui.listWidget.currentRow()) if channel : host = str(channel.text()).split("/", 1)[0] channel = str(channel.text()).split("/", 1)[1] word = text.split(" ")[-1] if word != "" : newword = word for nick in world.connections[host].channels[channel] : if nick.lower().startswith(word.lower()): newword = nick break if len(text.split(" ")) == 1 : self.ui.lineEdit.setText(newword + ": ") elif len(text.split(" ")) > 1 : self.ui.lineEdit.setText("%s %s " % (" ".join(text.split(" ")[:-1]), newword)) def nickchange(self, channel) : if channel == str(self.ui.listWidget.item(self.ui.listWidget.currentRow()).text()) : self.ui.listWidget_2.clear() self.ui.listWidget_2.addItems(world.connections[channel.split("/", 1)[0]].channels[channel.split("/", 1)[1]]) def sayhey(self) : QSound.play("hey.wav") def selfjoin(self, channel) : total = [world.connections[a].channellist for a in [b for b in conf.hosts]] newtotal = [] for network in total : for chnl in network : newtotal.append(chnl) self.ui.listWidget.clear() self.ui.listWidget.addItems(newtotal) self.selectchannel(channel) self.ui.listWidget.setCurrentItem(self.ui.listWidget.findItems(channel, Qt.MatchFixedString)[0]) self.ui.listWidget.setItemSelected(self.ui.listWidget.item(self.ui.listWidget.currentRow()), True) def newjoin(self, channel, sender) : if channel == str(self.ui.listWidget.item(self.ui.listWidget.currentRow()).text()) : self.ui.listWidget_2.addItem(sender) def removeChannel(self, channel) : host = channel.split("/", 1)[0] channel = channel.split("/", 1)[1] total = [world.connections[a].channellist for a in [b for b in conf.hosts]] newtotal = [] for network in total : for chnl in network : newtotal.append(chnl) self.ui.listWidget.clear() self.ui.listWidget.addItems(newtotal) self.selectchannel(world.connections[host].channellist[0]) self.ui.listWidget.setCurrentItem(self.ui.listWidget.item(len(world.connections[host].channellist) - 1)) self.ui.listWidget.setItemSelected(self.ui.listWidget.item(self.ui.listWidget.currentRow()), True) def newpart(self, host, channel, sender) : if channel == str(self.ui.listWidget.item(self.ui.listWidget.currentRow()).text()) : self.ui.listWidget_2.clear() self.ui.listWidget_2.addItems(world.connections[host].channels[channel]) def selectchannel(self, text) : if str(text) != "" : channel = str(text).split("/", 1)[1] host = str(text).split("/", 1)[0] self.textset(str(text), world.connections[host].scrollback[channel]) self.ui.listWidget_2.clear() self.ui.listWidget_2.addItems(world.connections[host].channels[channel]) def textappend2(self, text) : self.ui.plainTextEdit.appendPlainText(text) self.ui.plainTextEdit.verticalScrollBar().setValue(self.ui.plainTextEdit.verticalScrollBar().maximum()) def textset(self, channel, text) : channel2 = self.ui.listWidget.item(self.ui.listWidget.currentRow()) if channel2 : channel2 = str(channel2.text()) if channel == channel2 : self.ui.plainTextEdit.setPlainText(text) self.ui.plainTextEdit.verticalScrollBar().setValue(self.ui.plainTextEdit.verticalScrollBar().maximum()) def textappend(self) : text = str(self.ui.lineEdit.text()) channel = self.ui.listWidget.item(self.ui.listWidget.currentRow()) if channel : host = str(channel.text()).split("/", 1)[0] channel = str(channel.text()).split("/", 1)[1] words = text.split(" ") if text.startswith("/") : if words[0] == "/me" : world.connections[host].ircsend(channel, "\x01ACTION %s\x01" % (" ".join(words[1:]))) elif words[0] == "/quit" : world.connections[host].rawsend("QUIT :Leaving...\n") world.connections[host].sock.close() elif words[0] == "/eval" : self.textappend2(repr(eval(" ".join(words[1:]))) + "\n") elif words[0] == "/join" : world.connections[host].rawsend("JOIN %s\n" % (words[1])) elif words[0] == "/connect" : self.newconnection(words[1], words[2], words[3:]) elif words[0] == "/part" : if len(words) == 1 and channel.startswith("#") : world.connections[host].rawsend("PART %s\n" % (channel)) elif len(words) == 1 and not channel.startswith("#") : del world.connections[host].channels[channel] world.connections[host].channellist.remove("%s/%s" % (host, channel)) self.removeChannel("%s/%s" % (host, channel)) elif len(words) == 2 : if words[1].startswith("#") : world.connections[host].rawsend("PART %s\n" % (words[1])) elif not words[1].startswith("#") : del world.connections[host].channels[channel] world.connections[host].channellist.remove("%s/%s" % (host, words[1])) self.removeChannel("%s/%s" % (host, words[1])) elif words[0] == "/quote" : world.connections[host].rawsend("%s\n" % (" ".join(words[1:]))) elif words[0] == "/ctcp" : world.connections[host].ircsend(words[1], "\x01%s\x01\n" % (words[2])) else : world.connections[host].ircsend(channel, text) self.ui.lineEdit.setText("") self.ui.plainTextEdit.verticalScrollBar().setValue(self.ui.plainTextEdit.verticalScrollBar().maximum())