summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dialogs.py61
-rw-r--r--src/ui.py9
2 files changed, 69 insertions, 1 deletions
diff --git a/src/dialogs.py b/src/dialogs.py
new file mode 100644
index 0000000..48c3bfe
--- /dev/null
+++ b/src/dialogs.py
@@ -0,0 +1,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
+
+
diff --git a/src/ui.py b/src/ui.py
index 58cc127..648cfa9 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -56,7 +56,13 @@ class KPLayerList(QtGui.QWidget):
def addLayer(self):
- KP.map.appendLayer(KP.map.createNewLayer())
+ from dialogs import KPTilesetChooserDialog
+
+ tilesetName = KPTilesetChooserDialog.run('Choose a tileset for the new layer')
+ if tilesetName is None:
+ return
+
+ KP.map.appendLayer(KP.map.createNewLayer(tilesetName))
self.setButtonStates()
def removeLayer(self):
@@ -69,6 +75,7 @@ class KPLayerList(QtGui.QWidget):
scene.removeItem(item)
KP.map.removeLayer(self.selectedLayer())
+ self.setButtonStates()
def moveUp(self):
index = self.selectedLayerIndex()