Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 552 lines (505 sloc) 24.721 kb
79e4de5 illuminatedwax fdfdas
authored
1 from string import Template
2 import re
2dbd124 sounds, idle, etc
Stephen Dranger authored
3 from datetime import datetime, timedelta
79e4de5 illuminatedwax fdfdas
authored
4 from PyQt4 import QtGui, QtCore
5
547fdb7 illuminatedwax fds
authored
6 from dataobjs import PesterProfile, Mood, PesterHistory
a58dbe2 illuminatedwax 0.0.10
authored
7 from generic import PesterIcon, RightClickList
79e4de5 illuminatedwax fdfdas
authored
8 from parsetools import escapeBrackets, convertTags
9
10 class PesterTabWindow(QtGui.QFrame):
3bafa1e more memo work
Stephen Dranger authored
11 def __init__(self, mainwindow, parent=None, convo="convo"):
79e4de5 illuminatedwax fdfdas
authored
12 QtGui.QFrame.__init__(self, parent)
13 self.setFocusPolicy(QtCore.Qt.ClickFocus)
14 self.mainwindow = mainwindow
15
16 self.tabs = QtGui.QTabBar(self)
17 self.tabs.setTabsClosable(True)
18 self.connect(self.tabs, QtCore.SIGNAL('currentChanged(int)'),
19 self, QtCore.SLOT('changeTab(int)'))
20 self.connect(self.tabs, QtCore.SIGNAL('tabCloseRequested(int)'),
21 self, QtCore.SLOT('tabClose(int)'))
22
3bafa1e more memo work
Stephen Dranger authored
23 self.initTheme(self.mainwindow.theme[convo])
79e4de5 illuminatedwax fdfdas
authored
24 self.layout = QtGui.QVBoxLayout()
25 self.layout.setContentsMargins(0,0,0,0)
26 self.layout.addWidget(self.tabs)
27 self.setLayout(self.layout)
28 self.convos = {}
29 self.tabIndices = {}
30 self.currentConvo = None
31 self.changedTab = False
32 self.softclose = False
33
3bafa1e more memo work
Stephen Dranger authored
34 self.type = convo
35
79e4de5 illuminatedwax fdfdas
authored
36 # get default tab color i guess
37 self.defaultTabTextColor = self.getTabTextColor()
3bafa1e more memo work
Stephen Dranger authored
38
79e4de5 illuminatedwax fdfdas
authored
39 def getTabTextColor(self):
40 # ugly, ugly hack
41 self.changedTab = True
42 i = self.tabs.addTab(".")
43 c = self.tabs.tabTextColor(i)
44 self.tabs.removeTab(i)
45 self.changedTab = False
46 return c
47 def addChat(self, convo):
3bafa1e more memo work
Stephen Dranger authored
48 self.convos[convo.title()] = convo
79e4de5 illuminatedwax fdfdas
authored
49 # either addTab or setCurrentIndex will trigger changed()
3bafa1e more memo work
Stephen Dranger authored
50 newindex = self.tabs.addTab(convo.title())
51 self.tabIndices[convo.title()] = newindex
79e4de5 illuminatedwax fdfdas
authored
52 self.tabs.setCurrentIndex(newindex)
3bafa1e more memo work
Stephen Dranger authored
53 self.tabs.setTabIcon(newindex, convo.icon())
79e4de5 illuminatedwax fdfdas
authored
54 def showChat(self, handle):
55 tabi = self.tabIndices[handle]
56 if self.tabs.currentIndex() == tabi:
57 self.activateWindow()
58 self.raise_()
59 self.convos[handle].raiseChat()
60 else:
61 self.tabs.setCurrentIndex(tabi)
62
63 def convoHasFocus(self, convo):
64 if ((self.hasFocus() or self.tabs.hasFocus()) and
3bafa1e more memo work
Stephen Dranger authored
65 self.tabs.tabText(self.tabs.currentIndex()) == convo.title()):
79e4de5 illuminatedwax fdfdas
authored
66 return True
67
68 def keyPressEvent(self, event):
69 keypress = event.key()
70 mods = event.modifiers()
71 if ((mods & QtCore.Qt.ControlModifier) and
72 keypress == QtCore.Qt.Key_Tab):
87cbeca illuminatedwax fdsafd
authored
73 handles = self.convos.keys()
74 waiting = self.mainwindow.waitingMessages.waitingHandles()
75 waitinghandles = list(set(handles) & set(waiting))
76 if len(waitinghandles) > 0:
77 nexti = self.tabIndices[waitinghandles[0]]
78 else:
79 nexti = (self.tabIndices[self.currentConvo.title()] + 1) % self.tabs.count()
79e4de5 illuminatedwax fdfdas
authored
80 self.tabs.setCurrentIndex(nexti)
81
82 def closeSoft(self):
83 self.softclose = True
84 self.close()
85 def updateBlocked(self, handle):
86 i = self.tabIndices[handle]
87 icon = QtGui.QIcon(self.mainwindow.theme["main/chums/moods/blocked/icon"])
88 self.tabs.setTabIcon(i, icon)
89 if self.tabs.currentIndex() == i:
90 self.setWindowIcon(icon)
91 def updateMood(self, handle, mood, unblocked=False):
92 i = self.tabIndices[handle]
93 if handle in self.mainwindow.config.getBlocklist() and not unblocked:
94 icon = QtGui.QIcon(self.mainwindow.theme["main/chums/moods/blocked/icon"])
95 else:
96 icon = mood.icon(self.mainwindow.theme)
97 self.tabs.setTabIcon(i, icon)
98 if self.tabs.currentIndex() == i:
99 self.setWindowIcon(icon)
100 def closeEvent(self, event):
101 if not self.softclose:
102 while self.tabs.count() > 0:
103 self.tabClose(0)
104 self.windowClosed.emit()
105 def focusInEvent(self, event):
106 # make sure we're not switching tabs!
107 i = self.tabs.tabAt(self.mapFromGlobal(QtGui.QCursor.pos()))
108 if i == -1:
109 i = self.tabs.currentIndex()
110 handle = unicode(self.tabs.tabText(i))
111 self.clearNewMessage(handle)
112 def convoHasFocus(self, handle):
113 i = self.tabIndices[handle]
114 if (self.tabs.currentIndex() == i and
115 (self.hasFocus() or self.tabs.hasFocus())):
116 return True
117 else:
118 return False
119
120 def notifyNewMessage(self, handle):
121 i = self.tabIndices[handle]
3bafa1e more memo work
Stephen Dranger authored
122 self.tabs.setTabTextColor(i, QtGui.QColor(self.mainwindow.theme["%s/tabs/newmsgcolor" % (self.type)]))
79e4de5 illuminatedwax fdfdas
authored
123 convo = self.convos[handle]
124 def func():
125 convo.showChat()
126 self.mainwindow.waitingMessages.addMessage(handle, func)
127 # set system tray
128 def clearNewMessage(self, handle):
129 try:
130 i = self.tabIndices[handle]
131 self.tabs.setTabTextColor(i, self.defaultTabTextColor)
132 except KeyError:
133 pass
134 self.mainwindow.waitingMessages.messageAnswered(handle)
3bafa1e more memo work
Stephen Dranger authored
135 def initTheme(self, convo):
136 self.resize(*convo["size"])
e39590d illuminatedwax fsdd
authored
137 self.setStyleSheet(convo["tabs"]["style"])
3bafa1e more memo work
Stephen Dranger authored
138 self.tabs.setShape(convo["tabs"]["tabstyle"])
139 self.tabs.setStyleSheet("QTabBar::tab{ %s } QTabBar::tab:selected { %s }" % (convo["tabs"]["style"], convo["tabs"]["selectedstyle"]))
140
79e4de5 illuminatedwax fdfdas
authored
141 def changeTheme(self, theme):
e39590d illuminatedwax fsdd
authored
142 self.initTheme(theme["convo"])
79e4de5 illuminatedwax fdfdas
authored
143 for c in self.convos.values():
3790bc1 illuminatedwax fds
authored
144 tabi = self.tabIndices[c.title()]
145 self.tabs.setTabIcon(tabi, c.icon())
79e4de5 illuminatedwax fdfdas
authored
146 currenttabi = self.tabs.currentIndex()
147 if currenttabi >= 0:
148 currentHandle = unicode(self.tabs.tabText(self.tabs.currentIndex()))
3790bc1 illuminatedwax fds
authored
149 self.setWindowIcon(self.convos[currentHandle].icon())
79e4de5 illuminatedwax fdfdas
authored
150 self.defaultTabTextColor = self.getTabTextColor()
151
152 @QtCore.pyqtSlot(int)
153 def tabClose(self, i):
154 handle = unicode(self.tabs.tabText(i))
155 self.mainwindow.waitingMessages.messageAnswered(handle)
156 convo = self.convos[handle]
157 del self.convos[handle]
158 del self.tabIndices[handle]
159 self.tabs.removeTab(i)
160 for (h, j) in self.tabIndices.iteritems():
161 if j > i:
162 self.tabIndices[h] = j-1
163 self.layout.removeWidget(convo)
164 convo.close()
165 if self.tabs.count() == 0:
166 self.close()
167 return
168 if self.currentConvo == convo:
169 currenti = self.tabs.currentIndex()
170 currenth = unicode(self.tabs.tabText(currenti))
171 self.currentConvo = self.convos[currenth]
172 self.currentConvo.raiseChat()
173
174 @QtCore.pyqtSlot(int)
175 def changeTab(self, i):
176 if i < 0:
177 return
178 if self.changedTab:
179 self.changedTab = False
180 return
181 handle = unicode(self.tabs.tabText(i))
182 convo = self.convos[handle]
183 if self.currentConvo:
184 self.layout.removeWidget(self.currentConvo)
185 self.currentConvo = convo
186 self.layout.addWidget(convo)
3bafa1e more memo work
Stephen Dranger authored
187 self.setWindowIcon(convo.icon())
188 self.setWindowTitle(convo.title())
79e4de5 illuminatedwax fdfdas
authored
189 self.activateWindow()
190 self.raise_()
191 convo.raiseChat()
192
193 windowClosed = QtCore.pyqtSignal()
194
195 class PesterText(QtGui.QTextEdit):
196 def __init__(self, theme, parent=None):
197 QtGui.QTextEdit.__init__(self, parent)
7e3f40a illuminatedwax fds
authored
198 self.initTheme(theme)
79e4de5 illuminatedwax fdfdas
authored
199 self.setReadOnly(True)
200 self.setMouseTracking(True)
7e3f40a illuminatedwax fds
authored
201 def initTheme(self, theme):
202 if theme.has_key("convo/scrollbar"):
203 self.setStyleSheet("QTextEdit { %s } QScrollBar:vertical { %s } QScrollBar::handle:vertical { %s } QScrollBar::add-line:vertical { %s } QScrollBar::sub-line:vertical { %s } QScrollBar:up-arrow:vertical { %s } QScrollBar:down-arrow:vertical { %s }" % (theme["convo/textarea/style"], theme["convo/scrollbar/style"], theme["convo/scrollbar/handle"], theme["convo/scrollbar/downarrow"], theme["convo/scrollbar/uparrow"], theme["convo/scrollbar/uarrowstyle"], theme["convo/scrollbar/darrowstyle"] ))
204 else:
205 self.setStyleSheet("QTextEdit { %s }" % (theme["convo/textarea/style"]))
79e4de5 illuminatedwax fdfdas
authored
206 def addMessage(self, text, chum):
207 color = chum.colorhtml()
208 systemColor = QtGui.QColor(self.parent().mainwindow.theme["convo/systemMsgColor"])
209 initials = chum.initials()
210 msg = unicode(text)
211 parent = self.parent()
212 window = parent.mainwindow
213 me = window.profile()
214 if msg == "PESTERCHUM:BEGIN":
215 parent.setChumOpen(True)
216 msg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"])
217 window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
218 self.append(convertTags(msg))
219 elif msg == "PESTERCHUM:CEASE":
220 parent.setChumOpen(False)
221 msg = chum.pestermsg(me, systemColor, window.theme["convo/text/ceasepester"])
222 window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
223 self.append(convertTags(msg))
224 elif msg == "PESTERCHUM:BLOCK":
225 msg = chum.pestermsg(me, systemColor, window.theme['convo/text/blocked'])
226 window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
227 self.append(convertTags(msg))
228 elif msg == "PESTERCHUM:UNBLOCK":
229 msg = chum.pestermsg(me, systemColor, window.theme['convo/text/unblocked'])
230 window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
231 self.append(convertTags(msg))
2dbd124 sounds, idle, etc
Stephen Dranger authored
232 elif msg == "PESTERCHUM:BLOCKED":
233 msg = chum.pestermsg(me, systemColor, window.theme['convo/text/blockedmsg'])
234 window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
235 self.append(convertTags(msg))
236 elif msg == "PESTERCHUM:IDLE":
237 msg = chum.idlemsg(systemColor, window.theme['convo/text/idle'])
238 window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
239 self.append(convertTags(msg))
79e4de5 illuminatedwax fdfdas
authored
240 elif msg[0:3] == "/me" or msg[0:13] == "PESTERCHUM:ME":
241 if msg[0:3] == "/me":
242 start = 3
243 else:
244 start = 13
245 space = msg.find(" ")
246 msg = chum.memsg(systemColor, msg[start:space], msg[space:])
247 if chum is me:
248 window.chatlog.log(parent.chum.handle, convertTags(msg, "bbcode"))
249 else:
250 window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
251 self.append(convertTags(msg))
252 else:
253 if not parent.chumopen and chum is not me:
254 beginmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"])
255 parent.setChumOpen(True)
256 window.chatlog.log(chum.handle, convertTags(beginmsg, "bbcode"))
257 self.append(convertTags(beginmsg))
258
259 msg = escapeBrackets(msg)
99a49ef fdssfa
Stephen Dranger authored
260 msg = "<c=%s>%s: %s</c>" % (color, initials, msg)
79e4de5 illuminatedwax fdfdas
authored
261 self.append(convertTags(msg))
262 if chum is me:
263 window.chatlog.log(parent.chum.handle, convertTags(msg, "bbcode"))
264 else:
2dbd124 sounds, idle, etc
Stephen Dranger authored
265 if window.idle:
266 idlethreshhold = 60
267 if (not hasattr(self, 'lastmsg')) or \
268 datetime.now() - self.lastmsg > timedelta(0,60):
269 parent.messageSent.emit("PESTERCHUM:IDLE", parent.title())
270 self.lastmsg = datetime.now()
79e4de5 illuminatedwax fdfdas
authored
271 window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
272 def changeTheme(self, theme):
7e3f40a illuminatedwax fds
authored
273 self.initTheme(theme)
79e4de5 illuminatedwax fdfdas
authored
274 sb = self.verticalScrollBar()
275 sb.setValue(sb.maximum())
276 def focusInEvent(self, event):
277 self.parent().clearNewMessage()
278 QtGui.QTextEdit.focusInEvent(self, event)
279
280 def mousePressEvent(self, event):
281 url = self.anchorAt(event.pos())
282 if url != "":
a58dbe2 illuminatedwax 0.0.10
authored
283 if url[0] == "#" and url != "#pesterchum":
284 self.parent().mainwindow.showMemos(url[1:])
285 else:
286 QtGui.QDesktopServices.openUrl(QtCore.QUrl(url, QtCore.QUrl.TolerantMode))
79e4de5 illuminatedwax fdfdas
authored
287 QtGui.QTextEdit.mousePressEvent(self, event)
288 def mouseMoveEvent(self, event):
289 QtGui.QTextEdit.mouseMoveEvent(self, event)
290 if self.anchorAt(event.pos()):
291 if self.viewport().cursor().shape != QtCore.Qt.PointingHandCursor:
292 self.viewport().setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
293 else:
294 self.viewport().setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
295
296 class PesterInput(QtGui.QLineEdit):
297 def __init__(self, theme, parent=None):
298 QtGui.QLineEdit.__init__(self, parent)
299 self.setStyleSheet(theme["convo/input/style"])
300 def changeTheme(self, theme):
301 self.setStyleSheet(theme["convo/input/style"])
302 def focusInEvent(self, event):
303 self.parent().clearNewMessage()
304 QtGui.QLineEdit.focusInEvent(self, event)
547fdb7 illuminatedwax fds
authored
305 def keyPressEvent(self, event):
306 if event.key() == QtCore.Qt.Key_Up:
307 text = unicode(self.text())
308 next = self.parent().history.next(text)
309 if next is not None:
310 self.setText(next)
311 elif event.key() == QtCore.Qt.Key_Down:
312 prev = self.parent().history.prev()
313 if prev is not None:
314 self.setText(prev)
315 elif event.key() in [QtCore.Qt.Key_PageUp, QtCore.Qt.Key_PageDown]:
316 self.parent().textArea.keyPressEvent(event)
2dbd124 sounds, idle, etc
Stephen Dranger authored
317 self.parent().mainwindow.idletime = 0
547fdb7 illuminatedwax fds
authored
318 QtGui.QLineEdit.keyPressEvent(self, event)
319
79e4de5 illuminatedwax fdfdas
authored
320
321 class PesterConvo(QtGui.QFrame):
322 def __init__(self, chum, initiated, mainwindow, parent=None):
323 QtGui.QFrame.__init__(self, parent)
7e3f40a illuminatedwax fds
authored
324 self.setObjectName(chum.handle)
79e4de5 illuminatedwax fdfdas
authored
325 self.setFocusPolicy(QtCore.Qt.ClickFocus)
326 self.chum = chum
327 self.mainwindow = mainwindow
328 convo = self.mainwindow.theme["convo"]
329 self.resize(*convo["size"])
7e3f40a illuminatedwax fds
authored
330 self.setStyleSheet("QFrame { %s }" % convo["style"])
3bafa1e more memo work
Stephen Dranger authored
331 self.setWindowIcon(self.icon())
332 self.setWindowTitle(self.title())
79e4de5 illuminatedwax fdfdas
authored
333
334 t = Template(self.mainwindow.theme["convo/chumlabel/text"])
335
336 self.chumLabel = QtGui.QLabel(t.safe_substitute(handle=chum.handle), self)
337 self.chumLabel.setStyleSheet(self.mainwindow.theme["convo/chumlabel/style"])
338 self.chumLabel.setAlignment(self.aligndict["h"][self.mainwindow.theme["convo/chumlabel/align/h"]] | self.aligndict["v"][self.mainwindow.theme["convo/chumlabel/align/v"]])
339 self.chumLabel.setMaximumHeight(self.mainwindow.theme["convo/chumlabel/maxheight"])
340 self.chumLabel.setMinimumHeight(self.mainwindow.theme["convo/chumlabel/minheight"])
341 self.chumLabel.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Expanding))
342 self.textArea = PesterText(self.mainwindow.theme, self)
343 self.textInput = PesterInput(self.mainwindow.theme, self)
344 self.textInput.setFocus()
345
346 self.connect(self.textInput, QtCore.SIGNAL('returnPressed()'),
347 self, QtCore.SLOT('sentMessage()'))
348
349 self.layout = QtGui.QVBoxLayout()
350 self.layout.addWidget(self.chumLabel)
351 self.layout.addWidget(self.textArea)
352 self.layout.addWidget(self.textInput)
353 self.layout.setSpacing(0)
354 margins = self.mainwindow.theme["convo/margins"]
355 self.layout.setContentsMargins(margins["left"], margins["top"],
356 margins["right"], margins["bottom"])
357
358 self.setLayout(self.layout)
359
a58dbe2 illuminatedwax 0.0.10
authored
360 self.optionsMenu = QtGui.QMenu(self)
361 self.optionsMenu.setStyleSheet(self.mainwindow.theme["main/defaultwindow/style"])
362 self.addChumAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/addchum"], self)
363 self.connect(self.addChumAction, QtCore.SIGNAL('triggered()'),
364 self, QtCore.SLOT('addThisChum()'))
365 self.blockAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/blockchum"], self)
366 self.connect(self.blockAction, QtCore.SIGNAL('triggered()'),
367 self, QtCore.SLOT('blockThisChum()'))
368 self.quirksOff = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/quirksoff"], self)
369 self.quirksOff.setCheckable(True)
370 self.connect(self.quirksOff, QtCore.SIGNAL('toggled(bool)'),
371 self, QtCore.SLOT('toggleQuirks(bool)'))
2dbd124 sounds, idle, etc
Stephen Dranger authored
372 self.unblockchum = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/unblockchum"], self)
373 self.connect(self.unblockchum, QtCore.SIGNAL('triggered()'),
374 self, QtCore.SLOT('unblockChumSlot()'))
375
a58dbe2 illuminatedwax 0.0.10
authored
376 self.optionsMenu.addAction(self.quirksOff)
377 self.optionsMenu.addAction(self.addChumAction)
378 self.optionsMenu.addAction(self.blockAction)
379
79e4de5 illuminatedwax fdfdas
authored
380 self.chumopen = False
a58dbe2 illuminatedwax 0.0.10
authored
381 self.applyquirks = True
79e4de5 illuminatedwax fdfdas
authored
382
383 if parent:
384 parent.addChat(self)
385 if initiated:
386 msg = self.mainwindow.profile().pestermsg(self.chum, QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"]), self.mainwindow.theme["convo/text/beganpester"])
387 self.setChumOpen(True)
388 self.textArea.append(convertTags(msg))
3bafa1e more memo work
Stephen Dranger authored
389 self.mainwindow.chatlog.log(self.title(), convertTags(msg, "bbcode"))
79e4de5 illuminatedwax fdfdas
authored
390 self.newmessage = False
547fdb7 illuminatedwax fds
authored
391 self.history = PesterHistory()
79e4de5 illuminatedwax fdfdas
authored
392
3bafa1e more memo work
Stephen Dranger authored
393 def title(self):
394 return self.chum.handle
395 def icon(self):
396 return self.chum.mood.icon(self.mainwindow.theme)
397
f1aff28 smilies!
Stephen Dranger authored
398 def updateMood(self, mood, unblocked=False, old=None):
399 syscolor = QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"])
79e4de5 illuminatedwax fdfdas
authored
400 if mood.name() == "offline" and self.chumopen == True and not unblocked:
2dbd124 sounds, idle, etc
Stephen Dranger authored
401 self.mainwindow.ceasesound.play()
f1aff28 smilies!
Stephen Dranger authored
402 msg = self.chum.pestermsg(self.mainwindow.profile(), syscolor, self.mainwindow.theme["convo/text/ceasepester"])
79e4de5 illuminatedwax fdfdas
authored
403 self.textArea.append(convertTags(msg))
3bafa1e more memo work
Stephen Dranger authored
404 self.mainwindow.chatlog.log(self.title(), convertTags(msg, "bbcode"))
79e4de5 illuminatedwax fdfdas
authored
405 self.chumopen = False
f1aff28 smilies!
Stephen Dranger authored
406 elif old and old.name() != mood.name():
87cbeca illuminatedwax fdsafd
authored
407 msg = self.chum.moodmsg(mood, syscolor, self.mainwindow.theme)
f1aff28 smilies!
Stephen Dranger authored
408 self.textArea.append(convertTags(msg))
409 self.mainwindow.chatlog.log(self.title(), convertTags(msg, "bbcode"))
79e4de5 illuminatedwax fdfdas
authored
410 if self.parent():
3bafa1e more memo work
Stephen Dranger authored
411 self.parent().updateMood(self.title(), mood, unblocked)
79e4de5 illuminatedwax fdfdas
authored
412 else:
413 if self.chum.blocked(self.mainwindow.config) and not unblocked:
414 self.setWindowIcon(QtGui.QIcon(self.mainwindow.theme["main/chums/moods/blocked/icon"]))
2dbd124 sounds, idle, etc
Stephen Dranger authored
415 self.optionsMenu.addAction(self.unblockchum)
416 self.optionsMenu.removeAction(self.blockAction)
79e4de5 illuminatedwax fdfdas
authored
417 else:
418 self.setWindowIcon(mood.icon(self.mainwindow.theme))
2dbd124 sounds, idle, etc
Stephen Dranger authored
419 self.optionsMenu.removeAction(self.unblockchum)
420 self.optionsMenu.addAction(self.blockAction)
79e4de5 illuminatedwax fdfdas
authored
421 # print mood update?
422 def updateBlocked(self):
423 if self.parent():
3bafa1e more memo work
Stephen Dranger authored
424 self.parent().updateBlocked(self.title())
79e4de5 illuminatedwax fdfdas
authored
425 else:
426 self.setWindowIcon(QtGui.QIcon(self.mainwindow.theme["main/chums/moods/blocked/icon"]))
2dbd124 sounds, idle, etc
Stephen Dranger authored
427 self.optionsMenu.addAction(self.unblockchum)
428 self.optionsMenu.removeAction(self.blockAction)
429
79e4de5 illuminatedwax fdfdas
authored
430 def updateColor(self, color):
431 self.chum.color = color
432 def addMessage(self, text, me=True):
433 if me:
434 chum = self.mainwindow.profile()
435 else:
436 chum = self.chum
437 self.notifyNewMessage()
438 self.textArea.addMessage(text, chum)
439
440 def notifyNewMessage(self):
441 # first see if this conversation HASS the focus
442 if not (self.hasFocus() or self.textArea.hasFocus() or
443 self.textInput.hasFocus() or
3bafa1e more memo work
Stephen Dranger authored
444 (self.parent() and self.parent().convoHasFocus(self.title()))):
79e4de5 illuminatedwax fdfdas
authored
445 # ok if it has a tabconvo parent, send that the notify.
446 if self.parent():
3bafa1e more memo work
Stephen Dranger authored
447 self.parent().notifyNewMessage(self.title())
79e4de5 illuminatedwax fdfdas
authored
448 # if not change the window title and update system tray
449 else:
450 self.newmessage = True
3bafa1e more memo work
Stephen Dranger authored
451 self.setWindowTitle(self.title()+"*")
79e4de5 illuminatedwax fdfdas
authored
452 def func():
453 self.showChat()
3bafa1e more memo work
Stephen Dranger authored
454 self.mainwindow.waitingMessages.addMessage(self.title(), func)
79e4de5 illuminatedwax fdfdas
authored
455
456 def clearNewMessage(self):
457 if self.parent():
3bafa1e more memo work
Stephen Dranger authored
458 self.parent().clearNewMessage(self.title())
79e4de5 illuminatedwax fdfdas
authored
459 elif self.newmessage:
460 self.newmessage = False
3bafa1e more memo work
Stephen Dranger authored
461 self.setWindowTitle(self.title())
462 self.mainwindow.waitingMessages.messageAnswered(self.title())
79e4de5 illuminatedwax fdfdas
authored
463 # reset system tray
464 def focusInEvent(self, event):
465 self.clearNewMessage()
466 self.textInput.setFocus()
547fdb7 illuminatedwax fds
authored
467
79e4de5 illuminatedwax fdfdas
authored
468 def raiseChat(self):
469 self.activateWindow()
470 self.raise_()
471 self.textInput.setFocus()
472
473 def showChat(self):
474 if self.parent():
3bafa1e more memo work
Stephen Dranger authored
475 self.parent().showChat(self.title())
79e4de5 illuminatedwax fdfdas
authored
476 self.raiseChat()
a58dbe2 illuminatedwax 0.0.10
authored
477 def contextMenuEvent(self, event):
478 if event.reason() == QtGui.QContextMenuEvent.Mouse:
479 self.optionsMenu.popup(event.globalPos())
79e4de5 illuminatedwax fdfdas
authored
480 def closeEvent(self, event):
3bafa1e more memo work
Stephen Dranger authored
481 self.mainwindow.waitingMessages.messageAnswered(self.title())
482 self.windowClosed.emit(self.title())
a58dbe2 illuminatedwax 0.0.10
authored
483
79e4de5 illuminatedwax fdfdas
authored
484 def setChumOpen(self, o):
485 self.chumopen = o
486 def changeTheme(self, theme):
487 self.resize(*theme["convo/size"])
7e3f40a illuminatedwax fds
authored
488 self.setStyleSheet("QFrame { %s }" % (theme["convo/style"]))
489
79e4de5 illuminatedwax fdfdas
authored
490 margins = theme["convo/margins"]
491 self.layout.setContentsMargins(margins["left"], margins["top"],
492 margins["right"], margins["bottom"])
493
3bafa1e more memo work
Stephen Dranger authored
494 self.setWindowIcon(self.icon())
79e4de5 illuminatedwax fdfdas
authored
495 t = Template(self.mainwindow.theme["convo/chumlabel/text"])
3bafa1e more memo work
Stephen Dranger authored
496 self.chumLabel.setText(t.safe_substitute(handle=self.title()))
79e4de5 illuminatedwax fdfdas
authored
497 self.chumLabel.setStyleSheet(theme["convo/chumlabel/style"])
498 self.chumLabel.setAlignment(self.aligndict["h"][self.mainwindow.theme["convo/chumlabel/align/h"]] | self.aligndict["v"][self.mainwindow.theme["convo/chumlabel/align/v"]])
499 self.chumLabel.setMaximumHeight(self.mainwindow.theme["convo/chumlabel/maxheight"])
500 self.chumLabel.setMinimumHeight(self.mainwindow.theme["convo/chumlabel/minheight"])
501 self.chumLabel.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Expanding))
a58dbe2 illuminatedwax 0.0.10
authored
502 self.quirksOff.setText(self.mainwindow.theme["main/menus/rclickchumlist/quirksoff"])
503 self.addChumAction.setText(self.mainwindow.theme["main/menus/rclickchumlist/addchum"])
504 self.blockAction.setText(self.mainwindow.theme["main/menus/rclickchumlist/blockchum"])
7e3f40a illuminatedwax fds
authored
505 self.unblockchum.setText(self.mainwindow.theme["main/menus/rclickchumlist/unblockchum"])
a58dbe2 illuminatedwax 0.0.10
authored
506
79e4de5 illuminatedwax fdfdas
authored
507 self.textArea.changeTheme(theme)
508 self.textInput.changeTheme(theme)
509
a58dbe2 illuminatedwax 0.0.10
authored
510
79e4de5 illuminatedwax fdfdas
authored
511 @QtCore.pyqtSlot()
512 def sentMessage(self):
10d0ede illuminatedwax fdssdf
authored
513 text = unicode(self.textInput.text())
87cbeca illuminatedwax fdsafd
authored
514 if text == "" or text[0:11] == "PESTERCHUM:":
79e4de5 illuminatedwax fdfdas
authored
515 return
547fdb7 illuminatedwax fds
authored
516 self.history.add(text)
79e4de5 illuminatedwax fdfdas
authored
517 # deal with quirks here
a58dbe2 illuminatedwax 0.0.10
authored
518 if self.applyquirks:
10d0ede illuminatedwax fdssdf
authored
519 qtext = self.mainwindow.userprofile.quirks.apply(text)
520 text = qtext
79e4de5 illuminatedwax fdfdas
authored
521 self.addMessage(text, True)
522 # if ceased, rebegin
3bafa1e more memo work
Stephen Dranger authored
523 if hasattr(self, 'chumopen') and not self.chumopen:
524 self.mainwindow.newConvoStarted.emit(QtCore.QString(self.title()), True)
79e4de5 illuminatedwax fdfdas
authored
525 # convert color tags
10d0ede illuminatedwax fdssdf
authored
526 text = convertTags(text, "ctag")
3bafa1e more memo work
Stephen Dranger authored
527 self.messageSent.emit(text, self.title())
10d0ede illuminatedwax fdssdf
authored
528 self.textInput.setText("")
79e4de5 illuminatedwax fdfdas
authored
529
a58dbe2 illuminatedwax 0.0.10
authored
530 @QtCore.pyqtSlot()
531 def addThisChum(self):
532 self.mainwindow.addChum(self.chum)
533 @QtCore.pyqtSlot()
534 def blockThisChum(self):
535 self.mainwindow.blockChum(self.chum.handle)
2dbd124 sounds, idle, etc
Stephen Dranger authored
536 @QtCore.pyqtSlot()
537 def unblockChumSlot(self):
538 self.mainwindow.unblockChum(self.chum.handle)
a58dbe2 illuminatedwax 0.0.10
authored
539 @QtCore.pyqtSlot(bool)
540 def toggleQuirks(self, toggled):
541 self.applyquirks = not toggled
542
3bafa1e more memo work
Stephen Dranger authored
543 messageSent = QtCore.pyqtSignal(QtCore.QString, QtCore.QString)
79e4de5 illuminatedwax fdfdas
authored
544 windowClosed = QtCore.pyqtSignal(QtCore.QString)
545
546 aligndict = {"h": {"center": QtCore.Qt.AlignHCenter,
547 "left": QtCore.Qt.AlignLeft,
548 "right": QtCore.Qt.AlignRight },
549 "v": {"center": QtCore.Qt.AlignVCenter,
550 "top": QtCore.Qt.AlignTop,
551 "bottom": QtCore.Qt.AlignBottom } }
Something went wrong with that request. Please try again.