This commit is contained in:
Stephen Dranger 2011-02-19 17:06:54 -06:00
parent fececa45ba
commit 3cbfc193b4
18 changed files with 137 additions and 205 deletions

2
TODO
View file

@ -1,5 +1,5 @@
Bugs: Bugs:
* heartbeat -- ping IRC occasionally so we pick up on send errors * idle doesnt seem to work?
* X and _ buttons move around all crazy like * X and _ buttons move around all crazy like
Features: Features:

BIN
convo.pyc

Binary file not shown.

Binary file not shown.

Binary file not shown.

48
irc.py
View file

@ -11,9 +11,9 @@ from generic import PesterList
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
class PesterIRC(QtCore.QObject): class PesterIRC(QtCore.QThread):
def __init__(self, config, window): def __init__(self, config, window):
QtCore.QObject.__init__(self) QtCore.QThread.__init__(self)
self.mainwindow = window self.mainwindow = window
self.config = config self.config = config
def IRCConnect(self): def IRCConnect(self):
@ -25,15 +25,41 @@ class PesterIRC(QtCore.QObject):
self.conn = self.cli.connect() self.conn = self.cli.connect()
self.brokenConnection = False self.brokenConnection = False
self.registeredIRC = False self.registeredIRC = False
def closeConnection(self): def run(self):
if self.cli: self.IRCConnect()
self.cli.close() while 1:
self.cli = None try:
def setConnectionBroken(self, broken=True): self.updateIRC()
self.brokenConnection = True except socket.error, se:
if self.registeredIRC:
self.stopIRC = None
else:
self.stopIRC = se
return
def setConnected(self): def setConnected(self):
self.registeredIRC = True self.registeredIRC = True
self.connected.emit() self.connected.emit()
def setConnectionBroken(self):
self.reconnectIRC()
#self.brokenConnection = True
@QtCore.pyqtSlot()
def updateIRC(self):
try:
res = self.conn.next()
except socket.timeout, se:
if self.registeredIRC:
return
else:
raise se
except socket.error, se:
raise se
except StopIteration:
pass
@QtCore.pyqtSlot()
def reconnectIRC(self):
self.cli.close()
@QtCore.pyqtSlot(PesterProfile) @QtCore.pyqtSlot(PesterProfile)
def getMood(self, *chums): def getMood(self, *chums):
self.cli.command_handler.getMood(*chums) self.cli.command_handler.getMood(*chums)
@ -163,12 +189,6 @@ class PesterIRC(QtCore.QObject):
helpers.mode(self.cli, c, m, cmd) helpers.mode(self.cli, c, m, cmd)
except socket.error: except socket.error:
self.setConnectionBroken() self.setConnectionBroken()
@QtCore.pyqtSlot()
def reconnectIRC(self):
self.setConnectionBroken()
def updateIRC(self):
return self.conn.next()
moodUpdated = QtCore.pyqtSignal(QtCore.QString, Mood) moodUpdated = QtCore.pyqtSignal(QtCore.QString, Mood)
colorUpdated = QtCore.pyqtSignal(QtCore.QString, QtGui.QColor) colorUpdated = QtCore.pyqtSignal(QtCore.QString, QtGui.QColor)

BIN
irc.pyc

Binary file not shown.

BIN
memos.pyc

Binary file not shown.

