hyperlinks

This commit is contained in:
Stephen Dranger 2011-02-03 02:51:22 -06:00
parent ba1d2dac27
commit 964ea8aec0
8 changed files with 51 additions and 38 deletions

3
TODO
View file

@ -1,5 +1,5 @@
Features: Features:
* Hyperlinks * chat window margins
* /me ghostDunk's [GD'S] * /me ghostDunk's [GD'S]
* Transparent background * Transparent background
* tab recombining gives wrong window icon * tab recombining gives wrong window icon
@ -17,6 +17,7 @@ Features:
* ctrl-tab should prefer new convos * ctrl-tab should prefer new convos
* More complex quirks: random, spelling, by-sound * More complex quirks: random, spelling, by-sound
* Implement TC options * Implement TC options
* chumList not scaling -- QListView + delegate?
* spell check? * spell check?
* Help menu * Help menu
* more robust IRC error handling * more robust IRC error handling

Binary file not shown.

View file

@ -1 +1 @@
{"macruralAlchemist": {"color": "#700000", "handle": "macruralAlchemist", "mood": "offline"}, "agogPorphyry": {"color": "#522d80", "handle": "agogPorphyry", "mood": "offline"}, "fireSwallow": {"color": "#80bb9a", "handle": "fireSwallow", "mood": "offline"}, "aquaMarinist": {"color": "#00caca", "handle": "aquaMarinist", "mood": "offline"}, "nitroZealist": {"color": "#ff3737", "handle": "nitroZealist", "mood": "offline"}, "superGhost": {"color": "#800564", "handle": "superGhost", "mood": "offline"}, "tentacleTherapist": {"color": "#cc66ff", "handle": "tentacleTherapist", "mood": "offline"}, "captainCaveman": {"color": "#7c414e", "handle": "captainCaveman", "mood": "offline"}, "mechanicalSpectacle": {"color": "#0000ff", "handle": "mechanicalSpectacle", "mood": "offline"}, "gamblingGenocider": {"color": "#00ff00", "handle": "gamblingGenocider", "mood": "offline"}, "centaursTesticle": {"color": "#000056", "handle": "centaursTesticle", "mood": "offline"}, "schlagzeugGator": {"color": "#61821f", "handle": "schlagzeugGator", "mood": "offline"}, "unknownTraveler": {"color": "#006666", "handle": "unknownTraveler", "mood": "offline"}, "marineAquist": {"color": "#00caca", "handle": "marineAquist", "mood": "offline"}} {"macruralAlchemist": {"color": "#700000", "handle": "macruralAlchemist", "mood": "offline"}, "agogPorphyry": {"color": "#522d80", "handle": "agogPorphyry", "mood": "offline"}, "fireSwallow": {"color": "#80bb9a", "handle": "fireSwallow", "mood": "offline"}, "aquaMarinist": {"color": "#00caca", "handle": "aquaMarinist", "mood": "offline"}, "nitroZealist": {"color": "#ff3737", "handle": "nitroZealist", "mood": "offline"}, "superGhost": {"color": "#800564", "handle": "superGhost", "mood": "offline"}, "tentacleTherapist": {"color": "#cc66ff", "handle": "tentacleTherapist", "mood": "offline"}, "aquaticMarinist": {"color": "#00caca", "handle": "aquaticMarinist", "mood": "offline"}, "captainCaveman": {"color": "#7c414e", "handle": "captainCaveman", "mood": "offline"}, "mechanicalSpectacle": {"color": "#0000ff", "handle": "mechanicalSpectacle", "mood": "offline"}, "gamblingGenocider": {"color": "#00ff00", "handle": "gamblingGenocider", "mood": "offline"}, "centaursTesticle": {"color": "#000056", "handle": "centaursTesticle", "mood": "offline"}, "schlagzeugGator": {"color": "#61821f", "handle": "schlagzeugGator", "mood": "offline"}, "unknownTraveler": {"color": "#006666", "handle": "unknownTraveler", "mood": "offline"}, "marineAquist": {"color": "#00caca", "handle": "marineAquist", "mood": "offline"}}

View file

