summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ui.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/ui.py b/src/ui.py
index 2b89d39..c594966 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -22,15 +22,24 @@ class KPLayerList(QtGui.QWidget):
self.layout.addWidget(self.toolbar)
self.setupToolbar(self.toolbar)
+ self.setButtonStates()
self.setLayout(self.layout)
def setupToolbar(self, tb):
- tb.addAction(QtGui.QIcon(), 'Add', self.addLayer)
- tb.addAction(QtGui.QIcon(), 'Remove', self.removeLayer)
- tb.addAction(QtGui.QIcon(), 'Move Up', self.moveUp)
- tb.addAction(QtGui.QIcon(), 'Move Down', self.moveDown)
+ self.actAdd = tb.addAction(QtGui.QIcon(), 'Add', self.addLayer)
+ self.actRemove = tb.addAction(QtGui.QIcon(), 'Remove', self.removeLayer)
+ self.actMoveUp = tb.addAction(QtGui.QIcon(), 'Move Up', self.moveUp)
+ self.actMoveDown = tb.addAction(QtGui.QIcon(), 'Move Down', self.moveDown)
+
+
+ def setButtonStates(self):
+ index = self.selectedLayerIndex()
+
+ self.actRemove.setEnabled((index != -1) and (len(KP.map.layers) > 1))
+ self.actMoveUp.setEnabled(index > 0)
+ self.actMoveDown.setEnabled((index != -1) and (index < (len(KP.map.layers) - 1)))
def selectedLayerIndex(self):
@@ -43,10 +52,12 @@ class KPLayerList(QtGui.QWidget):
@QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex)
def handleRowChanged(self, current, previous):
self.selectedLayerChanged.emit(KP.map.layers[current.row()])
+ self.setButtonStates()
def addLayer(self):
KP.map.appendLayer(KP.map.createNewLayer())
+ self.setButtonStates()
def removeLayer(self):
layer = self.selectedLayer()