blob: 48c3bfe2a6b903c6fe8bb58ecf7d3b8f506f99ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
from common import *
class KPTilesetChooserDialog(QtGui.QDialog):
def __init__(self, label='Choose a tileset'):
QtGui.QDialog.__init__(self)
self.label = QtGui.QLabel(label)
self.label.setWordWrap(True)
# can't be assed to create a model
self.chooser = QtGui.QListWidget()
self.nameList = KP.map.tilesets.keys()
self.nameList.sort()
self.chooser.addItems(self.nameList)
self.chooser.currentRowChanged.connect(self.handleCurrentRowChanged)
self.chooser.itemActivated.connect(self.handleItemActivated)
self.buttons = QtGui.QDialogButtonBox(
QtGui.QDialogButtonBox.Ok |
QtGui.QDialogButtonBox.Cancel)
self.okButton = self.buttons.button(QtGui.QDialogButtonBox.Ok)
self.okButton.setEnabled(False)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.layout = QtGui.QVBoxLayout()
self.layout.addWidget(self.label)
self.layout.addWidget(self.chooser)
self.layout.addWidget(self.buttons)
self.setLayout(self.layout)
def handleCurrentRowChanged(self, row):
print row
self.okButton.setEnabled(row != -1)
def handleItemActivated(self, item):
self.accept()
def getChoice(self):
item = self.chooser.currentItem()
if item is None:
return None
else:
return str(item.text())
@classmethod
def run(cls, label=None):
dialog = cls(label)
result = dialog.exec_()
if result == QtGui.QDialog.Accepted:
return dialog.getChoice()
else:
return None
|