Chum sorting options: Alphabetical, Mood.

Chum list options menu fix
This commit is contained in:
Kiooeht 2011-04-20 01:04:16 -07:00
parent 308024a93b
commit 926efa748e
2 changed files with 56 additions and 16 deletions

View file

@ -600,6 +600,14 @@ class PesterOptions(QtGui.QDialog):
self.showonlinenumbers = QtGui.QCheckBox("Show Number of Online Chums", self) self.showonlinenumbers = QtGui.QCheckBox("Show Number of Online Chums", self)
self.showonlinenumbers.setChecked(self.config.showOnlineNumbers()) self.showonlinenumbers.setChecked(self.config.showOnlineNumbers())
sortLabel = QtGui.QLabel("Sort Chums")
self.sortBox = QtGui.QComboBox(self)
self.sortBox.addItem("Alphabetically")
self.sortBox.addItem("By Mood")
method = self.config.sortMethod()
if method >= 0 and method < self.sortBox.count():
self.sortBox.setCurrentIndex(method)
self.ok = QtGui.QPushButton("OK", self) self.ok = QtGui.QPushButton("OK", self)
self.ok.setDefault(True) self.ok.setDefault(True)
self.connect(self.ok, QtCore.SIGNAL('clicked()'), self.connect(self.ok, QtCore.SIGNAL('clicked()'),
@ -618,6 +626,8 @@ class PesterOptions(QtGui.QDialog):
#layout_0.addWidget(self.groupscheck) #layout_0.addWidget(self.groupscheck)
layout_0.addWidget(self.showemptycheck) layout_0.addWidget(self.showemptycheck)
layout_0.addWidget(self.showonlinenumbers) layout_0.addWidget(self.showonlinenumbers)
layout_0.addWidget(sortLabel)
layout_0.addWidget(self.sortBox)
layout_0.addWidget(hr) layout_0.addWidget(hr)
layout_0.addWidget(self.timestampcheck) layout_0.addWidget(self.timestampcheck)
layout_0.addWidget(self.timestampBox) layout_0.addWidget(self.timestampBox)

View file

@ -286,6 +286,8 @@ class userConfig(object):
if not self.config.has_key('showSeconds'): if not self.config.has_key('showSeconds'):
self.set("showSeconds", False) self.set("showSeconds", False)
return self.config.get('showSeconds', False) return self.config.get('showSeconds', False)
def sortMethod(self):
return self.config.get('sortMethod', 0)
def useGroups(self): def useGroups(self):
if not self.config.has_key('useGroups'): if not self.config.has_key('useGroups'):
self.set("useGroups", False) self.set("useGroups", False)
@ -570,7 +572,7 @@ class chumArea(RightClickTree):
#self.sortItems(1, QtCore.Qt.AscendingOrder) #self.sortItems(1, QtCore.Qt.AscendingOrder)
self.setSortingEnabled(False) self.setSortingEnabled(False)
self.header().hide() self.header().hide()
self.setDropIndicatorShown(False) self.setDropIndicatorShown(True)
self.setIndentation(0) self.setIndentation(0)
self.setDragEnabled(True) self.setDragEnabled(True)
self.setDragDropMode(QtGui.QAbstractItemView.InternalMove) self.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
@ -579,17 +581,17 @@ class chumArea(RightClickTree):
self, QtCore.SLOT('expandGroup()')) self, QtCore.SLOT('expandGroup()'))
def getOptionsMenu(self): def getOptionsMenu(self):
currenthandle = self.currentItem().chum.handle text = str(self.currentItem().text(0))
if currenthandle in canon_handles: if text.rfind(" ") != -1:
return self.canonMenu text = text[0:text.rfind(" ")]
if text == "Chums":
return self.groupMenu
elif text in self.groups:
return self.groupMenu
else: else:
text = str(self.currentItem().text(0)) currenthandle = self.currentItem().chum.handle
if text.rfind(" ") != -1: if currenthandle in canon_handles:
text = text[0:text.rfind(" ")] return self.canonMenu
if text == "Chums":
return self.groupMenu
elif text in self.groups:
return self.groupMenu
else: else:
return self.optionsMenu return self.optionsMenu
@ -666,7 +668,7 @@ class chumArea(RightClickTree):
else: else:
i += 1 i += 1
listing = self.topLevelItem(j).child(i) listing = self.topLevelItem(j).child(i)
self.topLevelItem(j).sortChildren(0, QtCore.Qt.AscendingOrder) self.sort()
def showAllGroups(self): def showAllGroups(self):
curgroups = [] curgroups = []
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
@ -758,7 +760,7 @@ class chumArea(RightClickTree):
if self.mainwindow.config.openDefaultGroup(): if self.mainwindow.config.openDefaultGroup():
child_1.setExpanded(True) child_1.setExpanded(True)
self.topLevelItem(0).addChild(chumLabel) self.topLevelItem(0).addChild(chumLabel)
self.topLevelItem(0).sortChildren(0, QtCore.Qt.AscendingOrder) self.sort()
else: else:
if not self.findItems(chumLabel.handle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive): if not self.findItems(chumLabel.handle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive):
if not self.findItems(chumLabel.chum.group, QtCore.Qt.MatchContains): if not self.findItems(chumLabel.chum.group, QtCore.Qt.MatchContains):
@ -773,7 +775,7 @@ class chumArea(RightClickTree):
if text == chumLabel.chum.group: if text == chumLabel.chum.group:
break break
self.topLevelItem(i).addChild(chumLabel) self.topLevelItem(i).addChild(chumLabel)
self.topLevelItem(i).sortChildren(0, QtCore.Qt.AscendingOrder) self.sort()
else: # usually means this is now the trollslum else: # usually means this is now the trollslum
if not self.findItems(chumLabel.handle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive): if not self.findItems(chumLabel.handle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive):
self.topLevelItem(0).addChild(chumLabel) self.topLevelItem(0).addChild(chumLabel)
@ -806,8 +808,12 @@ class chumArea(RightClickTree):
self.takeItem(self.row(c)) self.takeItem(self.row(c))
chums = [] chums = []
for c in chums: for c in chums:
oldmood = c.mood if (hasattr(c, 'mood')):
c.setMood(mood) oldmood = c.mood
c.setMood(mood)
if self.mainwindow.config.sortMethod() == 1:
for i in range(self.topLevelItemCount()):
self.moodSort(i)
if self.mainwindow.config.showOnlineNumbers(): if self.mainwindow.config.showOnlineNumbers():
self.showOnlineNumbers() self.showOnlineNumbers()
return oldmood return oldmood
@ -844,6 +850,24 @@ class chumArea(RightClickTree):
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
c = c + self.topLevelItem(i).childCount() c = c + self.topLevelItem(i).childCount()
return c return c
def sort(self):
if self.mainwindow.config.sortMethod() == 1:
for i in range(self.topLevelItemCount()):
self.moodSort(i)
else:
for i in range(self.topLevelItemCount()):
self.topLevelItem(i).sortChildren(0, QtCore.Qt.AscendingOrder)
def moodSort(self, group):
chums = []
listing = self.topLevelItem(group).child(0)
while listing is not None:
chums.append(self.topLevelItem(group).takeChild(0))
listing = self.topLevelItem(group).child(0)
chums.sort(key=lambda x: ((999 if x.chum.mood.value() == 2 else x.chum.mood.value()), x.chum.handle), reverse=False)
for c in chums:
self.topLevelItem(group).addChild(c)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def activateChum(self): def activateChum(self):
self.itemActivated.emit(self.currentItem(), 0) self.itemActivated.emit(self.currentItem(), 0)
@ -2160,6 +2184,12 @@ class PesterWindow(MovingWindow):
elif chumsetting and not curchum: elif chumsetting and not curchum:
self.chumList.hideOfflineChums() self.chumList.hideOfflineChums()
self.config.set("hideOfflineChums", chumsetting) self.config.set("hideOfflineChums", chumsetting)
# sorting method
sortsetting = self.optionmenu.sortBox.currentIndex()
cursort = self.config.sortMethod()
self.config.set("sortMethod", sortsetting)
if sortsetting != cursort:
self.chumList.sort()
# sound # sound
soundsetting = self.optionmenu.soundcheck.isChecked() soundsetting = self.optionmenu.soundcheck.isChecked()
self.config.set("soundon", soundsetting) self.config.set("soundon", soundsetting)