From b336977192da8208e3fe1521e68f130c62ea9e04 Mon Sep 17 00:00:00 2001 From: Treeki Date: Mon, 14 Nov 2011 23:13:09 +0100 Subject: an abysmal extension to the KPTilesetChooserDialog API --- src/dialogs.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/dialogs.py b/src/dialogs.py index 48c3bfe..b033294 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -2,7 +2,7 @@ from common import * class KPTilesetChooserDialog(QtGui.QDialog): - def __init__(self, label='Choose a tileset'): + def __init__(self, label='Choose a tileset', specials=None): QtGui.QDialog.__init__(self) self.label = QtGui.QLabel(label) @@ -10,8 +10,14 @@ class KPTilesetChooserDialog(QtGui.QDialog): # can't be assed to create a model self.chooser = QtGui.QListWidget() + self.nameList = KP.map.tilesets.keys() self.nameList.sort() + + # this piece of the API is kinda shitty but whatever + self.specials = specials + if specials: + self.chooser.addItems(self.specials) self.chooser.addItems(self.nameList) self.chooser.currentRowChanged.connect(self.handleCurrentRowChanged) @@ -34,7 +40,6 @@ class KPTilesetChooserDialog(QtGui.QDialog): self.setLayout(self.layout) def handleCurrentRowChanged(self, row): - print row self.okButton.setEnabled(row != -1) def handleItemActivated(self, item): @@ -42,15 +47,20 @@ class KPTilesetChooserDialog(QtGui.QDialog): def getChoice(self): item = self.chooser.currentItem() + number = self.chooser.currentRow() + if item is None: return None else: - return str(item.text()) + if self.specials is not None and number < len(self.specials): + return number + else: + return str(item.text()) @classmethod - def run(cls, label=None): - dialog = cls(label) + def run(cls, *args): + dialog = cls(*args) result = dialog.exec_() if result == QtGui.QDialog.Accepted: -- cgit v1.2.3