# HG changeset patch # User windel # Date 1332866309 -7200 # Node ID a309982ab4d522189d54d39981fadef37c1d083b # Parent c4ec95a588ea3e371acf66b977f3a43ce7613901 Added cool rotate function diff -r c4ec95a588ea -r a309982ab4d5 applications/lab/diagrameditor.py --- a/applications/lab/diagrameditor.py Tue Mar 27 07:29:59 2012 +0200 +++ b/applications/lab/diagrameditor.py Tue Mar 27 18:38:29 2012 +0200 @@ -3,7 +3,6 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * import sys -#from elementtree.SimpleXMLWriter import XMLWriter import xml.dom.minidom as md """ @@ -214,6 +213,10 @@ def editParameters(self): pd = ParameterDialog(self.window()) pd.exec_() + def addInput(self, i): + self.inputs.append(i) + def addOutput(self, o): + self.outputs.append(o) def contextMenuEvent(self, event): menu = QMenu() @@ -271,9 +274,11 @@ event.accept() def dropEvent(self, event): if event.mimeData().hasFormat('component/name'): - name = str(event.mimeData().data('component/name')) + name = bytes(event.mimeData().data('component/name')).decode() b1 = BlockItem(name) + print(event.pos()) b1.setPos(self.mapToScene(event.pos())) + print(self.mapToScene(event.pos())) self.scene().addItem(b1) class LibraryModel(QStandardItemModel): @@ -342,8 +347,14 @@ 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) self.loadDiagram('diagram2.usd') + def test(self): + self.diagramView.rotate(11) def save(self): self.saveDiagram('diagram2.usd') @@ -364,6 +375,14 @@ blockElement.setAttribute("y", str(y)) blockElement.setAttribute("width", str(w)) blockElement.setAttribute("height", str(h)) + for inp in block.inputs: + portElement = doc.createElement("input") + portElement.setAttribute("name", inp.name) + blockElement.appendChild(portElement) + for outp in block.outputs: + portElement = doc.createElement("output") + portElement.setAttribute("name", outp.name) + blockElement.appendChild(portElement) modelElement.appendChild(blockElement) with open(filename, 'w') as f: f.write(doc.toprettyxml()) @@ -375,13 +394,9 @@ print('{0} not found'.format(filename)) return sysElements = doc.getElementsByTagName('system') - print('systems:',sysElements) blockElements = doc.getElementsByTagName('block') - print('blocks:', blockElements) for sysElement in sysElements: - print('system:', sysElement) blockElements = sysElement.getElementsByTagName('block') - print('blocks:', blockElements) for blockElement in blockElements: x = float(blockElement.getAttribute('x')) y = float(blockElement.getAttribute('y')) @@ -392,11 +407,24 @@ self.diagramScene.addItem(block) block.setPos(x, y) block.sizer.setPos(w, h) + # Load ports: + portElements = blockElement.getElementsByTagName('port') + for portElement in portElements: + print(portElement) + connectionElements = sysElement.getElementsByTagName('connection') + for connectionElement in connectionElements: + print(connectionElement) + self.zoomAll() def toggleFullScreen(self): self.setWindowState(self.windowState() ^ Qt.WindowFullScreen) def startConnection(self, port): self.startedConnection = Connection(port, None) + def zoomAll(self): + """ zoom to fit all items """ + rect = self.diagramScene.itemsBoundingRect() + print(rect) + self.diagramView.fitInView(rect, Qt.KeepAspectRatio) def sceneMouseMoveEvent(self, event): if self.startedConnection: pos = event.scenePos() @@ -423,6 +451,6 @@ global editor editor = DiagramEditor() editor.show() - editor.resize(700, 800) + editor.resize(700, 500) app.exec_()