From 63fe5fc612fd806fb43d5651469804b16ed38c37 Mon Sep 17 00:00:00 2001 From: Kiooeht Date: Sun, 17 Apr 2011 00:46:11 -0700 Subject: [PATCH] Switch individual quirks on and off --- dataobjs.py | 7 ++++++- menus.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/dataobjs.py b/dataobjs.py index b3e22d4..3879555 100644 --- a/dataobjs.py +++ b/dataobjs.py @@ -49,8 +49,13 @@ class pesterQuirk(object): raise ValueError("Quirks must be given a dictionary") self.quirk = quirk self.type = self.quirk["type"] + if "on" not in self.quirk: + self.quirk["on"] = True + self.on = self.quirk["on"] def apply(self, string, first=False, last=False): - if self.type == "prefix": + if not self.on: + return string + elif self.type == "prefix": return self.quirk["value"] + string elif self.type == "suffix": return string + self.quirk["value"] diff --git a/menus.py b/menus.py index 2402705..ed9380f 100644 --- a/menus.py +++ b/menus.py @@ -37,6 +37,22 @@ class PesterQuirkList(QtGui.QListWidget): self.setDragEnabled(True) self.setDragDropMode(QtGui.QAbstractItemView.InternalMove) + def addItem(self, item): + self.connect(self, QtCore.SIGNAL('itemChanged(QListWidgetItem *)'), + self, QtCore.SLOT('changeCheckState()')) + item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) + if item.quirk.on: + item.setCheckState(2) + else: + item.setCheckState(0) + QtGui.QListWidget.addItem(self, item) + + @QtCore.pyqtSlot() + def changeCheckState(self): + item = self.currentItem() + if not item: return + item.quirk.quirk["on"] = item.quirk.on = (item.checkState() == QtCore.Qt.Checked) + def currentQuirk(self): return self.item(self.currentRow())