@ -22,11 +22,12 @@ logging.basicConfig(level=logging.INFO)
_ctag_begin = re.compile(r'<c=(.*?)>') _ctag_begin = re.compile(r'<c=(.*?)>')
_ctag_rgb = re.compile(r'\d+,\d+,\d+') _ctag_rgb = re.compile(r'\d+,\d+,\d+')
_urlre = re.compile(r"(?i)(http://[^\s<]+)")
def convertColorTags(string, format="html"): def convertTags(string, format="html"):
if format not in ["html", "bbcode", "ctag"]: if format not in ["html", "bbcode", "ctag"]:
raise ValueError("Color format not recognized") raise ValueError("Color format not recognized")
def repfunc(matchobj): def colorrepfunc(matchobj):
color = matchobj.group(1) color = matchobj.group(1)
if _ctag_rgb.match(color) is not None: if _ctag_rgb.match(color) is not None:
if format=='ctag': if format=='ctag':
@ -46,9 +47,13 @@ def convertColorTags(string, format="html"):
elif format == "ctag": elif format == "ctag":
(r,g,b,a) = qc.getRgb() (r,g,b,a) = qc.getRgb()
return '<c=%s,%s,%s>' % (r,g,b) return '<c=%s,%s,%s>' % (r,g,b)
string = _ctag_begin.sub(repfunc, string) string = _ctag_begin.sub(colorrepfunc, string)
endtag = {"html": "</span>", "bbcode": "[/color]", "ctag": "</c>"} endtag = {"html": "</span>", "bbcode": "[/color]", "ctag": "</c>"}
string = string.replace("</c>", endtag[format]) string = string.replace("</c>", endtag[format])
urlrep = {"html": r"<a href='\1'>\1</a>",
"bbcode": r"[url]\1[/url]",
"ctag": r"\1" }
string = _urlre.sub(urlrep[format], string)
return string return string
def escapeBrackets(string): def escapeBrackets(string):
@ -98,10 +103,6 @@ def escapeBrackets(string):
retval += "</c>" retval += "</c>"
return retval return retval
#_urlre = re.compile()
#def findURLs(string):
class waitingMessageHolder(object): class waitingMessageHolder(object):
def __init__(self, mainwindow, **msgfuncs): def __init__(self, mainwindow, **msgfuncs):
self.mainwindow = mainwindow self.mainwindow = mainwindow
@ -362,13 +363,15 @@ class chumListing(QtGui.QListWidgetItem):
def updateMood(self, unblock=False): def updateMood(self, unblock=False):
mood = self.chum.mood mood = self.chum.mood
self.mood = mood self.mood = mood
self.setIcon(self.mood.icon(self.mainwindow.theme)) icon = self.mood.icon(self.mainwindow.theme)
self.setIcon(icon)
try: try:
self.setTextColor(QtGui.QColor(self.mainwindow.theme["main/chums/moods"][self.mood.name()]["color"])) self.setTextColor(QtGui.QColor(self.mainwindow.theme["main/chums/moods"][self.mood.name()]["color"]))
except KeyError: except KeyError:
self.setTextColor(QtGui.QColor(self.mainwindow.theme["main/chums/moods/chummy/color"])) self.setTextColor(QtGui.QColor(self.mainwindow.theme["main/chums/moods/chummy/color"]))
def changeTheme(self, theme): def changeTheme(self, theme):
self.setIcon(self.mood.icon(theme)) icon = self.mood.icon(theme)
self.setIcon(icon)
try: try:
self.setTextColor(QtGui.QColor(self.mainwindow.theme["main/chums/moods"][self.mood.name()]["color"])) self.setTextColor(QtGui.QColor(self.mainwindow.theme["main/chums/moods"][self.mood.name()]["color"]))
except KeyError: except KeyError:
@ -841,36 +844,35 @@ class PesterText(QtGui.QTextEdit):
if msg == "PESTERCHUM:BEGIN": if msg == "PESTERCHUM:BEGIN":
parent.setChumOpen(True) parent.setChumOpen(True)
msg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"]) msg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"])
window.chatlog.log(chum.handle, convertColorTags(msg, "bbcode")) window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
self.append(convertColorTags(msg)) self.append(convertTags(msg))
elif msg == "PESTERCHUM:CEASE": elif msg == "PESTERCHUM:CEASE":
parent.setChumOpen(False) parent.setChumOpen(False)
msg = chum.pestermsg(me, systemColor, window.theme["convo/text/ceasepester"]) msg = chum.pestermsg(me, systemColor, window.theme["convo/text/ceasepester"])
window.chatlog.log(chum.handle, convertColorTags(msg, "bbcode")) window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
self.append(convertColorTags(msg)) self.append(convertTags(msg))
elif msg == "PESTERCHUM:BLOCK": elif msg == "PESTERCHUM:BLOCK":
msg = chum.pestermsg(me, systemColor, window.theme['convo/text/blocked']) msg = chum.pestermsg(me, systemColor, window.theme['convo/text/blocked'])
window.chatlog.log(chum.handle, convertColorTags(msg, "bbcode")) window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
self.append(convertColorTags(msg)) self.append(convertTags(msg))
elif msg == "PESTERCHUM:UNBLOCK": elif msg == "PESTERCHUM:UNBLOCK":
msg = chum.pestermsg(me, systemColor, window.theme['convo/text/unblocked']) msg = chum.pestermsg(me, systemColor, window.theme['convo/text/unblocked'])
window.chatlog.log(chum.handle, convertColorTags(msg, "bbcode")) window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
self.append(convertColorTags(msg)) self.append(convertTags(msg))
else: else:
if not parent.chumopen and chum is not me: if not parent.chumopen and chum is not me:
beginmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"]) beginmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"])
parent.setChumOpen(True) parent.setChumOpen(True)
window.chatlog.log(chum.handle, convertColorTags(beginmsg, "bbcode")) window.chatlog.log(chum.handle, convertTags(beginmsg, "bbcode"))
self.append(convertColorTags(beginmsg)) self.append(convertTags(beginmsg))
msg = "<c=%s>%s: %s</c>" % (color, initials, msg) msg = "<c=%s>%s: %s</c>" % (color, initials, msg)
msg = escapeBrackets(msg) msg = escapeBrackets(msg)
#msg = findURLs(msg) self.append(convertTags(msg))
self.append(convertColorTags(msg))
if chum is me: if chum is me:
window.chatlog.log(parent.chum.handle, convertColorTags(msg, "bbcode")) window.chatlog.log(parent.chum.handle, convertTags(msg, "bbcode"))
else: else:
window.chatlog.log(chum.handle, convertColorTags(msg, "bbcode")) window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
def changeTheme(self, theme): def changeTheme(self, theme):
self.setStyleSheet(theme["convo/textarea/style"]) self.setStyleSheet(theme["convo/textarea/style"])
sb = self.verticalScrollBar() sb = self.verticalScrollBar()
@ -880,6 +882,13 @@ class PesterText(QtGui.QTextEdit):
self.parent().clearNewMessage() self.parent().clearNewMessage()
QtGui.QTextEdit.focusInEvent(self, event) QtGui.QTextEdit.focusInEvent(self, event)
def mousePressEvent(self, event):
url = self.anchorAt(event.pos())
if url == "":
return
else:
QtGui.QDesktopServices.openUrl(QtCore.QUrl(url, QtCore.QUrl.TolerantMode))
class PesterInput(QtGui.QLineEdit): class PesterInput(QtGui.QLineEdit):
def __init__(self, theme, parent=None): def __init__(self, theme, parent=None):
QtGui.QLineEdit.__init__(self, parent) QtGui.QLineEdit.__init__(self, parent)
@ -932,15 +941,15 @@ class PesterConvo(QtGui.QFrame):
if initiated: if initiated:
msg = self.mainwindow.profile().pestermsg(self.chum, QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"]), self.mainwindow.theme["convo/text/beganpester"]) msg = self.mainwindow.profile().pestermsg(self.chum, QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"]), self.mainwindow.theme["convo/text/beganpester"])
self.setChumOpen(True) self.setChumOpen(True)
self.textArea.append(convertColorTags(msg)) self.textArea.append(convertTags(msg))
self.mainwindow.chatlog.log(self.chum.handle, convertColorTags(msg, "bbcode")) self.mainwindow.chatlog.log(self.chum.handle, convertTags(msg, "bbcode"))
self.newmessage = False self.newmessage = False
def updateMood(self, mood, unblocked=False): def updateMood(self, mood, unblocked=False):
if mood.name() == "offline" and self.chumopen == True and not unblocked: if mood.name() == "offline" and self.chumopen == True and not unblocked:
msg = self.chum.pestermsg(self.mainwindow.profile(), QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"]), self.mainwindow.theme["convo/text/ceasepester"]) msg = self.chum.pestermsg(self.mainwindow.profile(), QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"]), self.mainwindow.theme["convo/text/ceasepester"])
self.textArea.append(convertColorTags(msg)) self.textArea.append(convertTags(msg))
self.mainwindow.chatlog.log(self.chum.handle, convertColorTags(msg, "bbcode")) self.mainwindow.chatlog.log(self.chum.handle, convertTags(msg, "bbcode"))
self.chumopen = False self.chumopen = False
if self.parent(): if self.parent():
self.parent().updateMood(self.chum.handle, mood, unblocked) self.parent().updateMood(self.chum.handle, mood, unblocked)
@ -1034,6 +1043,8 @@ class PesterConvo(QtGui.QFrame):
# if ceased, rebegin # if ceased, rebegin
if not self.chumopen: if not self.chumopen:
self.mainwindow.newConvoStarted.emit(QtCore.QString(self.chum.handle), True) self.mainwindow.newConvoStarted.emit(QtCore.QString(self.chum.handle), True)
# convert color tags
text = convertTags(unicode(text), "ctag")
self.messageSent.emit(text, self.chum) self.messageSent.emit(text, self.chum)
messageSent = QtCore.pyqtSignal(QtCore.QString, PesterProfile) messageSent = QtCore.pyqtSignal(QtCore.QString, PesterProfile)
@ -1395,7 +1406,7 @@ class PesterWindow(MovingWindow):
chum = self.convos[h].chum chum = self.convos[h].chum
chumopen = self.convos[h].chumopen chumopen = self.convos[h].chumopen
if chumopen: if chumopen:
self.chatlog.log(chum.handle, convertColorTags(self.profile().pestermsg(chum, QtGui.QColor(self.theme["convo/systemMsgColor"]), self.theme["convo/text/ceasepester"]), "bbcode")) self.chatlog.log(chum.handle, convertTags(self.profile().pestermsg(chum, QtGui.QColor(self.theme["convo/systemMsgColor"]), self.theme["convo/text/ceasepester"]), "bbcode"))
self.chatlog.finish(h) self.chatlog.finish(h)
self.convoClosed.emit(handle) self.convoClosed.emit(handle)
del self.convos[h] del self.convos[h]
@ -1487,8 +1498,8 @@ class PesterWindow(MovingWindow):
if self.convos.has_key(h): if self.convos.has_key(h):
convo = self.convos[h] convo = self.convos[h]
msg = self.profile().pestermsg(convo.chum, QtGui.QColor(self.theme["convo/systemMsgColor"]), self.theme["convo/text/blocked"]) msg = self.profile().pestermsg(convo.chum, QtGui.QColor(self.theme["convo/systemMsgColor"]), self.theme["convo/text/blocked"])
convo.textArea.append(convertColorTags(msg)) convo.textArea.append(convertTags(msg))
self.chatlog.log(convo.chum.handle, convertColorTags(msg, "bbcode")) self.chatlog.log(convo.chum.handle, convertTags(msg, "bbcode"))
convo.updateBlocked() convo.updateBlocked()
self.chumList.removeChum(h) self.chumList.removeChum(h)
if hasattr(self, 'trollslum') and self.trollslum: if hasattr(self, 'trollslum') and self.trollslum:
@ -1504,8 +1515,8 @@ class PesterWindow(MovingWindow):
if self.convos.has_key(h): if self.convos.has_key(h):
convo = self.convos[h] convo = self.convos[h]
msg = self.profile().pestermsg(convo.chum, QtGui.QColor(self.theme["convo/systemMsgColor"]), self.theme["convo/text/unblocked"]) msg = self.profile().pestermsg(convo.chum, QtGui.QColor(self.theme["convo/systemMsgColor"]), self.theme["convo/text/unblocked"])
convo.textArea.append(convertColorTags(msg)) convo.textArea.append(convertTags(msg))
self.chatlog.log(convo.chum.handle, convertColorTags(msg, "bbcode")) self.chatlog.log(convo.chum.handle, convertTags(msg, "bbcode"))
convo.updateMood(convo.chum.mood, unblocked=True) convo.updateMood(convo.chum.mood, unblocked=True)
chum = PesterProfile(h, chumdb=self.chumdb) chum = PesterProfile(h, chumdb=self.chumdb)
if hasattr(self, 'trollslum') and self.trollslum: if hasattr(self, 'trollslum') and self.trollslum:

