diff --git a/gameview.py b/gameview.py index 2c5eae5..5d961d7 100644 --- a/gameview.py +++ b/gameview.py @@ -1,4 +1,4 @@ -import thread, time, os, buttons, urllib, charselect, ini, random +import thread, time, os, buttons, urllib, charselect, ini, random, re from os.path import exists, basename from ConfigParserEdit import ConfigParser from constants import * @@ -68,6 +68,8 @@ SCALING_SMOOTH = 2 DOWNLOAD_BLACKLIST = [] +URL_REGEX = r"https?://(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)" + VIEWPORT_W = 256*2 VIEWPORT_H = 192*2 @@ -173,6 +175,9 @@ class ChatLogs(QtGui.QTextEdit): self.type = logtype self.savelog = ini.read_ini_bool("AO2XP.ini", "General", "save logs") self.combinelog = ini.read_ini_bool("AO2XP.ini", "General", "combined logs") + self.setMouseTracking(True) + self.anchor = None + if not exists("chatlogs"): os.mkdir("chatlogs") @@ -189,14 +194,27 @@ class ChatLogs(QtGui.QTextEdit): else: self.logfile = open("chatlogs/OOC_%d%.2d%.2d_on_%.2d.%.2d.%.2d.txt" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5]), "w") else: - self.logfile = None + self.logfile = None + + def mouseMoveEvent(self, e): + super(ChatLogs, self).mouseMoveEvent(e) + self.anchor = self.anchorAt(e.pos()) + if self.anchor: + QtGui.QApplication.setOverrideCursor(QtCore.Qt.PointingHandCursor) + else: + QtGui.QApplication.setOverrideCursor(QtCore.Qt.ArrowCursor) + def mouseReleaseEvent(self, e): + if self.anchor: + QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.anchor)) + QtGui.QApplication.setOverrideCursor(QtCore.Qt.ArrowCursor) + self.anchor = None + def __del__(self): if self.savelog: self.logfile.close() def append(self, text): - super(ChatLogs, self).append(text) if self.savelog: if isinstance(text, str) or isinstance(text, unicode): if self.combinelog and not "Log started" in text: @@ -215,6 +233,12 @@ class ChatLogs(QtGui.QTextEdit): else: self.logfile.write(text.toUtf8()+"\n") + if "http" in text: + text = unicode(text) # Get rid of QStrings + text = re.sub(URL_REGEX, r'\g<0>', text) + + super(ChatLogs, self).append(text) + class AOCharMovie(QtGui.QLabel): done = QtCore.pyqtSignal() use_pillow = 0 @@ -2174,6 +2198,7 @@ class gui(QtGui.QWidget): if f_char.lower() != self.charlist[f_char_id][0].lower(): logcharname = self.charlist[f_char_id][0] + ' (' + f_char.decode("utf-8") + ')' + chatmsg = self.m_chatmessage[CHATMSG] if self.m_chatmessage[SHOWNAME] and self.m_chatmessage[SHOWNAME].lower() != f_char.lower(): try: @@ -2182,7 +2207,7 @@ class gui(QtGui.QWidget): logcharname += " (???)" if evidence == -1: - self.icLog.append('[%d:%.2d] %s: %s' % (t[3], t[4], logcharname, self.m_chatmessage[CHATMSG])) + self.icLog.append('[%d:%.2d] %s: %s' % (t[3], t[4], logcharname, chatmsg)) else: eviname = '(NULL) %d' % evidence try: @@ -2190,7 +2215,7 @@ class gui(QtGui.QWidget): except: pass - self.icLog.append('[%d:%.2d] %s: %s\n%s presented an evidence: %s' % (t[3], t[4], logcharname, self.m_chatmessage[CHATMSG], f_char, eviname)) + self.icLog.append('[%d:%.2d] %s: %s\n%s presented an evidence: %s' % (t[3], t[4], logcharname, chatmsg, f_char, eviname)) self.is_additive = (self.m_chatmessage[ADDITIVE] == "1") @@ -3489,7 +3514,6 @@ class TCP_Thread(QtCore.QThread): elif header == 'CT': name = decode_ao_str(network[1].decode('utf-8')) chatmsg = decode_ao_str(network[2].decode('utf-8').replace("\n", "
")) - #self.parent.ooclog.append('%s: %s' % (name, chatmsg)) self.OOC_Log.emit("%s: %s" % (name, chatmsg)) elif header == 'PV':