From 386647ceb4508dcbc194b723e232627e3c0a2175 Mon Sep 17 00:00:00 2001 From: Treeki Date: Mon, 14 Nov 2011 03:51:43 +0100 Subject: layer list buttons now enabled/disabled properly --- src/ui.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') 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() -- cgit v1.2.3