View file

@ -347,7 +347,7 @@ class PesterUserlist(QtGui.QDialog):
self.userarea.clear() self.userarea.clear()
for n in names: for n in names:
item = QtGui.QListWidgetItem(n) item = QtGui.QListWidgetItem(n)
item.setTextColor(QtGui.QColor(self.theme["main/chums/moods/chummy/color"])) item.setTextColor(QtGui.QColor(self.theme["main/chums/userlistcolor"]))
self.userarea.addItem(item) self.userarea.addItem(item)
self.userarea.sortItems() self.userarea.sortItems()
@QtCore.pyqtSlot(QtCore.QString, QtCore.QString, QtCore.QString) @QtCore.pyqtSlot(QtCore.QString, QtCore.QString, QtCore.QString)
@ -362,7 +362,7 @@ class PesterUserlist(QtGui.QDialog):
self.addUser(h) self.addUser(h)
def addUser(self, name): def addUser(self, name):
item = QtGui.QListWidgetItem(name) item = QtGui.QListWidgetItem(name)
item.setTextColor(QtGui.QColor(self.theme["main/chums/moods/chummy/color"])) item.setTextColor(QtGui.QColor(self.theme["main/chums/userlistcolor"]))
self.userarea.addItem(item) self.userarea.addItem(item)
self.userarea.sortItems() self.userarea.sortItems()
def delUser(self, name): def delUser(self, name):
@ -377,7 +377,7 @@ class PesterUserlist(QtGui.QDialog):
self.addChumAction.setText(theme["main/menus/rclickchumlist/addchum"]) self.addChumAction.setText(theme["main/menus/rclickchumlist/addchum"])
for item in [self.userarea.item(i) for i in range(0, self.userarea.count())]: for item in [self.userarea.item(i) for i in range(0, self.userarea.count())]:
print item.text() print item.text()
item.setTextColor(QtGui.QColor(theme["main/chums/moods/chummy/color"])) item.setTextColor(QtGui.QColor(theme["main/chums/userlistcolor"]))
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def addChumSlot(self): def addChumSlot(self):

