from common import * from editorui import * class KPLayerList(QtGui.QWidget): class LayerModel(QtCore.QAbstractListModel): def headerData(self, section, orientation, role = Qt.DisplayRole): return 'Layer' def rowCount(self, parent): return len(KP.map.layers) def data(self, index, role = Qt.DisplayRole): try: if role == Qt.DisplayRole and index.isValid(): return KP.map.layers[index.row()].name except IndexError: pass return QVariant() def __init__(self): QtGui.QWidget.__init__(self) self.layout = QtGui.QVBoxLayout() self.model = KPLayerList.LayerModel() self.listWidget = QtGui.QListView() self.listWidget.setModel(self.model) self.layout.addWidget(self.listWidget) self.toolbar = QtGui.QToolBar() self.layout.addWidget(self.toolbar) self.setLayout(self.layout) 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)