# HG changeset patch # User windel # Date 1335937835 -7200 # Node ID 6fa41208a3a886d268e41b708244c5a6349e69fc # Parent b976546f5a604a9df66dae448be2a4a91a3043cd Rework into windowed system diff -r b976546f5a60 -r 6fa41208a3a8 applications/lab/diagrameditor.py --- a/applications/lab/diagrameditor.py Mon Apr 30 17:40:04 2012 +0200 +++ b/applications/lab/diagrameditor.py Wed May 02 07:50:35 2012 +0200 @@ -552,12 +552,35 @@ class DiagramEditor(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) - self.setWindowTitle("Diagram editor") # Widget layout and child widgets: self.horizontalLayout = QHBoxLayout(self) - self.libraryBrowserView = QListView(self) - self.libraryBrowserView.setMaximumWidth(160) + self.diagramScene = DiagramScene(self) + self.loadDiagram = self.diagramScene.loadDiagram + self.diagramView = EditorGraphicsView(self.diagramScene, self) + self.horizontalLayout.addWidget(self.diagramView) + + testShortcut = QShortcut(QKeySequence("F12"), self) + testShortcut.activated.connect(self.test) + delShort = QShortcut(QKeySequence.Delete, self) + delShort.activated.connect(self.diagramScene.deleteItem) + + def test(self): + self.diagramView.rotate(30) + self.zoomAll() + def save(self): + self.diagramScene.saveDiagram('diagram2.usd') + def load(self): + filename = QFileDialog.getOpenFileName(self) + self.diagramScene.loadDiagram(filename) + def zoomAll(self): + """ zoom to fit all items """ + rect = self.diagramScene.itemsBoundingRect() + self.diagramView.fitInView(rect, Qt.KeepAspectRatio) + +class LibraryWidget(QListView): + def __init__(self): + super(LibraryWidget, self).__init__(None) self.libraryModel = LibraryModel(self) self.libraryModel.setColumnCount(1) # Create an icon with an icon: @@ -576,38 +599,45 @@ self.libItems.append( QStandardItem(QIcon(pixmap), 'Device') ) for i in self.libItems: self.libraryModel.appendRow(i) - self.libraryBrowserView.setModel(self.libraryModel) - self.libraryBrowserView.setViewMode(self.libraryBrowserView.IconMode) - self.libraryBrowserView.setDragDropMode(self.libraryBrowserView.DragOnly) + self.setModel(self.libraryModel) + self.setViewMode(self.IconMode) + self.setDragDropMode(self.DragOnly) - self.diagramScene = DiagramScene(self) - self.loadDiagram = self.diagramScene.loadDiagram - self.diagramView = EditorGraphicsView(self.diagramScene, self) - self.horizontalLayout.addWidget(self.libraryBrowserView) - self.horizontalLayout.addWidget(self.diagramView) +class Main(QMainWindow): + def __init__(self): + super(Main, self).__init__(None) + self.editor = DiagramEditor() + self.setCentralWidget(self.editor) + self.setWindowTitle("Diagram editor") + toolbar = self.addToolBar('Tools') - fullScreenShortcut = QShortcut(QKeySequence("F11"), self) - fullScreenShortcut.activated.connect(self.toggleFullScreen) - saveShortcut = QShortcut(QKeySequence(QKeySequence.Save), self) - saveShortcut.activated.connect(self.save) - testShortcut = QShortcut(QKeySequence("F12"), self) - testShortcut.activated.connect(self.test) - zoomShortcut = QShortcut(QKeySequence("F8"), self) - zoomShortcut.activated.connect(self.zoomAll) - delShort = QShortcut(QKeySequence.Delete, self) - delShort.activated.connect(self.diagramScene.deleteItem) + saveAction = QAction('Save', self) + saveAction.setShortcuts(QKeySequence.Save) + saveAction.triggered.connect(self.editor.save) + toolbar.addAction(saveAction) + openAction = QAction('Open', self) + openAction.setShortcuts(QKeySequence.Open) + openAction.triggered.connect(self.editor.load) + toolbar.addAction(openAction) + fullScreenAction = QAction('Full screen', self) + fullScreenAction.setShortcuts(QKeySequence("F11")) + fullScreenAction.triggered.connect(self.toggleFullScreen) + toolbar.addAction(fullScreenAction) + zoomAction = QAction('Fit in view', self) + zoomAction.setShortcuts(QKeySequence('F8')) + zoomAction.triggered.connect(self.editor.zoomAll) + toolbar.addAction(zoomAction) - def test(self): - self.diagramView.rotate(30) - self.zoomAll() - def save(self): - self.diagramScene.saveDiagram('diagram2.usd') + self.library = LibraryWidget() + libraryDock = QDockWidget('Library', self) + libraryDock.setWidget(self.library) + self.addDockWidget(Qt.LeftDockWidgetArea, libraryDock) + + self.editor.loadDiagram('diagram2.usd') + def toggleFullScreen(self): self.setWindowState(self.windowState() ^ Qt.WindowFullScreen) - def zoomAll(self): - """ zoom to fit all items """ - rect = self.diagramScene.itemsBoundingRect() - self.diagramView.fitInView(rect, Qt.KeepAspectRatio) + self.editor.zoomAll() if __name__ == '__main__': if sys.version_info.major != 3: @@ -615,10 +645,9 @@ sys.exit(1) app = QApplication(sys.argv) - editor = DiagramEditor() - editor.loadDiagram('diagram2.usd') - editor.show() - editor.resize(700, 500) - editor.zoomAll() + main = Main() + main.show() + main.resize(700, 500) + main.editor.zoomAll() app.exec_()