annotate applications/lab/diagrameditor.py @ 48:a309982ab4d5

Added cool rotate function
author windel
date Tue, 27 Mar 2012 18:38:29 +0200
parents c4ec95a588ea
children 2b07ab2c0dc4
rev   line source
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
1 #!/usr/bin/python
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
2
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
3 from PyQt4.QtGui import *
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
4 from PyQt4.QtCore import *
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
5 import sys
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
6 import xml.dom.minidom as md
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
7
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
8 """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
9 This script implements a basic diagram editor.
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
10 """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
11
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
12 class Connection:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
13 """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
14 - fromPort
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
15 - list of line items in between
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
16 - toPort
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
17 """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
18 def __init__(self, fromPort, toPort):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
19 self.pos1 = None
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
20 self.pos2 = None
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
21 self.pathItem = QGraphicsPathItem()
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
22 pen = QPen()
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
23 pen.setWidth(4)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
24 pen.setColor(Qt.blue)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
25 pen.setCapStyle(Qt.RoundCap)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
26 self.pathItem.setPen(pen)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
27 #self.pathItem.setFlags(self.pathItem.ItemIsSelectable)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
28 editor.diagramScene.addItem(self.pathItem)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
29 self.setFromPort(fromPort)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
30 self.setToPort(toPort)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
31 def setFromPort(self, fromPort):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
32 self.fromPort = fromPort
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
33 if self.fromPort:
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
34 self.setBeginPos(fromPort.scenePos())
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
35 self.fromPort.posCallbacks.append(self.setBeginPos)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
36 def setToPort(self, toPort):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
37 self.toPort = toPort
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
38 if self.toPort:
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
39 self.setEndPos(toPort.scenePos())
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
40 self.toPort.posCallbacks.append(self.setEndPos)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
41 def setBeginPos(self, pos1):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
42 self.pos1 = pos1
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
43 self.updateLineStukken()
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
44 def setEndPos(self, endpos):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
45 self.pos2 = endpos
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
46 self.updateLineStukken()
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
47 def updateLineStukken(self):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
48 """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
49 This algorithm determines the optimal routing of all signals.
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
50 TODO: implement nice automatic line router
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
51 """
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
52 if self.pos1 is None or self.pos2 is None:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
53 return
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
54
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
55 ds = editor.diagramScene
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
56
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
57 # TODO: create pieces of lines.
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
58
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
59 # Determine the begin and end positions:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
60 p1 = self.pos1
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
61 p4 = self.pos2
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
62 x1, y1 = self.pos1.x(), self.pos1.y()
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
63 x4, y4 = self.pos2.x(), self.pos2.y()
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
64
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
65 def stripHits(hits):
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
66 """ Helper function that removes object hits """
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
67 hits = [hit for hit in hits if type(hit) is BlockItem]
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
68 if self.pathItem in hits:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
69 hits.remove(self.pathItem)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
70 if self.fromPort in hits:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
71 hits.remove(self.fromPort)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
72 if self.toPort in hits:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
73 hits.remove(self.toPort)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
74 return hits
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
75
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
76 def viaPoints(pA, pB):
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
77 # Construct intermediate points:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
78
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
79 pAB1 = QPointF(pA.x(), pB.y())
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
80 pAB2 = QPointF(pB.x(), pA.y())
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
81 path1 = QPainterPath(pA)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
82 path1.lineTo(pAB1)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
83 path2 = QPainterPath(pA)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
84 path2.lineTo(pAB2)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
85 if len(stripHits(ds.items(path1))) > len(stripHits(ds.items(path2))):
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
86 pAB = pAB2
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
87 else:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
88 pAB = pAB1
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
89 return [pAB]
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
90
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
91 # Determine left or right:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
92 dx = QPointF(10, 0)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
93 if len(stripHits(ds.items(p1 + dx))) > len(stripHits(ds.items(p1 - dx))):
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
94 p2 = p1 - dx
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
95 else:
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
96 p2 = p1 + dx
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
97
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
98 if len(stripHits(ds.items(p4 + dx))) > len(stripHits(ds.items(p4 - dx))):
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
99 p3 = p4 - dx
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
100 else:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
101 p3 = p4 + dx
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
102
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
103 path = QPainterPath(p1)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
104 path.lineTo(p2)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
105 # Now move from p2 to p3 without hitting blocks:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
106 pts = viaPoints(p2, p3)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
107 for pt in pts:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
108 path.lineTo(pt)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
109 path.lineTo(p3)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
110 path.lineTo(p4)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
111
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
112 hits = stripHits(ds.items(path))
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
113
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
114 #print('Items:', hits)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
115 self.pathItem.setPath(path)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
116
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
117 def delete(self):
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
118 editor.diagramScene.removeItem(self.pathItem)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
119 # Remove position update callbacks:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
120
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
121 class ParameterDialog(QDialog):
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
122 def __init__(self, parent = None):
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
123 super(ParameterDialog, self).__init__(parent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
124 self.button = QPushButton('Ok', self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
125 l = QVBoxLayout(self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
126 l.addWidget(self.button)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
127 self.button.clicked.connect(self.OK)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
128 def OK(self):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
129 self.close()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
130
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
131 class PortItem(QGraphicsEllipseItem):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
132 """ Represents a port to a subsystem """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
133 def __init__(self, name, parent=None):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
134 QGraphicsEllipseItem.__init__(self, QRectF(-6,-6,12.0,12.0), parent)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
135 self.setCursor(QCursor(Qt.CrossCursor))
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
136 # Properties:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
137 self.setBrush(QBrush(Qt.red))
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
138 # Name:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
139 self.name = name
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
140 self.posCallbacks = []
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
141 self.setFlag(self.ItemSendsScenePositionChanges, True)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
142 def itemChange(self, change, value):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
143 if change == self.ItemScenePositionHasChanged:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
144 for cb in self.posCallbacks:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
145 cb(value)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
146 return value
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
147 return super(PortItem, self).itemChange(change, value)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
148 def mousePressEvent(self, event):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
149 editor.startConnection(self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
150
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
151 # Block part:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
152 class HandleItem(QGraphicsEllipseItem):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
153 """ A handle that can be moved by the mouse """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
154 def __init__(self, parent=None):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
155 super(HandleItem, self).__init__(QRectF(-4.0,-4.0,8.0,8.0), parent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
156 self.posChangeCallbacks = []
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
157 self.setBrush(QBrush(Qt.white))
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
158 self.setFlags(self.ItemIsMovable | self.ItemSendsScenePositionChanges)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
159 self.setCursor(QCursor(Qt.SizeFDiagCursor))
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
160
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
161 def itemChange(self, change, value):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
162 if change == self.ItemPositionChange:
45
8a52263d67c4 Fixed width of library
windel
parents: 44
diff changeset
163 #value = value.toPointF()
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
164 x, y = value.x(), value.y()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
165 # TODO: make this a signal?
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
166 # This cannot be a signal because this is not a QObject
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
167 for cb in self.posChangeCallbacks:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
168 res = cb(x, y)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
169 if res:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
170 x, y = res
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
171 value = QPointF(x, y)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
172 return value
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
173 # Call superclass method:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
174 return super(HandleItem, self).itemChange(change, value)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
175
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
176 class BlockItem(QGraphicsRectItem):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
177 """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
178 Represents a block in the diagram
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
179 Has an x and y and width and height
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
180 width and height can only be adjusted with a tip in the lower right corner.
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
181
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
182 - in and output ports
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
183 - parameters
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
184 - description
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
185 """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
186 def __init__(self, name='Untitled', parent=None):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
187 super(BlockItem, self).__init__(parent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
188 w = 60.0
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
189 h = 40.0
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
190 # Properties of the rectangle:
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
191 self.setPen(QPen(Qt.blue, 2))
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
192 self.setBrush(QBrush(Qt.lightGray))
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
193 self.setFlags(self.ItemIsSelectable | self.ItemIsMovable)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
194 self.setCursor(QCursor(Qt.PointingHandCursor))
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
195 # Label:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
196 self.label = QGraphicsTextItem(name, self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
197 # Create corner for resize:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
198 self.sizer = HandleItem(self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
199 self.sizer.setPos(w, h)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
200 self.sizer.posChangeCallbacks.append(self.changeSize) # Connect the callback
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
201 #self.sizer.setVisible(False)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
202 self.sizer.setFlag(self.sizer.ItemIsSelectable, True)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
203
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
204 # Inputs and outputs of the block:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
205 self.inputs = []
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
206 self.inputs.append( PortItem('a', self) )
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
207 self.inputs.append( PortItem('b', self) )
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
208 self.inputs.append( PortItem('c', self) )
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
209 self.outputs = []
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
210 self.outputs.append( PortItem('y', self) )
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
211 # Update size:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
212 self.changeSize(w, h)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
213 def editParameters(self):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
214 pd = ParameterDialog(self.window())
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
215 pd.exec_()
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
216 def addInput(self, i):
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
217 self.inputs.append(i)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
218 def addOutput(self, o):
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
219 self.outputs.append(o)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
220
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
221 def contextMenuEvent(self, event):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
222 menu = QMenu()
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
223 da = menu.addAction('Delete')
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
224 da.triggered.connect(self.delete)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
225 pa = menu.addAction('Parameters')
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
226 pa.triggered.connect(self.editParameters)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
227 menu.exec_(event.screenPos())
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
228
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
229 def delete(self):
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
230 editor.diagramScene.removeItem(self)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
231 # TODO: remove connections
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
232
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
233 def changeSize(self, w, h):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
234 """ Resize block function """
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
235 # Limit the block size:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
236 if h < 20:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
237 h = 20
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
238 if w < 40:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
239 w = 40
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
240 self.setRect(0.0, 0.0, w, h)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
241 # center label:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
242 rect = self.label.boundingRect()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
243 lw, lh = rect.width(), rect.height()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
244 lx = (w - lw) / 2
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
245 ly = (h - lh) / 2
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
246 self.label.setPos(lx, ly)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
247 # Update port positions:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
248 if len(self.inputs) == 1:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
249 self.inputs[0].setPos(-4, h / 2)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
250 elif len(self.inputs) > 1:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
251 y = 5
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
252 dy = (h - 10) / (len(self.inputs) - 1)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
253 for inp in self.inputs:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
254 inp.setPos(-4, y)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
255 y += dy
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
256 if len(self.outputs) == 1:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
257 self.outputs[0].setPos(w+4, h / 2)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
258 elif len(self.outputs) > 1:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
259 y = 5
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
260 dy = (h - 10) / (len(self.outputs) + 0)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
261 for outp in self.outputs:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
262 outp.setPos(w+4, y)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
263 y += dy
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
264 return w, h
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
265
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
266 class EditorGraphicsView(QGraphicsView):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
267 def __init__(self, scene, parent=None):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
268 QGraphicsView.__init__(self, scene, parent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
269 def dragEnterEvent(self, event):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
270 if event.mimeData().hasFormat('component/name'):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
271 event.accept()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
272 def dragMoveEvent(self, event):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
273 if event.mimeData().hasFormat('component/name'):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
274 event.accept()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
275 def dropEvent(self, event):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
276 if event.mimeData().hasFormat('component/name'):
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
277 name = bytes(event.mimeData().data('component/name')).decode()
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
278 b1 = BlockItem(name)
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
279 print(event.pos())
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
280 b1.setPos(self.mapToScene(event.pos()))
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
281 print(self.mapToScene(event.pos()))
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
282 self.scene().addItem(b1)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
283
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
284 class LibraryModel(QStandardItemModel):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
285 def __init__(self, parent=None):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
286 QStandardItemModel.__init__(self, parent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
287 def mimeTypes(self):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
288 return ['component/name']
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
289 def mimeData(self, idxs):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
290 mimedata = QMimeData()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
291 for idx in idxs:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
292 if idx.isValid():
45
8a52263d67c4 Fixed width of library
windel
parents: 44
diff changeset
293 #txt = self.data(idx, Qt.DisplayRole).toByteArray() # python2
8a52263d67c4 Fixed width of library
windel
parents: 44
diff changeset
294 txt = self.data(idx, Qt.DisplayRole) # python 3
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
295 mimedata.setData('component/name', txt)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
296 return mimedata
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
297
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
298 class DiagramScene(QGraphicsScene):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
299 def __init__(self, parent=None):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
300 super(DiagramScene, self).__init__(parent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
301 def mouseMoveEvent(self, mouseEvent):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
302 editor.sceneMouseMoveEvent(mouseEvent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
303 super(DiagramScene, self).mouseMoveEvent(mouseEvent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
304 def mouseReleaseEvent(self, mouseEvent):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
305 editor.sceneMouseReleaseEvent(mouseEvent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
306 super(DiagramScene, self).mouseReleaseEvent(mouseEvent)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
307
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
308 class DiagramEditor(QWidget):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
309 def __init__(self, parent=None):
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
310 QWidget.__init__(self, parent)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
311 self.setWindowTitle("Diagram editor")
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
312
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
313 # Widget layout and child widgets:
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
314 self.horizontalLayout = QHBoxLayout(self)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
315 self.libraryBrowserView = QListView(self)
45
8a52263d67c4 Fixed width of library
windel
parents: 44
diff changeset
316 self.libraryBrowserView.setMaximumWidth(160)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
317 self.libraryModel = LibraryModel(self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
318 self.libraryModel.setColumnCount(1)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
319 # Create an icon with an icon:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
320 pixmap = QPixmap(60, 60)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
321 pixmap.fill()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
322 painter = QPainter(pixmap)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
323 painter.fillRect(10, 10, 40, 40, Qt.blue)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
324 painter.setBrush(Qt.red)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
325 painter.drawEllipse(36, 2, 20, 20)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
326 painter.setBrush(Qt.yellow)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
327 painter.drawEllipse(20, 20, 20, 20)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
328 painter.end()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
329
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
330 self.libItems = []
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
331 self.libItems.append( QStandardItem(QIcon(pixmap), 'Block') )
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
332 self.libItems.append( QStandardItem(QIcon(pixmap), 'Uber Unit') )
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
333 self.libItems.append( QStandardItem(QIcon(pixmap), 'Device') )
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
334 for i in self.libItems:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
335 self.libraryModel.appendRow(i)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
336 self.libraryBrowserView.setModel(self.libraryModel)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
337 self.libraryBrowserView.setViewMode(self.libraryBrowserView.IconMode)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
338 self.libraryBrowserView.setDragDropMode(self.libraryBrowserView.DragOnly)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
339
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
340 self.diagramScene = DiagramScene(self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
341 self.diagramView = EditorGraphicsView(self.diagramScene, self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
342 self.horizontalLayout.addWidget(self.libraryBrowserView)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
343 self.horizontalLayout.addWidget(self.diagramView)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
344
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
345 self.startedConnection = None
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
346 fullScreenShortcut = QShortcut(QKeySequence("F11"), self)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
347 fullScreenShortcut.activated.connect(self.toggleFullScreen)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
348 saveShortcut = QShortcut(QKeySequence(QKeySequence.Save), self)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
349 saveShortcut.activated.connect(self.save)
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
350 testShortcut = QShortcut(QKeySequence("F12"), self)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
351 testShortcut.activated.connect(self.test)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
352 zoomShortcut = QShortcut(QKeySequence("F8"), self)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
353 zoomShortcut.activated.connect(self.zoomAll)
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
354 self.loadDiagram('diagram2.usd')
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
355
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
356 def test(self):
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
357 self.diagramView.rotate(11)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
358 def save(self):
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
359 self.saveDiagram('diagram2.usd')
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
360
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
361 def saveDiagram(self, filename):
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
362 items = self.diagramScene.items()
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
363 blocks = [item for item in items if type(item) is BlockItem]
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
364
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
365 doc = md.Document()
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
366 modelElement = doc.createElement('system')
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
367 doc.appendChild(modelElement)
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
368 for block in blocks:
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
369 blockElement = doc.createElement("block")
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
370 x, y = block.scenePos().x(), block.scenePos().y()
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
371 rect = block.rect()
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
372 w, h = rect.width(), rect.height()
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
373 blockElement.setAttribute("name", block.label.toPlainText())
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
374 blockElement.setAttribute("x", str(x))
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
375 blockElement.setAttribute("y", str(y))
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
376 blockElement.setAttribute("width", str(w))
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
377 blockElement.setAttribute("height", str(h))
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
378 for inp in block.inputs:
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
379 portElement = doc.createElement("input")
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
380 portElement.setAttribute("name", inp.name)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
381 blockElement.appendChild(portElement)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
382 for outp in block.outputs:
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
383 portElement = doc.createElement("output")
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
384 portElement.setAttribute("name", outp.name)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
385 blockElement.appendChild(portElement)
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
386 modelElement.appendChild(blockElement)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
387 with open(filename, 'w') as f:
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
388 f.write(doc.toprettyxml())
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
389
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
390 def loadDiagram(self, filename):
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
391 try:
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
392 doc = md.parse(filename)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
393 except IOError as e:
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
394 print('{0} not found'.format(filename))
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
395 return
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
396 sysElements = doc.getElementsByTagName('system')
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
397 blockElements = doc.getElementsByTagName('block')
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
398 for sysElement in sysElements:
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
399 blockElements = sysElement.getElementsByTagName('block')
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
400 for blockElement in blockElements:
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
401 x = float(blockElement.getAttribute('x'))
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
402 y = float(blockElement.getAttribute('y'))
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
403 w = float(blockElement.getAttribute('width'))
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
404 h = float(blockElement.getAttribute('height'))
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
405 name = blockElement.getAttribute('name')
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
406 block = BlockItem(name)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
407 self.diagramScene.addItem(block)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
408 block.setPos(x, y)
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
409 block.sizer.setPos(w, h)
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
410 # Load ports:
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
411 portElements = blockElement.getElementsByTagName('port')
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
412 for portElement in portElements:
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
413 print(portElement)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
414 connectionElements = sysElement.getElementsByTagName('connection')
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
415 for connectionElement in connectionElements:
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
416 print(connectionElement)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
417 self.zoomAll()
47
c4ec95a588ea Fixed save to xml
windel
parents: 46
diff changeset
418
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
419 def toggleFullScreen(self):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
420 self.setWindowState(self.windowState() ^ Qt.WindowFullScreen)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
421 def startConnection(self, port):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
422 self.startedConnection = Connection(port, None)
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
423 def zoomAll(self):
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
424 """ zoom to fit all items """
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
425 rect = self.diagramScene.itemsBoundingRect()
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
426 print(rect)
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
427 self.diagramView.fitInView(rect, Qt.KeepAspectRatio)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
428 def sceneMouseMoveEvent(self, event):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
429 if self.startedConnection:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
430 pos = event.scenePos()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
431 self.startedConnection.setEndPos(pos)
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
432 def sceneMouseReleaseEvent(self, event):
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
433 # Clear the actual connection:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
434 if self.startedConnection:
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
435 items = self.diagramScene.items(event.scenePos())
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
436 for item in items:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
437 if type(item) is PortItem:
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
438 self.startedConnection.setToPort(item)
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
439 self.startedConnection = None
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
440 return
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
441 self.startedConnection.delete()
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
442 del self.startedConnection
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
443 self.startedConnection = None
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
444
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
445 if __name__ == '__main__':
45
8a52263d67c4 Fixed width of library
windel
parents: 44
diff changeset
446 if sys.version_info.major != 3:
8a52263d67c4 Fixed width of library
windel
parents: 44
diff changeset
447 print('Please use python 3.x')
8a52263d67c4 Fixed width of library
windel
parents: 44
diff changeset
448 sys.exit(1)
8a52263d67c4 Fixed width of library
windel
parents: 44
diff changeset
449
46
7964065400b7 Added xml save function
windel
parents: 45
diff changeset
450 app = QApplication(sys.argv)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
451 global editor
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
452 editor = DiagramEditor()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
453 editor.show()
48
a309982ab4d5 Added cool rotate function
windel
parents: 47
diff changeset
454 editor.resize(700, 500)
44
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
455 app.exec_()
cbf199e007c2 Added some demo applications
windel
parents:
diff changeset
456