reworked parsing
This commit is contained in:
parent
728da1632d
commit
b73bd2afbd
20 changed files with 115 additions and 100 deletions
17
convo.py
17
convo.py
|
@ -5,7 +5,7 @@ from PyQt4 import QtGui, QtCore
|
||||||
|
|
||||||
from dataobjs import PesterProfile, Mood, PesterHistory
|
from dataobjs import PesterProfile, Mood, PesterHistory
|
||||||
from generic import PesterIcon, RightClickList
|
from generic import PesterIcon, RightClickList
|
||||||
from parsetools import escapeBrackets, convertTags
|
from parsetools import convertTags
|
||||||
|
|
||||||
class PesterTabWindow(QtGui.QFrame):
|
class PesterTabWindow(QtGui.QFrame):
|
||||||
def __init__(self, mainwindow, parent=None, convo="convo"):
|
def __init__(self, mainwindow, parent=None, convo="convo"):
|
||||||
|
@ -211,6 +211,7 @@ class PesterText(QtGui.QTextEdit):
|
||||||
parent = self.parent()
|
parent = self.parent()
|
||||||
window = parent.mainwindow
|
window = parent.mainwindow
|
||||||
me = window.profile()
|
me = window.profile()
|
||||||
|
quirks = window.userprofile.quirks if parent.applyquirks else None
|
||||||
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"])
|
||||||
|
@ -238,6 +239,8 @@ class PesterText(QtGui.QTextEdit):
|
||||||
window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
|
window.chatlog.log(chum.handle, convertTags(msg, "bbcode"))
|
||||||
self.append(convertTags(msg))
|
self.append(convertTags(msg))
|
||||||
elif msg[0:3] == "/me" or msg[0:13] == "PESTERCHUM:ME":
|
elif msg[0:3] == "/me" or msg[0:13] == "PESTERCHUM:ME":
|
||||||
|
if quirks:
|
||||||
|
msg = quirks.apply(msg)
|
||||||
if msg[0:3] == "/me":
|
if msg[0:3] == "/me":
|
||||||
start = 3
|
start = 3
|
||||||
else:
|
else:
|
||||||
|
@ -256,11 +259,10 @@ class PesterText(QtGui.QTextEdit):
|
||||||
window.chatlog.log(chum.handle, convertTags(beginmsg, "bbcode"))
|
window.chatlog.log(chum.handle, convertTags(beginmsg, "bbcode"))
|
||||||
self.append(convertTags(beginmsg))
|
self.append(convertTags(beginmsg))
|
||||||
|
|
||||||
msg = escapeBrackets(msg)
|
|
||||||
msg = "<c=%s>%s: %s</c>" % (color, initials, msg)
|
msg = "<c=%s>%s: %s</c>" % (color, initials, msg)
|
||||||
self.append(convertTags(msg))
|
self.append(convertTags(msg, quirkobj=quirks))
|
||||||
if chum is me:
|
if chum is me:
|
||||||
window.chatlog.log(parent.chum.handle, convertTags(msg, "bbcode"))
|
window.chatlog.log(parent.chum.handle, convertTags(msg, "bbcode", quirkobj=quirks))
|
||||||
else:
|
else:
|
||||||
if window.idle:
|
if window.idle:
|
||||||
idlethreshhold = 60
|
idlethreshhold = 60
|
||||||
|
@ -514,16 +516,13 @@ class PesterConvo(QtGui.QFrame):
|
||||||
if text == "" or text[0:11] == "PESTERCHUM:":
|
if text == "" or text[0:11] == "PESTERCHUM:":
|
||||||
return
|
return
|
||||||
self.history.add(text)
|
self.history.add(text)
|
||||||
# deal with quirks here
|
|
||||||
if self.applyquirks:
|
|
||||||
qtext = self.mainwindow.userprofile.quirks.apply(text)
|
|
||||||
text = qtext
|
|
||||||
self.addMessage(text, True)
|
self.addMessage(text, True)
|
||||||
# if ceased, rebegin
|
# if ceased, rebegin
|
||||||
if hasattr(self, 'chumopen') and not self.chumopen:
|
if hasattr(self, 'chumopen') and not self.chumopen:
|
||||||
self.mainwindow.newConvoStarted.emit(QtCore.QString(self.title()), True)
|
self.mainwindow.newConvoStarted.emit(QtCore.QString(self.title()), True)
|
||||||
# convert color tags
|
# convert color tags
|
||||||
text = convertTags(text, "ctag")
|
quirkobj = self.mainwindow.userprofile.quirks if self.applyquirks else None
|
||||||
|
text = convertTags(text, "ctag", quirkobj)
|
||||||
self.messageSent.emit(text, self.title())
|
self.messageSent.emit(text, self.title())
|
||||||
self.textInput.setText("")
|
self.textInput.setText("")
|
||||||
|
|
||||||
|
|
BIN
convo.pyc
BIN
convo.pyc
Binary file not shown.
BIN
dataobjs.pyc
BIN
dataobjs.pyc
Binary file not shown.
BIN
generic.pyc
BIN
generic.pyc
Binary file not shown.
BIN
irc.pyc
BIN
irc.pyc
Binary file not shown.
File diff suppressed because one or more lines are too long
26
memos.py
26
memos.py
|
@ -6,7 +6,7 @@ from datetime import time, timedelta, datetime
|
||||||
from dataobjs import PesterProfile, Mood, PesterHistory
|
from dataobjs import PesterProfile, Mood, PesterHistory
|
||||||
from generic import PesterIcon, RightClickList
|
from generic import PesterIcon, RightClickList
|
||||||
from convo import PesterConvo, PesterInput, PesterText, PesterTabWindow
|
from convo import PesterConvo, PesterInput, PesterText, PesterTabWindow
|
||||||
from parsetools import convertTags, escapeBrackets, addTimeInitial, timeProtocol
|
from parsetools import convertTags, addTimeInitial, timeProtocol
|
||||||
|
|
||||||
def delta2txt(d, format="pc"):
|
def delta2txt(d, format="pc"):
|
||||||
if format == "pc":
|
if format == "pc":
|
||||||
|
@ -227,6 +227,7 @@ class MemoText(PesterText):
|
||||||
parent = self.parent()
|
parent = self.parent()
|
||||||
window = parent.mainwindow
|
window = parent.mainwindow
|
||||||
me = window.profile()
|
me = window.profile()
|
||||||
|
quirks = window.userprofile.quirks if parent.applyquirks else None
|
||||||
msg = unicode(text)
|
msg = unicode(text)
|
||||||
chumdb = window.chumdb
|
chumdb = window.chumdb
|
||||||
if chum is not me: # SO MUCH WH1T3SP4C3 >:]
|
if chum is not me: # SO MUCH WH1T3SP4C3 >:]
|
||||||
|
@ -268,6 +269,8 @@ class MemoText(PesterText):
|
||||||
time.openCurrentTime()
|
time.openCurrentTime()
|
||||||
|
|
||||||
if msg[0:3] == "/me" or msg[0:13] == "PESTERCHUM:ME":
|
if msg[0:3] == "/me" or msg[0:13] == "PESTERCHUM:ME":
|
||||||
|
if quirks:
|
||||||
|
msg = quirks.apply(msg)
|
||||||
if msg[0:3] == "/me":
|
if msg[0:3] == "/me":
|
||||||
start = 3
|
start = 3
|
||||||
else:
|
else:
|
||||||
|
@ -279,9 +282,8 @@ class MemoText(PesterText):
|
||||||
else:
|
else:
|
||||||
if chum is not me:
|
if chum is not me:
|
||||||
msg = addTimeInitial(msg, parent.times[chum.handle].getGrammar())
|
msg = addTimeInitial(msg, parent.times[chum.handle].getGrammar())
|
||||||
msg = escapeBrackets(msg)
|
self.append(convertTags(msg, quirksobj=quirks))
|
||||||
self.append(convertTags(msg))
|
window.chatlog.log(parent.channel, convertTags(msg, "bbcode", quirks))
|
||||||
window.chatlog.log(parent.channel, convertTags(msg, "bbcode"))
|
|
||||||
|
|
||||||
|
|
||||||
def changeTheme(self, theme):
|
def changeTheme(self, theme):
|
||||||
|
@ -554,23 +556,19 @@ class PesterMemo(PesterConvo):
|
||||||
if self.time.getTime() == None:
|
if self.time.getTime() == None:
|
||||||
self.sendtime()
|
self.sendtime()
|
||||||
grammar = self.time.getGrammar()
|
grammar = self.time.getGrammar()
|
||||||
# deal with quirks here
|
if text[0:3] != "/me":
|
||||||
if self.applyquirks:
|
|
||||||
qtext = self.mainwindow.userprofile.quirks.apply(text)
|
|
||||||
else:
|
|
||||||
qtext = text
|
|
||||||
if qtext[0:3] != "/me":
|
|
||||||
initials = self.mainwindow.profile().initials()
|
initials = self.mainwindow.profile().initials()
|
||||||
colorcmd = self.mainwindow.profile().colorcmd()
|
colorcmd = self.mainwindow.profile().colorcmd()
|
||||||
clientText = "<c=%s>%s%s%s: %s</c>" % (colorcmd, grammar.pcf, initials, grammar.number, qtext)
|
clientText = "<c=%s>%s%s%s: %s</c>" % (colorcmd, grammar.pcf, initials, grammar.number, text)
|
||||||
# account for TC's parsing error
|
# account for TC's parsing error
|
||||||
serverText = "<c=%s>%s: %s</c> " % (colorcmd, initials, qtext)
|
serverText = "<c=%s>%s: %s</c> " % (colorcmd, initials, text)
|
||||||
else:
|
else:
|
||||||
clientText = qtext
|
clientText = text
|
||||||
serverText = clientText
|
serverText = clientText
|
||||||
self.addMessage(clientText, True)
|
self.addMessage(clientText, True)
|
||||||
# convert color tags
|
# convert color tags
|
||||||
serverText = convertTags(unicode(serverText), "ctag")
|
quirks = self.mainwindow.userprofile.quirks if self.applyquirks else None
|
||||||
|
serverText = convertTags(unicode(serverText), "ctag", quirks)
|
||||||
self.messageSent.emit(serverText, self.title())
|
self.messageSent.emit(serverText, self.title())
|
||||||
self.textInput.setText("")
|
self.textInput.setText("")
|
||||||
@QtCore.pyqtSlot()
|
@QtCore.pyqtSlot()
|
||||||
|
|
BIN
memos.pyc
BIN
memos.pyc
Binary file not shown.
BIN
menus.pyc
BIN
menus.pyc
Binary file not shown.
Binary file not shown.
BIN
oyoyo/client.pyc
BIN
oyoyo/client.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
oyoyo/parse.pyc
BIN
oyoyo/parse.pyc
Binary file not shown.
161
parsetools.py
161
parsetools.py
|
@ -4,35 +4,40 @@ from datetime import timedelta
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
_ctag_begin = re.compile(r'(?i)<c=(.*?)>')
|
_ctag_begin = re.compile(r'(?i)<c=(.*?)>')
|
||||||
|
_ctag_end = re.compile(r'(?i)</c>')
|
||||||
_ctag_rgb = re.compile(r'\d+,\d+,\d+')
|
_ctag_rgb = re.compile(r'\d+,\d+,\d+')
|
||||||
_urlre = re.compile(r"(?i)(http://[^\s<[]+)")
|
_urlre = re.compile(r"(?i)http://[^\s]+")
|
||||||
_memore = re.compile(r" (#[A-Za-z0-9_]+)")
|
_memore = re.compile(r" (#[A-Za-z0-9_]+)")
|
||||||
|
|
||||||
def lexer(string, objlist):
|
def lexer(string, objlist):
|
||||||
"""objlist is a list: [(objecttype, re),...] list is in order of preference"""
|
"""objlist is a list: [(objecttype, re),...] list is in order of preference"""
|
||||||
stringlist = [string]
|
stringlist = [string]
|
||||||
for (oType, regexp) in objlist:
|
for (oType, regexp) in objlist:
|
||||||
newstringlist = copy(stringlist)
|
newstringlist = []
|
||||||
for (stri, s) in enumerate(stringlist):
|
for (stri, s) in enumerate(stringlist):
|
||||||
tmp = []
|
if type(s) not in [str, unicode]:
|
||||||
|
newstringlist.append(s)
|
||||||
|
continue
|
||||||
lasti = 0
|
lasti = 0
|
||||||
for m in regexp.finditer(string):
|
for m in regexp.finditer(s):
|
||||||
start = m.start()
|
start = m.start()
|
||||||
end = m.end()
|
end = m.end()
|
||||||
tag = oType(group(0), *groups())
|
tag = oType(m.group(0), *m.groups())
|
||||||
tmp.append(string[lasti:start])
|
if lasti != start:
|
||||||
tmp.append(tag)
|
newstringlist.append(s[lasti:start])
|
||||||
|
newstringlist.append(tag)
|
||||||
|
lasti = end
|
||||||
if lasti < len(string):
|
if lasti < len(string):
|
||||||
tmp.append(string[lasti:])
|
newstringlist.append(s[lasti:])
|
||||||
stringlist = stringlist[0:stri]+tmp+stringlist[stri+1:]
|
|
||||||
stringlist = copy(newstringlist)
|
stringlist = copy(newstringlist)
|
||||||
return stringlist
|
return stringlist
|
||||||
|
|
||||||
def convertTags(string, format="html"):
|
class colorBegin(object):
|
||||||
if format not in ["html", "bbcode", "ctag"]:
|
def __init__(self, string, color):
|
||||||
raise ValueError("Color format not recognized")
|
self.string = string
|
||||||
def colorrepfunc(matchobj):
|
self.color = color
|
||||||
color = matchobj.group(1)
|
def convert(self, format):
|
||||||
|
color = self.color
|
||||||
if _ctag_rgb.match(color) is not None:
|
if _ctag_rgb.match(color) is not None:
|
||||||
if format=='ctag':
|
if format=='ctag':
|
||||||
return "<c=%s>" % (color)
|
return "<c=%s>" % (color)
|
||||||
|
@ -51,69 +56,75 @@ def convertTags(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(colorrepfunc, string)
|
class colorEnd(object):
|
||||||
endtag = {"html": "</span>", "bbcode": "[/color]", "ctag": "</c>"}
|
def __init__(self, string):
|
||||||
string = string.replace("</c>", endtag[format])
|
self.string = string
|
||||||
def urlrep(matchobj):
|
def convert(self, format):
|
||||||
if format=="html":
|
if format == "html":
|
||||||
return "<a href='%s'>%s</a>" % (matchobj.group(1).replace("&", "&"), matchobj.group(1))
|
return "</span>"
|
||||||
elif format=="bbcode":
|
elif format == "bbcode":
|
||||||
return "[url]%s[/url]" % (matchobj.group(1).replace("&", "&"))
|
return "[/color]"
|
||||||
elif format=="ctag":
|
else:
|
||||||
return matchobj.group(1)
|
return self.string
|
||||||
string = _urlre.sub(urlrep, string)
|
class hyperlink(object):
|
||||||
if format == "html":
|
def __init__(self, string):
|
||||||
string = _memore.sub(r" <a href='\1'>\1</a>", string)
|
self.string = string
|
||||||
for (code, f) in smiledict.iteritems():
|
def convert(self, format):
|
||||||
string = string.replace(" %s" % (code), " <img src='smilies/%s' />" % (f))
|
if format == "html":
|
||||||
return string
|
return "<a href='%s'>%s</a>" % (self.string, self.string)
|
||||||
|
elif format == "bbcode":
|
||||||
|
return "[url]%s[/url]" % (self.string)
|
||||||
|
else:
|
||||||
|
return self.string
|
||||||
|
class smiley(object):
|
||||||
|
def __init__(self, string):
|
||||||
|
self.string = string
|
||||||
|
def convert(self, format):
|
||||||
|
if format == "html":
|
||||||
|
return "<img src='smilies/%s' />" % (smiledict[self.string])
|
||||||
|
else:
|
||||||
|
return self.string
|
||||||
|
|
||||||
def escapeBrackets(string):
|
def convertTags(string, format="html", quirkobj=None):
|
||||||
class beginTag(object):
|
if format not in ["html", "bbcode", "ctag"]:
|
||||||
def __init__(self, tag):
|
raise ValueError("Color format not recognized")
|
||||||
self.tag = tag
|
lexlist = [(colorBegin, _ctag_begin), (colorEnd, _ctag_end),
|
||||||
class endTag(object):
|
(hyperlink, _urlre), (hyperlink, _memore),
|
||||||
pass
|
(smiley, _smilere)]
|
||||||
newlist = []
|
|
||||||
begintagpos = [(m.start(), m.end()) for m in _ctag_begin.finditer(string)]
|
lexed = lexer(string, lexlist)
|
||||||
lasti = 0
|
balanced = []
|
||||||
for (s, e) in begintagpos:
|
beginc = 0
|
||||||
newlist.append(string[lasti:s])
|
endc = 0
|
||||||
newlist.append(beginTag(string[s:e]))
|
for o in lexed:
|
||||||
lasti = e
|
if type(o) is colorBegin:
|
||||||
if lasti < len(string):
|
beginc += 1
|
||||||
newlist.append(string[lasti:])
|
balanced.append(o)
|
||||||
tmp = []
|
elif type(o) is colorEnd:
|
||||||
for o in newlist:
|
if beginc >= endc:
|
||||||
if type(o) is not beginTag:
|
endc += 1
|
||||||
l = o.split("</c>")
|
balanced.append(o)
|
||||||
tmp.append(l[0])
|
|
||||||
l = l[1:]
|
|
||||||
for item in l:
|
|
||||||
tmp.append(endTag())
|
|
||||||
tmp.append(item)
|
|
||||||
else:
|
|
||||||
tmp.append(o)
|
|
||||||
btlen = 0
|
|
||||||
etlen = 0
|
|
||||||
retval = ""
|
|
||||||
newlist = tmp
|
|
||||||
for o in newlist:
|
|
||||||
if type(o) is beginTag:
|
|
||||||
retval += o.tag.replace("&", "&")
|
|
||||||
btlen +=1
|
|
||||||
elif type(o) is endTag:
|
|
||||||
if etlen >= btlen:
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
retval += "</c>"
|
balanced.append(o.string)
|
||||||
etlen += 1
|
|
||||||
else:
|
else:
|
||||||
retval += o.replace("&", "&").replace("<", "<").replace(">", ">")
|
balanced.append(o)
|
||||||
if btlen > etlen:
|
if beginc > endc:
|
||||||
for i in range(0, btlen-etlen):
|
for i in range(0, beginc-endc):
|
||||||
retval += "</c>"
|
balanced.append(colorEnd("</c>"))
|
||||||
return retval
|
|
||||||
|
escaped = ""
|
||||||
|
for o in balanced:
|
||||||
|
if type(o) in [str, unicode]:
|
||||||
|
if quirkobj:
|
||||||
|
o = quirkobj.apply(o)
|
||||||
|
if format == "html":
|
||||||
|
escaped += o.replace("&", "&").replace(">", ">").replace("<","<")
|
||||||
|
else:
|
||||||
|
escaped += o
|
||||||
|
else:
|
||||||
|
escaped += o.convert(format)
|
||||||
|
return escaped
|
||||||
|
|
||||||
|
|
||||||
def addTimeInitial(string, grammar):
|
def addTimeInitial(string, grammar):
|
||||||
endofi = string.find(":")
|
endofi = string.find(":")
|
||||||
|
@ -196,3 +207,5 @@ smiledict = {
|
||||||
":befuddled:": "what.gif",
|
":befuddled:": "what.gif",
|
||||||
":pumpkin:": "whatpumpkin.gif",
|
":pumpkin:": "whatpumpkin.gif",
|
||||||
":trollcool:": "trollcool.gif"}
|
":trollcool:": "trollcool.gif"}
|
||||||
|
|
||||||
|
_smilere = re.compile("|".join(smiledict.keys()))
|
||||||
|
|
BIN
parsetools.pyc
BIN
parsetools.pyc
Binary file not shown.
|
@ -9,6 +9,7 @@ import json
|
||||||
import codecs
|
import codecs
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
|
import platform
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
@ -66,7 +67,10 @@ class PesterLog(object):
|
||||||
os.mkdir("logs/%s/%s" % (self.handle, handle))
|
os.mkdir("logs/%s/%s" % (self.handle, handle))
|
||||||
fp = codecs.open("logs/%s/%s/%s.%s" % (self.handle, handle, handle, time), encoding='utf-8', mode='a')
|
fp = codecs.open("logs/%s/%s/%s.%s" % (self.handle, handle, handle, time), encoding='utf-8', mode='a')
|
||||||
self.convos[handle] = fp
|
self.convos[handle] = fp
|
||||||
self.convos[handle].write(msg+"\n")
|
if platform.system() == "Windows":
|
||||||
|
self.convos[handle].write(msg+"\r\n")
|
||||||
|
else:
|
||||||
|
self.convos[handle].write(msg+"\n")
|
||||||
self.convos[handle].flush()
|
self.convos[handle].flush()
|
||||||
def finish(self, handle):
|
def finish(self, handle):
|
||||||
if not self.convos.has_key(handle):
|
if not self.convos.has_key(handle):
|
||||||
|
|
1
profiles/doctorHorrible.js
Normal file
1
profiles/doctorHorrible.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"color": "#000000", "theme": "pesterchum", "quirks": [], "handle": "doctorHorrible"}
|
|
@ -1 +1 @@
|
||||||
{"color": "#ff00ff", "theme": "trollian", "quirks": [], "handle": "ghostDunk"}
|
{"color": "#ff00ff", "theme": "pesterchum", "quirks": [{"to": "7", "from": "t", "type": "replace"}], "handle": "ghostDunk"}
|
Loading…
Reference in a new issue