BIN
menus.pyc

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -82,6 +82,7 @@ class IRCClient:
... ...
""" """
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "initalizing socket %d" % (self.socket.fileno())
self.nick = None self.nick = None
self.real_name = None self.real_name = None
self.host = None self.host = None
@ -200,16 +201,16 @@ class IRCClient:
if self.socket: if self.socket:
logging.info('closing socket') logging.info('closing socket')
self.socket.close() self.socket.close()
print se
raise se raise se
else: else:
if self.socket: if self.socket:
logging.info('closing socket') logging.info('closing socket')
self.socket.close() self.socket.close()
def close(self): def close(self):
# with extreme prejudice
if self.socket: if self.socket:
logging.info('closing socket') logging.info('shutdown socket')
self.socket.close() self.socket.shutdown(socket.SHUT_RDWR)
class IRCApp: class IRCApp:
""" This class manages several IRCClient instances without the use of threads. """ This class manages several IRCClient instances without the use of threads.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -820,9 +820,6 @@ class PesterWindow(MovingWindow):
if not self.config.defaultprofile(): if not self.config.defaultprofile():
self.changeProfile() self.changeProfile()
self.loadingscreen = LoadingScreen(self)
self.connect(self.loadingscreen, QtCore.SIGNAL('rejected()'),
self, QtCore.SLOT('close()'))
def profile(self): def profile(self):
return self.userprofile.chat return self.userprofile.chat
@ -1618,6 +1615,9 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(QtCore.QString, QtCore.QString) @QtCore.pyqtSlot(QtCore.QString, QtCore.QString)
def nickCollision(self, handle, tmphandle): def nickCollision(self, handle, tmphandle):
self.mychumhandle.setText(tmphandle) self.mychumhandle.setText(tmphandle)
self.userprofile = userProfile(PesterProfile("pesterClient%d" % (random.randint(100,999)), QtGui.QColor("black"), Mood(0)))
self.changeTheme(self.userprofile.getTheme())
if not hasattr(self, 'chooseprofile'): if not hasattr(self, 'chooseprofile'):
self.chooseprofile = None self.chooseprofile = None
if not self.chooseprofile: if not self.chooseprofile:
@ -1660,44 +1660,6 @@ class PesterWindow(MovingWindow):
closeSignal = QtCore.pyqtSignal() closeSignal = QtCore.pyqtSignal()
reconnectIRC = QtCore.pyqtSignal() reconnectIRC = QtCore.pyqtSignal()
class IRCThread(QtCore.QThread):
def __init__(self, ircobj):
QtCore.QThread.__init__(self)
self.irc = ircobj
def run(self):
irc = self.irc
irc.IRCConnect()
timer = QtCore.QTimer(self)
self.connect(timer, QtCore.SIGNAL('timeout()'),
self, QtCore.SLOT('updateIRC()'))
timer.start()
self.exec_()
@QtCore.pyqtSlot()
def updateIRC(self):
irc = self.irc
if irc.brokenConnection:
irc.brokenConnection = False
self.restartIRC.emit()
irc.closeConnection()
irc.IRCConnect()
try:
res = irc.updateIRC()
except socket.timeout, se:
if not irc.registeredIRC:
irc.closeConnection()
self.failedIRC.emit("Connection timed out")
except socket.error, se:
if irc.registeredIRC:
irc.setConnectionBroken()
else:
irc.closeConnection()
self.failedIRC.emit(str(se))
except StopIteration:
pass
restartIRC = QtCore.pyqtSignal()
failedIRC = QtCore.pyqtSignal(QtCore.QString)
class PesterTray(QtGui.QSystemTrayIcon): class PesterTray(QtGui.QSystemTrayIcon):
def __init__(self, icon, mainwindow, parent): def __init__(self, icon, mainwindow, parent):
QtGui.QSystemTrayIcon.__init__(self, icon, parent) QtGui.QSystemTrayIcon.__init__(self, icon, parent)
@ -1764,164 +1726,113 @@ class MainProgram(QtCore.QObject):
QtCore.SLOT('mainWindowClosed()')) QtCore.SLOT('mainWindowClosed()'))
self.irc = PesterIRC(self.widget.config, self.widget) self.irc = PesterIRC(self.widget.config, self.widget)
self.connectWidgets(self.irc, self.widget) self.connect(self.irc, QtCore.SIGNAL('finished()'),
self.ircapp = IRCThread(self.irc)
self.connect(self.ircapp, QtCore.SIGNAL('restartIRC()'),
self, QtCore.SLOT('restartIRC()')) self, QtCore.SLOT('restartIRC()'))
self.connect(self.ircapp, QtCore.SIGNAL('failedIRC(QString)'), self.connectWidgets(self.irc, self.widget)
self, QtCore.SLOT('failedIRC(QString)'))
widget2irc = [('sendMessage(QString, QString)',
'sendMessage(QString, QString)'),
('newConvoStarted(QString, bool)',
'startConvo(QString, bool)'),
('convoClosed(QString)',
'endConvo(QString)'),
('profileChanged()',
'updateProfile()'),
('moodRequest(PyQt_PyObject)',
'getMood(PyQt_PyObject)'),
('moodsRequest(PyQt_PyObject)',
'getMoods(PyQt_PyObject)'),
('moodUpdated()', 'updateMood()'),
('mycolorUpdated()','updateColor()'),
('blockedChum(QString)', 'blockedChum(QString)'),
('unblockedChum(QString)', 'unblockedChum(QString)'),
('requestNames(QString)','requestNames(QString)'),
('requestChannelList()', 'requestChannelList()'),
('joinChannel(QString)', 'joinChannel(QString)'),
('leftChannel(QString)', 'leftChannel(QString)'),
('kickUser(QString, QString)',
'kickUser(QString, QString)'),
('setChannelMode(QString, QString, QString)',
'setChannelMode(QString, QString, QString)'),
('reconnectIRC()', 'reconnectIRC()')
]
# IRC --> Main window
irc2widget = [('connected()', 'connected()'),
('moodUpdated(QString, PyQt_PyObject)',
'updateMoodSlot(QString, PyQt_PyObject)'),
('colorUpdated(QString, QColor)',
'updateColorSlot(QString, QColor)'),
('messageReceived(QString, QString)',
'deliverMessage(QString, QString)'),
('memoReceived(QString, QString, QString)',
'deliverMemo(QString, QString, QString)'),
('nickCollision(QString, QString)',
'nickCollision(QString, QString)'),
('namesReceived(QString, PyQt_PyObject)',
'updateNames(QString, PyQt_PyObject)'),
('userPresentUpdate(QString, QString, QString)',
'userPresentUpdate(QString, QString, QString)'),
('channelListReceived(PyQt_PyObject)',
'updateChannelList(PyQt_PyObject)'),
('timeCommand(QString, QString, QString)',
'timeCommand(QString, QString, QString)')
]
def connectWidgets(self, irc, widget): def connectWidgets(self, irc, widget):
irc.connect(widget, QtCore.SIGNAL('sendMessage(QString, QString)'), for c in self.widget2irc:
irc, QtCore.SLOT('sendMessage(QString, QString)')) self.connect(widget, QtCore.SIGNAL(c[0]),
irc.connect(widget, irc, QtCore.SLOT(c[1]))
QtCore.SIGNAL('newConvoStarted(QString, bool)'), for c in self.irc2widget:
irc, QtCore.SLOT('startConvo(QString, bool)')) self.connect(irc, QtCore.SIGNAL(c[0]),
irc.connect(widget, widget, QtCore.SLOT(c[1]))
QtCore.SIGNAL('convoClosed(QString)'), def disconnectWidgets(self, irc, widget):
irc, QtCore.SLOT('endConvo(QString)')) for c in self.widget2irc:
irc.connect(widget, self.disconnect(widget, QtCore.SIGNAL(c[0]),
QtCore.SIGNAL('profileChanged()'), irc, QtCore.SLOT(c[1]))
irc, for c in self.irc2widget:
QtCore.SLOT('updateProfile()')) self.disconnect(irc, QtCore.SIGNAL(c[0]),
irc.connect(widget, widget, QtCore.SLOT(c[1]))
QtCore.SIGNAL('moodRequest(PyQt_PyObject)'),
irc,
QtCore.SLOT('getMood(PyQt_PyObject)'))
irc.connect(widget,
QtCore.SIGNAL('moodsRequest(PyQt_PyObject)'),
irc,
QtCore.SLOT('getMoods(PyQt_PyObject)'))
irc.connect(widget,
QtCore.SIGNAL('moodUpdated()'),
irc,
QtCore.SLOT('updateMood()'))
irc.connect(widget,
QtCore.SIGNAL('mycolorUpdated()'),
irc,
QtCore.SLOT('updateColor()'))
irc.connect(widget,
QtCore.SIGNAL('blockedChum(QString)'),
irc,
QtCore.SLOT('blockedChum(QString)'))
irc.connect(widget,
QtCore.SIGNAL('unblockedChum(QString)'),
irc,
QtCore.SLOT('unblockedChum(QString)'))
irc.connect(widget,
QtCore.SIGNAL('requestNames(QString)'),
irc,
QtCore.SLOT('requestNames(QString)'))
irc.connect(widget,
QtCore.SIGNAL('requestChannelList()'),
irc,
QtCore.SLOT('requestChannelList()'))
irc.connect(widget,
QtCore.SIGNAL('joinChannel(QString)'),
irc,
QtCore.SLOT('joinChannel(QString)'))
irc.connect(widget,
QtCore.SIGNAL('leftChannel(QString)'),
irc,
QtCore.SLOT('leftChannel(QString)'))
irc.connect(widget,
QtCore.SIGNAL('kickUser(QString, QString)'),
irc,
QtCore.SLOT('kickUser(QString, QString)'))
irc.connect(widget,
QtCore.SIGNAL('setChannelMode(QString, QString, QString)'),
irc,
QtCore.SLOT('setChannelMode(QString, QString, QString)'))
irc.connect(widget,
QtCore.SIGNAL('reconnectIRC()'),
irc,
QtCore.SLOT('reconnectIRC()'))
# IRC --> Main window def showLoading(self, widget, msg="CONN3CT1NG"):
irc.connect(irc, QtCore.SIGNAL('connected()'), self.widget.show()
widget, QtCore.SLOT('connected()')) self.widget.activateWindow()
irc.connect(irc, widget.loadingscreen = LoadingScreen(widget)
QtCore.SIGNAL('moodUpdated(QString, PyQt_PyObject)'), widget.loadingscreen.loadinglabel.setText(msg)
widget, self.connect(widget.loadingscreen, QtCore.SIGNAL('rejected()'),
QtCore.SLOT('updateMoodSlot(QString, PyQt_PyObject)')) widget, QtCore.SLOT('close()'))
irc.connect(irc, self.connect(self.widget.loadingscreen, QtCore.SIGNAL('tryAgain()'),
QtCore.SIGNAL('colorUpdated(QString, QColor)'), self, QtCore.SLOT('tryAgain()'))
widget, status = widget.loadingscreen.exec_()
QtCore.SLOT('updateColorSlot(QString, QColor)')) if status == QtGui.QDialog.Rejected:
irc.connect(irc, sys.exit(0)
QtCore.SIGNAL('messageReceived(QString, QString)'),
widget,
QtCore.SLOT('deliverMessage(QString, QString)'))
irc.connect(irc,
QtCore.SIGNAL('memoReceived(QString, QString, QString)'),
widget,
QtCore.SLOT('deliverMemo(QString, QString, QString)'))
irc.connect(irc,
QtCore.SIGNAL('nickCollision(QString, QString)'),
widget,
QtCore.SLOT('nickCollision(QString, QString)'))
irc.connect(irc,
QtCore.SIGNAL('namesReceived(QString, PyQt_PyObject)'),
widget,
QtCore.SLOT('updateNames(QString, PyQt_PyObject)'))
irc.connect(irc,
QtCore.SIGNAL('userPresentUpdate(QString, QString, QString)'),
widget,
QtCore.SLOT('userPresentUpdate(QString, QString, QString)'))
irc.connect(irc,
QtCore.SIGNAL('channelListReceived(PyQt_PyObject)'),
widget,
QtCore.SLOT('updateChannelList(PyQt_PyObject)'))
irc.connect(irc,
QtCore.SIGNAL('timeCommand(QString, QString, QString)'),
widget,
QtCore.SLOT('timeCommand(QString, QString, QString)'))
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def tryAgain(self): def tryAgain(self):
self.ircapp.quit() if self.loadingscreen:
print "Quit?" self.loadingscreen.accept()
self.restartIRC()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def restartIRC(self): def restartIRC(self):
# tell ppl that we're restarting if self.irc:
self.widget.show() self.disconnectWidgets(self.irc, self.widget)
self.widget.activateWindow() self.disconnect(self.irc, QtCore.SIGNAL('finished()'),
self.widget.loadingscreen = LoadingScreen(self.widget) self, QtCore.SLOT('restartIRC()'))
self.connect(self.widget.loadingscreen, QtCore.SIGNAL('rejected()'), stop = self.irc.stopIRC
self.widget, QtCore.SLOT('close()')) del self.irc
self.connect(self.widget.loadingscreen, QtCore.SIGNAL('tryAgain()'),
self, QtCore.SLOT('tryAgain()'))
status = self.widget.loadingscreen.exec_()
if status == QtGui.QDialog.Rejected:
sys.exit(0)
@QtCore.pyqtSlot(QtCore.QString)
def failedIRC(self, reason):
self.widget.show()
self.widget.activateWindow()
if not self.widget.loadingscreen:
self.widget.loadingscreen = LoadingScreen(self.widget)
self.widget.loadingscreen.loadinglabel.setText("F41L3D: %s" % (reason))
self.connect(self.widget.loadingscreen, QtCore.SIGNAL('rejected()'),
self.widget, QtCore.SLOT('close()'))
self.connect(self.widget.loadingscreen, QtCore.SIGNAL('tryAgain()'),
self, QtCore.SLOT('tryAgain()'))
status = self.widget.loadingscreen.exec_()
if status == QtGui.QDialog.Rejected:
sys.exit(0)
else: else:
self.widget.loadingscreen.loadinglabel.setText("F41L3D: %s" % (reason)) stop = None
if not stop:
self.irc = PesterIRC(self.widget.config, self.widget)
self.connect(self.irc, QtCore.SIGNAL('finished()'),
self, QtCore.SLOT('restartIRC()'))
self.connectWidgets(self.irc, self.widget)
self.irc.start()
self.showLoading(self.widget)
else:
self.showLoading(self.widget, "F41L3D: %s" % stop)
def run(self): def run(self):
self.ircapp.start() self.irc.start()
self.widget.loadingscreen = LoadingScreen(self.widget) self.showLoading(self.widget)
self.connect(self.widget.loadingscreen, QtCore.SIGNAL('rejected()'),
self.widget, QtCore.SLOT('close()'))
self.connect(self.widget.loadingscreen, QtCore.SIGNAL('tryAgain()'),
self, QtCore.SLOT('tryAgain()'))
status = self.widget.loadingscreen.exec_()
if status == QtGui.QDialog.Rejected:
sys.exit(0)
sys.exit(self.app.exec_()) sys.exit(self.app.exec_())
pesterchum = MainProgram() pesterchum = MainProgram()