Binary file not shown.

View file

@ -35,6 +35,7 @@
"chums": { "style": "border:2px solid yellow; background-color: black;color: white;font: bold;font-family: 'Courier';selection-background-color:#646464; ", "chums": { "style": "border:2px solid yellow; background-color: black;color: white;font: bold;font-family: 'Courier';selection-background-color:#646464; ",
"loc": [12, 117], "loc": [12, 117],
"size": [209, 82], "size": [209, 82],
"userlistcolor": "black",
"moods": { "moods": {
"chummy": { "icon": "$path/chummy.gif", "color": "white" }, "chummy": { "icon": "$path/chummy.gif", "color": "white" },

View file

@ -34,7 +34,7 @@
"chums": { "style": "border: 0px; background-color: white; padding: 5px; font-family: 'Arial';selection-background-color:rgb(200,200,200); ", "chums": { "style": "border: 0px; background-color: white; padding: 5px; font-family: 'Arial';selection-background-color:rgb(200,200,200); ",
"loc": [476, 90], "loc": [476, 90],
"size": [175, 361], "size": [175, 361],
"userlistcolor": "black",
"moods": { "moods": {
"chummy": { "icon": "$path/chummy.png", "color": "#63ea00" }, "chummy": { "icon": "$path/chummy.png", "color": "#63ea00" },