from common import * from editorui import * class KPLayerList(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.layout = QtGui.QVBoxLayout() self.layout.setSpacing(0) self.model = KP.map.layerModel self.listView = QtGui.QListView() self.listView.setModel(self.model) self.layout.addWidget(self.listView) self.toolbar = QtGui.QToolBar() self.layout.addWidget(self.toolbar) self.setupToolbar(self.toolbar) 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) def selectedLayerIndex(self): return self.listView.selectionModel().currentIndex().row() def selectedLayer(self): return KP.map.layers[self.listView.selectionModel().currentIndex().row()] def addLayer(self): KP.map.appendLayer(KP.map.createNewLayer()) def removeLayer(self): KP.map.removeLayer(self.selectedLayer()) def moveUp(self): index = self.selectedLayerIndex() KP.map.moveLayer(index, index - 1) def moveDown(self): index = self.selectedLayerIndex() KP.map.moveLayer(index, index + 2) class KPMainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.editor = KPEditorWidget() self.setCentralWidget(self.editor) self.setupMenuBar() self.setupDocks() def setupMenuBar(self): mb = self.menuBar() m = mb.addMenu('&File') # ... def setupDocks(self): self.layerList = KPLayerList() self.layerListDock = QtGui.QDockWidget('Layers') self.layerListDock.setWidget(self.layerList) self.addDockWidget(Qt.RightDockWidgetArea, self.layerListDock)