# HG changeset patch # User windel # Date 1354036299 -3600 # Node ID 4b18920547443995eacb582f6b8a39f310f23a5c # Parent f3fe557be5ede46db518884fe4d9806c16589d46 Cleanup diff -r f3fe557be5ed -r 4b1892054744 python/apps/diagrameditor.py --- a/python/apps/diagrameditor.py Tue Nov 27 18:00:13 2012 +0100 +++ b/python/apps/diagrameditor.py Tue Nov 27 18:11:39 2012 +0100 @@ -4,7 +4,7 @@ from PyQt4.QtCore import * import sys, json, base64 -from diagramitems import Connection, ResizeSelectionHandle, BlockItem, DiagramScene +from diagramitems import Connection, ResizeSelectionHandle, Block, DiagramScene """ Author: Windel Bouwman diff -r f3fe557be5ed -r 4b1892054744 python/apps/diagramitems.py --- a/python/apps/diagramitems.py Tue Nov 27 18:00:13 2012 +0100 +++ b/python/apps/diagramitems.py Tue Nov 27 18:11:39 2012 +0100 @@ -97,15 +97,12 @@ line = QLineF(p1, p2) litem.setLine(line) citems = scene.collidingItems(litem) - citems = [i for i in citems if type(i) is BlockItem] + citems = [i for i in citems if type(i) is Block] scene.removeItem(litem) pts = [pos1] + vias + [pos2] self.arrowhead.setPos(pos2) self.arrowhead.setRotation(90) p = buildPath(pts) - pps = QPainterPathStroker() - pps.setWidth(3) - p = pps.createStroke(p).simplified() self.setPath(p) """ Create a shape outline using the path stroker """ s = super(Connection, self).shape() @@ -155,8 +152,7 @@ class Handle(QGraphicsEllipseItem): """ A handle that can be moved by the mouse """ - def __init__(self, parent=None): - dx = 13.0 + def __init__(self, dx=10.0, parent=None): super(Handle, self).__init__(QRectF(-0.5*dx,-0.5*dx,dx,dx), parent) self.posChangeCallbacks = [] self.setBrush(QBrush(Qt.white)) @@ -190,11 +186,10 @@ def mouseMoveEvent(self, event): self.scene().sizerMoveEvent(self, event.scenePos()) - -class BlockItem(QGraphicsRectItem): +class Block(QGraphicsRectItem): """ Represents a block in the diagram """ def __init__(self, name='Untitled', parent=None): - super(BlockItem, self).__init__(parent) + super(Block, self).__init__(parent) self.subModel = DiagramScene() self.subModel.containingBlock = self # Properties of the rectangle: @@ -278,7 +273,7 @@ if change == self.ItemSelectedHasChanged: for child in [self.buttonItemAddInput, self.buttonItemAddOutput]: child.setVisible(value) - return super(BlockItem, self).itemChange(change, value) + return super(Block, self).itemChange(change, value) def myDelete(self): for p in self.inputs + self.outputs: if p.connection: p.connection.myDelete() @@ -304,7 +299,6 @@ self.label.setPos((w - rect.width()) / 2, (h - rect.height()) / 2) self.updateSize() - class DiagramScene(QGraphicsScene): def __init__(self): super(DiagramScene, self).__init__() @@ -329,7 +323,7 @@ def handleSelectionChanged(self): [h.setVisible(False) for h in self.selectionHandles] items = self.selectedItems() - items = [i for i in items if type(i) is BlockItem] + items = [i for i in items if type(i) is Block] if items: r = QRectF() for i in items: @@ -349,17 +343,17 @@ print('invalid position') self.repositionAndShowHandles() items = self.selectedItems() - items = [i for i in items if type(i) is BlockItem] + items = [i for i in items if type(i) is Block] if items: item = items[0] # TODO resize more items! item.setCenterAndSize(self.selectionRect.center(), self.selectionRect.size()) - blocks = property(lambda sel: [i for i in sel.items() if type(i) is BlockItem]) + blocks = property(lambda sel: [i for i in sel.items() if type(i) is Block]) connections = property(lambda sel: [i for i in sel.items() if type(i) is Connection]) def setDict(self, d): for block in d['blocks']: - b = BlockItem() + b = Block() self.addItem(b) b.Dict = block for con in d['connections']: @@ -386,7 +380,7 @@ if block.name == blockname: return block def addNewBlock(self, pos, name): blocknames = [item.name for item in self.blocks] - b1 = BlockItem(uniqify(name, blocknames)) + b1 = Block(uniqify(name, blocknames)) b1.setPos(pos) self.addItem(b1) def mouseMoveEvent(self, event): @@ -411,3 +405,4 @@ self.addItem(self.startedConnection) def deleteItems(self): for item in list(self.selectedItems()): item.myDelete() +