def createPortConstraints(self, constraining_shape, shapes, orientation): """Create the contstraints needed to display the ports in relation to the component. Uses ports on the right and provides ports on the left.""" if len(shapes) == 0: return [] if orientation == "RIGHT": position = ogl.CONSTRAINT_RIGHT_OF else: position = ogl.CONSTRAINT_LEFT_OF constraints = [] if len(shapes) > 0: constraints.append(ogl.Constraint(position,constraining_shape, [shapes[0]])) topShape = bottomShape = shapes[0] for x in range(1,len(shapes)): constraints.append(ogl.Constraint(ogl.CONSTRAINT_ALIGNED_LEFT, topShape, [shapes[x]])) tmpCon = None if x%2: tmpCon = ogl.Constraint(ogl.CONSTRAINT_ABOVE, topShape, [shapes[x]]) constraints.append(tmpCon) tmpCon.SetSpacing(0,self.portSpacing) topShape = shapes[x] else: tmpCon = ogl.Constraint(ogl.CONSTRAINT_BELOW, bottomShape, [shapes[x]]) constraints.append(tmpCon) tmpCon.SetSpacing(0,self.portSpacing) bottomShape = shapes[x] return constraints else: return None
def createGaugeConstraint(self, constraining_shape, shape): """Create the contraints used to display the gauges in relation to uses ports they represent.""" position1 = ogl.CONSTRAINT_LEFT_OF constraint = ogl.Constraint(position1, constraining_shape, [shape]) self.AddConstraint(constraint) position2 = ogl.CONSTRAINT_CENTRED_VERTICALLY constraint = ogl.Constraint(position2, constraining_shape, [shape]) self.AddConstraint(constraint)
def __init__(self, canvas): ogl.CompositeShape.__init__(self) self.SetCanvas(canvas) constraining_shape = ogl.RectangleShape(120, 100) constrained_shape1 = ogl.CircleShape(50) constrained_shape2 = ogl.RectangleShape(80, 20) constraining_shape.SetBrush(wx.BLUE_BRUSH) constrained_shape2.SetBrush(wx.RED_BRUSH) self.AddChild(constraining_shape) self.AddChild(constrained_shape1) self.AddChild(constrained_shape2) constraint = ogl.Constraint(ogl.CONSTRAINT_MIDALIGNED_BOTTOM, constraining_shape, [constrained_shape1, constrained_shape2]) self.AddConstraint(constraint) self.Recompute() # If we don't do this, the shapes will be able to move on their # own, instead of moving the composite constraining_shape.SetDraggable(False) constrained_shape1.SetDraggable(False) constrained_shape2.SetDraggable(False) # If we don't do this the shape will take all left-clicks for itself constraining_shape.SetSensitivityFilter(0)
def test_lib_oglCompositeShape(self): ogl.OGLInitialize() osc = ogl.ShapeCanvas(self.frame) self.diagram = ogl.Diagram() osc.SetDiagram(self.diagram) self.diagram.SetCanvas(osc) aShape = ogl.CompositeShape() aShape.SetCanvas(osc) self.diagram.AddShape(aShape) constraining_shape = ogl.RectangleShape(120, 100) constrained_shape1 = ogl.CircleShape(50) constrained_shape2 = ogl.RectangleShape(80, 20) aShape.AddChild(constraining_shape) aShape.AddChild(constrained_shape1) aShape.AddChild(constrained_shape2) constraint = ogl.Constraint(ogl.CONSTRAINT_MIDALIGNED_BOTTOM, constraining_shape, [constrained_shape1, constrained_shape2]) aShape.AddConstraint(constraint) aShape.Recompute()