Mercurial > lcfOS
comparison applications/lab/diagrameditor.py @ 45:8a52263d67c4
Fixed width of library
author | windel |
---|---|
date | Sat, 18 Feb 2012 17:09:21 +0100 |
parents | cbf199e007c2 |
children | 7964065400b7 |
comparison
equal
deleted
inserted
replaced
44:cbf199e007c2 | 45:8a52263d67c4 |
---|---|
94 self.name = name | 94 self.name = name |
95 self.posCallbacks = [] | 95 self.posCallbacks = [] |
96 self.setFlag(self.ItemSendsScenePositionChanges, True) | 96 self.setFlag(self.ItemSendsScenePositionChanges, True) |
97 def itemChange(self, change, value): | 97 def itemChange(self, change, value): |
98 if change == self.ItemScenePositionHasChanged: | 98 if change == self.ItemScenePositionHasChanged: |
99 value = value.toPointF() # Required! | 99 #value = value.toPointF() # Required in python2??! |
100 for cb in self.posCallbacks: | 100 for cb in self.posCallbacks: |
101 cb(value) | 101 cb(value) |
102 return value | 102 return value |
103 return super(PortItem, self).itemChange(change, value) | 103 return super(PortItem, self).itemChange(change, value) |
104 def mousePressEvent(self, event): | 104 def mousePressEvent(self, event): |
115 self.setFlag(self.ItemSendsScenePositionChanges, True) | 115 self.setFlag(self.ItemSendsScenePositionChanges, True) |
116 self.setCursor(QtGui.QCursor(Qt.SizeFDiagCursor)) | 116 self.setCursor(QtGui.QCursor(Qt.SizeFDiagCursor)) |
117 | 117 |
118 def itemChange(self, change, value): | 118 def itemChange(self, change, value): |
119 if change == self.ItemPositionChange: | 119 if change == self.ItemPositionChange: |
120 value = value.toPointF() | 120 #value = value.toPointF() |
121 x, y = value.x(), value.y() | 121 x, y = value.x(), value.y() |
122 # TODO: make this a signal? | 122 # TODO: make this a signal? |
123 # This cannot be a signal because this is not a QObject | 123 # This cannot be a signal because this is not a QObject |
124 for cb in self.posChangeCallbacks: | 124 for cb in self.posChangeCallbacks: |
125 res = cb(x, y) | 125 res = cb(x, y) |
242 return ['component/name'] | 242 return ['component/name'] |
243 def mimeData(self, idxs): | 243 def mimeData(self, idxs): |
244 mimedata = QMimeData() | 244 mimedata = QMimeData() |
245 for idx in idxs: | 245 for idx in idxs: |
246 if idx.isValid(): | 246 if idx.isValid(): |
247 txt = self.data(idx, Qt.DisplayRole).toByteArray() | 247 #txt = self.data(idx, Qt.DisplayRole).toByteArray() # python2 |
248 txt = self.data(idx, Qt.DisplayRole) # python 3 | |
248 mimedata.setData('component/name', txt) | 249 mimedata.setData('component/name', txt) |
249 return mimedata | 250 return mimedata |
250 | 251 |
251 class DiagramScene(QGraphicsScene): | 252 class DiagramScene(QGraphicsScene): |
252 def __init__(self, parent=None): | 253 def __init__(self, parent=None): |
264 self.setWindowTitle("Diagram editor") | 265 self.setWindowTitle("Diagram editor") |
265 | 266 |
266 # Widget layout and child widgets: | 267 # Widget layout and child widgets: |
267 self.horizontalLayout = QtGui.QHBoxLayout(self) | 268 self.horizontalLayout = QtGui.QHBoxLayout(self) |
268 self.libraryBrowserView = QtGui.QListView(self) | 269 self.libraryBrowserView = QtGui.QListView(self) |
270 self.libraryBrowserView.setMaximumWidth(160) | |
269 self.libraryModel = LibraryModel(self) | 271 self.libraryModel = LibraryModel(self) |
270 self.libraryModel.setColumnCount(1) | 272 self.libraryModel.setColumnCount(1) |
271 # Create an icon with an icon: | 273 # Create an icon with an icon: |
272 pixmap = QPixmap(60, 60) | 274 pixmap = QPixmap(60, 60) |
273 pixmap.fill() | 275 pixmap.fill() |
324 if self.startedConnection.toPort == None: | 326 if self.startedConnection.toPort == None: |
325 self.startedConnection.delete() | 327 self.startedConnection.delete() |
326 self.startedConnection = None | 328 self.startedConnection = None |
327 | 329 |
328 if __name__ == '__main__': | 330 if __name__ == '__main__': |
331 if sys.version_info.major != 3: | |
332 print('Please use python 3.x') | |
333 sys.exit(1) | |
334 | |
329 app = QtGui.QApplication(sys.argv) | 335 app = QtGui.QApplication(sys.argv) |
330 global editor | 336 global editor |
331 editor = DiagramEditor() | 337 editor = DiagramEditor() |
332 editor.show() | 338 editor.show() |
333 editor.resize(700, 800) | 339 editor.resize(700, 800) |