From 28f476e7fdbb0a9b064d07cba2536f0773513086 Mon Sep 17 00:00:00 2001 From: Stephen Dranger Date: Fri, 28 Jan 2011 00:08:56 -0600 Subject: [PATCH] profiles pt.2, dealt with pointer/mutable issures --- TODO | 4 ++ oyoyo/__init__.pyc | Bin 333 -> 333 bytes oyoyo/client.pyc | Bin 9728 -> 9728 bytes oyoyo/cmdhandler.pyc | Bin 8312 -> 8312 bytes oyoyo/helpers.pyc | Bin 4044 -> 4044 bytes oyoyo/ircevents.pyc | Bin 5693 -> 5693 bytes oyoyo/parse.pyc | Bin 2869 -> 2869 bytes pesterchum.js | 2 +- pesterchum.py | 131 ++++++++++++++++++++----------------- themes/pesterchum/style.js | 2 +- 10 files changed, 77 insertions(+), 62 deletions(-) diff --git a/TODO b/TODO index 1d7d6d8..339bcc9 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,15 @@ Features: * Profile management +* pesterchum:begin +* changeColor +* protect against messages from yourself :P * Theme Changing * Handle user signoffs * Logging * Moods * Add chum * REMOVE chum +* Sounds * New message reminder * User profile options * Quirks diff --git a/oyoyo/__init__.pyc b/oyoyo/__init__.pyc index be26c04278418a75756d2cf8046f30e23a4107ba..28e3e80c476d1ac01bd4cfb463eeb187f0612c7e 100644 GIT binary patch delta 15 WcmX@hbe4(j;wN6NbFmxQ+!+BfRRyU4 delta 15 XcmX@hbe4(j;wN6Nd*3&*xibO)HMa&+ diff --git a/oyoyo/client.pyc b/oyoyo/client.pyc index 08d3b013fe5f0b5668cbd1136ac7c611e46875ec..ad7d9f762837f88938fa10bd13f344b041befc5c 100644 GIT binary patch delta 15 WcmZqhY4BmY_=%V6TSqCHl diff --git a/oyoyo/cmdhandler.pyc b/oyoyo/cmdhandler.pyc index e9def19d77978e0983f9458c1605a5ac084df2c3..d97b3d1ff2c4eb42e44ae39815380e44fd3c0833 100644 GIT binary patch delta 15 Wcmez2@WX-a;wN6NbFmxQiWC4n$_B*% delta 15 Xcmez2@WX-a;wN6Nd*3&*6)6A!K`aMv diff --git a/oyoyo/helpers.pyc b/oyoyo/helpers.pyc index c0234d25d072796f8b388b87b552b1546ccf3529..89ddc32e0cd6dc88371e9adf1eaa78565bca880a 100644 GIT binary patch delta 16 YcmX>je@34D;wN6N$F5Er*^lxA06cRBt^fc4 delta 16 YcmX>je@34D;wN6N&p#bEvLEFK06`W9aR2}S diff --git a/oyoyo/ircevents.pyc b/oyoyo/ircevents.pyc index 1f1ccd60b234136833f75055fd8d2e431da22511..c83999f5508b0e331f132f84e784455707b3e147 100644 GIT binary patch delta 15 Wcmdn1vsZ`h;wN6NbFmxQ%*6mS&IRHC delta 15 Xcmdn1vsZ`h;wN6Nd*3&*nTr7cI4}l` diff --git a/oyoyo/parse.pyc b/oyoyo/parse.pyc index e67f2eacb08e566bee9472177a2c6889c2828d09..9095b24ca7fdd4567a86d7cbbd0c9a4cc710c079 100644 GIT binary patch delta 15 WcmdlgwpEPn;wN6NbFmxQ^tk~smj#mm delta 15 XcmdlgwpEPn;wN6Nd*3&*>2m`BH2DTS diff --git a/pesterchum.js b/pesterchum.js index 049a185..d44f809 100644 --- a/pesterchum.js +++ b/pesterchum.js @@ -1 +1 @@ -{"tabs": true, "theme": "pesterchum", "chums": ["gamblingGenocider", "grimAuxiliatrix", "gardenGnostic", "ghostDunk", "spaceGhost", "aquaMarinist", "carcinoGeneticist", "tentacleTherapist"]} \ No newline at end of file +{"tabs": false, "theme": "pesterchum", "chums": ["gamblingGenocider", "grimAuxiliatrix", "gardenGnostic", "ghostDunk", "spaceGhost", "aquaMarinist", "carcinoGeneticist", "tentacleTherapist"]} \ No newline at end of file diff --git a/pesterchum.py b/pesterchum.py index ade7f1e..c290f3e 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -47,6 +47,10 @@ class PesterProfile(object): def colorcmd(self): (r, g, b, a) = self.color.getRgb() return "%d,%d,%d" % (r,g,b) + def update(self, newprofile): + self.handle = newprofile.handle + self.color = newprofile.color + self.mood = newprofile.mood class pesterTheme(dict): def __init__(self, name): @@ -74,18 +78,17 @@ class userConfig(object): fp = open("pesterchum.js") self.config = json.load(fp) fp.close() - self.defaulttheme = pesterTheme("pesterchum") if self.config.has_key("defaultprofile"): - self.profile = userProfile(self.config["defaultprofile"]) + self.userprofile = userProfile(self.config["defaultprofile"]) else: - self.profile = None + self.userprofile = None def chums(self): return self.config['chums'] - def getTheme(self): - if self.profile: - return self.profile.getTheme() - else: - return self.defaulttheme + def defaultprofile(self): + try: + return self.config['defaultprofile'] + except KeyError: + return None def tabs(self): return self.config["tabs"] def set(self, item, setting): @@ -142,7 +145,7 @@ class pesterQuirks(object): self.quirklist = quirklist class PesterChooseProfile(QtGui.QDialog): - def __init__(self, userprofile, config, theme, parent): + def __init__(self, userprofile, config, theme, parent, collision=None): QtGui.QDialog.__init__(self, parent) self.userprofile = userprofile self.theme = theme @@ -186,6 +189,9 @@ class PesterChooseProfile(QtGui.QDialog): layout_ok.addWidget(self.ok) layout_0 = QtGui.QVBoxLayout() + if collision: + collision_warning = QtGui.QLabel("%s is taken already! Pick a new profile." % (collision)) + layout_0.addWidget(collision_warning) layout_0.addLayout(layout_1) if avail_profiles: profileLabel = QtGui.QLabel("Or choose an existing profile:", self) @@ -264,9 +270,9 @@ class WMButton(QtGui.QPushButton): self.setAutoDefault(False) class chumListing(QtGui.QListWidgetItem): - def __init__(self, chum, theme): + def __init__(self, chum, window): QtGui.QListWidgetItem.__init__(self, chum.handle) - self.theme = theme + self.window = window self.chum = chum self.handle = chum.handle self.setMood(Mood("offline")) @@ -276,16 +282,18 @@ class chumListing(QtGui.QListWidgetItem): def updateMood(self): mood = self.chum.mood self.mood = mood - self.setIcon(self.mood.icon(self.theme)) - self.setTextColor(QtGui.QColor(self.theme["main/chums/moods"][self.mood.name()]["color"])) + self.setIcon(self.mood.icon(self.window.theme)) + self.setTextColor(QtGui.QColor(self.window.theme["main/chums/moods"][self.mood.name()]["color"])) def __lt__(self, cl): h1 = self.handle.lower() h2 = cl.handle.lower() return (h1 < h2) class chumArea(QtGui.QListWidget): - def __init__(self, chums, theme, parent=None): + def __init__(self, chums, parent=None): QtGui.QListWidget.__init__(self, parent) + self.window = parent + theme = self.window.theme geometry = theme["main/chums/loc"] + theme["main/chums/size"] self.setGeometry(*geometry) self.setStyleSheet(theme["main/chums/style"]) @@ -293,7 +301,7 @@ class chumArea(QtGui.QListWidget): for c in self.chums: chandle = c.handle if not self.findItems(chandle, QtCore.Qt.MatchFlags(0)): - chumLabel = chumListing(c, theme) + chumLabel = chumListing(c, self.window) self.addItem(chumLabel) self.sortItems() def updateMood(self, handle, mood): @@ -326,9 +334,8 @@ class PesterTabWindow(QtGui.QFrame): def __init__(self, mainwindow, parent=None): QtGui.QFrame.__init__(self, parent) self.mainwindow = mainwindow - self.theme = mainwindow.theme - self.resize(*self.theme["convo/size"]) - self.setStyleSheet(self.theme["convo/style"]) + self.resize(*self.mainwindow.theme["convo/size"]) + self.setStyleSheet(self.mainwindow.theme["convo/style"]) self.tabs = QtGui.QTabBar(self) self.tabs.setTabsClosable(True) @@ -336,7 +343,7 @@ class PesterTabWindow(QtGui.QFrame): self, QtCore.SLOT('changeTab(int)')) self.connect(self.tabs, QtCore.SIGNAL('tabCloseRequested(int)'), self, QtCore.SLOT('tabClose(int)')) - self.tabs.setShape(self.theme["convo/tabstyle"]) + self.tabs.setShape(self.mainwindow.theme["convo/tabstyle"]) self.layout = QtGui.QVBoxLayout() @@ -354,7 +361,7 @@ class PesterTabWindow(QtGui.QFrame): newindex = self.tabs.addTab(convo.chum.handle) self.tabIndices[convo.chum.handle] = newindex self.tabs.setCurrentIndex(newindex) - self.tabs.setTabIcon(newindex, convo.chum.mood.icon(self.theme)) + self.tabs.setTabIcon(newindex, convo.chum.mood.icon(self.mainwindow.theme)) def showChat(self, handle): self.tabs.setCurrentIndex(self.tabIndices[handle]) def keyPressEvent(self, event): @@ -370,7 +377,7 @@ class PesterTabWindow(QtGui.QFrame): self.close() def updateMood(self, handle, mood): i = self.tabIndices[handle] - self.tabs.setTabIcon(i, mood.icon(self.theme)) + self.tabs.setTabIcon(i, mood.icon(self.mainwindow.theme)) def closeEvent(self, event): if not self.softclose: while self.tabs.count() > 0: @@ -411,7 +418,7 @@ class PesterTabWindow(QtGui.QFrame): self.layout.removeWidget(self.currentConvo) self.currentConvo = convo self.layout.addWidget(convo) - self.setWindowIcon(convo.chum.mood.icon(self.theme)) + self.setWindowIcon(convo.chum.mood.icon(self.mainwindow.theme)) self.setWindowTitle(convo.chum.handle) self.activateWindow() self.raise_() @@ -442,18 +449,17 @@ class PesterConvo(QtGui.QFrame): QtGui.QFrame.__init__(self, parent) self.chum = chum - self.theme = mainwindow.theme self.mainwindow = mainwindow - convo = self.theme["convo"] + convo = self.mainwindow.theme["convo"] self.resize(*convo["size"]) self.setStyleSheet(convo["style"]) - self.setWindowIcon(chum.mood.icon(self.theme)) + self.setWindowIcon(chum.mood.icon(self.mainwindow.theme)) self.setWindowTitle(chum.handle) self.chumLabel = QtGui.QLabel(chum.handle, self) - self.chumLabel.setStyleSheet(self.theme["convo/chumlabel/style"]) - self.textArea = PesterText(self.theme, self) - self.textInput = PesterInput(self.theme, self) + self.chumLabel.setStyleSheet(self.mainwindow.theme["convo/chumlabel/style"]) + self.textArea = PesterText(self.mainwindow.theme, self) + self.textInput = PesterInput(self.mainwindow.theme, self) self.textInput.setFocus() self.connect(self.textInput, QtCore.SIGNAL('returnPressed()'), @@ -473,7 +479,7 @@ class PesterConvo(QtGui.QFrame): if self.parent(): self.parent().updateMood(self.chum.handle, mood) else: - self.setWindowIcon(mood.icon(self.theme)) + self.setWindowIcon(mood.icon(self.mainwindow.theme)) # print mood update? def addMessage(self, text, me=True): if me: @@ -511,7 +517,16 @@ class PesterWindow(MovingWindow): flags=QtCore.Qt.CustomizeWindowHint) self.setObjectName("main") self.config = userConfig() - self.theme = self.config.getTheme() + if self.config.defaultprofile(): + self.userprofile = userProfile(self.config.defaultprofile()) + self.profile = self.userprofile.chat + self.theme = self.userprofile.getTheme() + else: + self.userprofile = userProfile(PesterProfile("pesterClient%d" % (random.randint(100,999)), QtGui.QColor("black"), Mood(0))) + self.profile = self.userprofile.chat + self.theme = self.userprofile.getTheme() + self.changeProfile() + main = self.theme["main"] size = main['size'] self.setGeometry(100, 100, size[0], size[1]) @@ -544,18 +559,9 @@ class PesterWindow(MovingWindow): self, QtCore.SLOT('showMinimized()')) chums = [PesterProfile(c) for c in set(self.config.chums())] - self.chumList = chumArea(chums, self.theme, self) + self.chumList = chumArea(chums, self) self.connect(self.chumList, QtCore.SIGNAL('itemDoubleClicked(QListWidgetItem *)'), self, QtCore.SLOT('newConversationWindow(QListWidgetItem *)')) - if self.config.profile: - pass - #self.userprofile = self.config.profile - #self.profile = self.userprofile.chat - else: - self.userprofile = userProfile(PesterProfile("pesterClient%d" % (random.randint(100,999)), QtGui.QColor("black"), Mood(0))) - self.profile = self.userprofile.chat - self.chooseprofile = PesterChooseProfile(self.userprofile, self.config, self.theme, self) - self.chooseprofile.exec_() self.convos = {} self.tabconvo = None @@ -609,6 +615,11 @@ class PesterWindow(MovingWindow): self.connect(self.tabconvo, QtCore.SIGNAL('windowClosed()'), self, QtCore.SLOT('tabsClosed()')) + def changeProfile(self, collision=None): + self.chooseprofile = PesterChooseProfile(self.userprofile, self.config, self.theme, self, collision=collision) + self.chooseprofile.exec_() + + @QtCore.pyqtSlot(QtGui.QListWidgetItem) def newConversationWindow(self, chumlisting): chum = chumlisting.chum @@ -708,24 +719,24 @@ class PesterWindow(MovingWindow): def closeProfile(self): self.chooseprofile = None - @QtCore.pyqtSlot() - def nickCollision(self): - pass + @QtCore.pyqtSlot(QtCore.QString) + def nickCollision(self, handle): + if not self.chooseprofile: + h = unicode(handle) + self.changeProfile(collision=h) newConvoStarted = QtCore.pyqtSignal(QtCore.QString, bool, name="newConvoStarted") sendMessage = QtCore.pyqtSignal(QtCore.QString, PesterProfile) convoClosed = QtCore.pyqtSignal(QtCore.QString) class PesterIRC(QtCore.QObject): - def __init__(self, profile, chums): + def __init__(self, window): QtCore.QObject.__init__(self) - self.profile = profile - self.chums = chums + self.window = window def IRCConnect(self): - self.cli = IRCClient(PesterHandler, host="irc.tymoon.eu", port=6667, nick=self.profile.handle, blocking=True) + self.cli = IRCClient(PesterHandler, host="irc.tymoon.eu", port=6667, nick=self.window.profile.handle, blocking=True) self.cli.command_handler.parent = self - self.cli.command_handler.profile = self.profile - self.cli.command_handler.chums = self.chums + self.cli.command_handler.window = self.window self.conn = self.cli.connect() def getMood(self, *chums): @@ -741,7 +752,7 @@ class PesterIRC(QtCore.QObject): h = str(handle) if initiated: helpers.msg(self.cli, h, "PESTERCHUM:BEGIN") - helpers.msg(self.cli, h, "COLOR >%s" % (self.profile.colorcmd())) + helpers.msg(self.cli, h, "COLOR >%s" % (self.window.profile.colorcmd())) @QtCore.pyqtSlot(QtCore.QString) def endConvo(self, handle): h = str(handle) @@ -754,7 +765,7 @@ class PesterIRC(QtCore.QObject): colorUpdated = QtCore.pyqtSignal(QtCore.QString, QtGui.QColor) pesterchumBegin = QtCore.pyqtSignal(PesterProfile) messageReceived = QtCore.pyqtSignal(QtCore.QString, QtCore.QString) - nickCollision = QtCore.pyqtSignal() + nickCollision = QtCore.pyqtSignal(QtCore.QString) class PesterHandler(DefaultCommandHandler): def privmsg(self, nick, chan, msg): @@ -772,8 +783,8 @@ class PesterHandler(DefaultCommandHandler): mood = Mood(0) self.parent.moodUpdated.emit(handle, mood) elif msg[0:7] == "GETMOOD": - mychumhandle = self.profile.handle - mymood = self.profile.mood.value() + mychumhandle = self.window.profile.handle + mymood = self.window.profile.mood.value() if msg.find(mychumhandle, 8) != -1: helpers.msg(self.client, "#pesterchum", "MOOD >%d" % (mymood)) @@ -797,16 +808,16 @@ class PesterHandler(DefaultCommandHandler): def welcome(self, server, nick, msg): helpers.join(self.client, "#pesterchum") - mychumhandle = self.profile.handle - mymood = self.profile.mood.value() + mychumhandle = self.window.profile.handle + mymood = self.window.profile.mood.value() helpers.msg(self.client, "#pesterchum", "MOOD >%d" % (mymood)) - chums = self.chums + chums = self.window.chumList.chums self.getMood(*chums) def nicknameinuse(self, server, cmd, nick, msg): helpers.nick(self.client, "pesterClient%d" % (random.randint(100,999))) - self.parent().emit.nickCollision.emit() + self.parent.nickCollision.emit(nick) def getMood(self, *chums): chumglub = "GETMOOD " for c in chums: @@ -838,7 +849,7 @@ def main(): trayicon.setContextMenu(traymenu) trayicon.show() - irc = PesterIRC(widget.profile, widget.chumList.chums) + irc = PesterIRC(widget) irc.IRCConnect() irc.connect(widget, QtCore.SIGNAL('sendMessage(QString, PyQt_PyObject)'), irc, QtCore.SLOT('sendMessage(QString, PyQt_PyObject)')) @@ -865,9 +876,9 @@ def main(): widget, QtCore.SLOT('deliverMessage(QString, QString)')) irc.connect(irc, - QtCore.SIGNAL('nickCollision()'), + QtCore.SIGNAL('nickCollision(QString)'), widget, - QtCore.SLOT('nickCollision()')) + QtCore.SLOT('nickCollision(QString)')) ircapp = IRCThread(irc) ircapp.start() diff --git a/themes/pesterchum/style.js b/themes/pesterchum/style.js index 53aded7..4f5614e 100644 --- a/themes/pesterchum/style.js +++ b/themes/pesterchum/style.js @@ -21,7 +21,7 @@ "color": "red" } } }, - "defaultwindow": { "style": "background: #fdb302; font-family:'Courier New';font:bold;" + "defaultwindow": { "style": "background: #fdb302; font-family:'Courier New';font:bold;selection-background-color:#919191; " }, "labels": { "mychumhandle": "MYCHUMHANDLE" }, "elements": [