Userlist search function + Improved hyperlink support

Hyperlinks must be preceded by a space.
FTP and Magnet hyperlinks are now supported.
The userlist now features a type-to-search function.
This commit is contained in:
oakwhiz 2012-06-04 09:43:56 -07:00
parent 95fd257fb7
commit 5db1906767
3 changed files with 17 additions and 7 deletions

View file

@ -405,7 +405,6 @@ class PesterText(QtGui.QTextEdit):
if event.modifiers() == QtCore.Qt.ControlModifier: if event.modifiers() == QtCore.Qt.ControlModifier:
QtGui.QApplication.clipboard().setText(url) QtGui.QApplication.clipboard().setText(url)
else: else:
if not unicode(url).startswith("http"): url = "http://" + url
QtGui.QDesktopServices.openUrl(QtCore.QUrl(url, QtCore.QUrl.TolerantMode)) QtGui.QDesktopServices.openUrl(QtCore.QUrl(url, QtCore.QUrl.TolerantMode))
QtGui.QTextEdit.mousePressEvent(self, event) QtGui.QTextEdit.mousePressEvent(self, event)
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):

View file

@ -1466,6 +1466,11 @@ class PesterUserlist(QtGui.QDialog):
self.setStyleSheet(self.theme["main/defaultwindow/style"]) self.setStyleSheet(self.theme["main/defaultwindow/style"])
self.resize(200, 600) self.resize(200, 600)
self.searchbox = QtGui.QLineEdit(self)
#self.searchbox.setStyleSheet(theme["convo/input/style"]) # which style is better?
self.searchbox.setPlaceholderText("Search")
self.connect(self.searchbox, QtCore.SIGNAL("textChanged(QString)"), self, QtCore.SLOT("updateUsers()"))
self.label = QtGui.QLabel("USERLIST") self.label = QtGui.QLabel("USERLIST")
self.userarea = RightClickList(self) self.userarea = RightClickList(self)
self.userarea.setStyleSheet(self.theme["main/chums/style"]) self.userarea.setStyleSheet(self.theme["main/chums/style"])
@ -1487,6 +1492,7 @@ class PesterUserlist(QtGui.QDialog):
layout_0 = QtGui.QVBoxLayout() layout_0 = QtGui.QVBoxLayout()
layout_0.addWidget(self.label) layout_0.addWidget(self.label)
layout_0.addWidget(self.searchbox)
layout_0.addWidget(self.userarea) layout_0.addWidget(self.userarea)
layout_0.addWidget(self.ok) layout_0.addWidget(self.ok)
@ -1505,9 +1511,10 @@ class PesterUserlist(QtGui.QDialog):
names = self.mainwindow.namesdb["#pesterchum"] names = self.mainwindow.namesdb["#pesterchum"]
self.userarea.clear() self.userarea.clear()
for n in names: for n in names:
item = QtGui.QListWidgetItem(n) if str(self.searchbox.text()) == "" or n.lower().find(str(self.searchbox.text()).lower()) != -1:
item.setTextColor(QtGui.QColor(self.theme["main/chums/userlistcolor"])) item = QtGui.QListWidgetItem(n)
self.userarea.addItem(item) item.setTextColor(QtGui.QColor(self.theme["main/chums/userlistcolor"]))
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)
def updateUserPresent(self, handle, channel, update): def updateUserPresent(self, handle, channel, update):
@ -1518,7 +1525,8 @@ class PesterUserlist(QtGui.QDialog):
elif update == "left" and c == "#pesterchum": elif update == "left" and c == "#pesterchum":
self.delUser(h) self.delUser(h)
elif update == "join" and c == "#pesterchum": elif update == "join" and c == "#pesterchum":
self.addUser(h) if str(self.searchbox.text()) == "" or n.lower().find(str(self.searchbox.text()).lower()) != -1:
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/userlistcolor"])) item.setTextColor(QtGui.QColor(self.theme["main/chums/userlistcolor"]))

View file

@ -12,7 +12,7 @@ _ctag_begin = re.compile(r'(?i)<c=(.*?)>')
_gtag_begin = re.compile(r'(?i)<g[a-f]>') _gtag_begin = re.compile(r'(?i)<g[a-f]>')
_ctag_end = 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)https?://[^\s]+") _urlre = re.compile(r"(?i)(?:^|(?<=\s))(?:(?:https?|ftp)://|magnet:)[^\s]+")
_url2re = re.compile(r"(?i)www\.[^\s]+") _url2re = re.compile(r"(?i)www\.[^\s]+")
_memore = re.compile(r"(\s|^)(#[A-Za-z0-9_]+)") _memore = re.compile(r"(\s|^)(#[A-Za-z0-9_]+)")
_handlere = re.compile(r"(\s|^)(@[A-Za-z0-9_]+)") _handlere = re.compile(r"(\s|^)(@[A-Za-z0-9_]+)")
@ -128,6 +128,9 @@ class hyperlink(object):
return "[url]%s[/url]" % (self.string) return "[url]%s[/url]" % (self.string)
else: else:
return self.string return self.string
class hyperlink_lazy(hyperlink):
def __init__(self, string):
self.string = "http://" + string
class imagelink(object): class imagelink(object):
def __init__(self, string, img): def __init__(self, string, img):
self.string = string self.string = string
@ -183,7 +186,7 @@ def lexMessage(string):
(colorEnd, _ctag_end), (colorEnd, _ctag_end),
(formatBegin, _format_begin), (formatEnd, _format_end), (formatBegin, _format_begin), (formatEnd, _format_end),
(imagelink, _imgre), (imagelink, _imgre),
(hyperlink, _urlre), (hyperlink, _url2re), (hyperlink, _urlre), (hyperlink_lazy, _url2re),
(memolex, _memore), (memolex, _memore),
(chumhandlelex, _handlere), (chumhandlelex, _handlere),
(smiley, _smilere)] (smiley, _smilere)]