def test_lib_oglRectangle(self): ogl.OGLInitialize() osc = ogl.ShapeCanvas(self.frame) self.diagram = ogl.Diagram() osc.SetDiagram(self.diagram) self.diagram.SetCanvas(osc) aShape = ogl.RectangleShape(w=50, h=50) aShape.SetCanvas(osc) self.diagram.AddShape(aShape)
def BootStrap(self): y = 0 for x in range(0, 1200, 70): shape = ogl.RectangleShape(60, 60) shape.AddText("%d,%d" % (x, y)) setpos(shape, x, y) self.umlwin.AddShape(shape) y += 70 self.umlwin.GetDiagram().ShowAll(1)
def __init__(self): wx.Frame.__init__(self, None, -1, "Demo", size=(300, 200), style=wx.DEFAULT_FRAME_STYLE) sizer = wx.BoxSizer(wx.VERTICAL) # put stuff into sizer canvas = ogl.ShapeCanvas(self) sizer.Add(canvas, 1, wx.GROW) canvas.SetBackgroundColour("LIGHT BLUE") # diagram = ogl.Diagram() canvas.SetDiagram(diagram) diagram.SetCanvas(canvas) shape = ogl.RectangleShape(60, 60) shape.SetX(30) shape.SetY(30) print shape.GetBoundingBoxMax() canvas.AddShape(shape) shape = ogl.RectangleShape(60, 60) shape.SetX(90) shape.SetY(30) canvas.AddShape(shape) shape = ogl.RectangleShape(60, 60) shape.SetX(150) shape.SetY(30) canvas.AddShape(shape) diagram.ShowAll(1) # apply sizer self.SetSizer(sizer) self.SetAutoLayout(1) self.Show(1)
def test_lib_oglLineShape(self): ogl.OGLInitialize() osc = ogl.ShapeCanvas(self.frame) self.diagram = ogl.Diagram() osc.SetDiagram(self.diagram) self.diagram.SetCanvas(osc) fromShape = ogl.RectangleShape(w=50, h=50) fromShape.SetCanvas(osc) self.diagram.AddShape(fromShape) toShape = ogl.RectangleShape(w=50, h=50) toShape.SetCanvas(osc) self.diagram.AddShape(toShape) lShape = ogl.LineShape() lShape.SetCanvas(osc) lShape.MakeLineControlPoints(2) fromShape.AddLine(lShape, toShape) self.diagram.AddShape(lShape) lShape.Show(True)
def createNodeShape(self, node): shape = ogl.RectangleShape( node.width, node.height ) shape.AddText(node.id) setpos(shape, node.left, node.top) #shape.SetDraggable(True, True) self.oglcanvas.AddShape( shape ) node.shape = shape shape.node = node # wire in the event handler for the new shape evthandler = MyEvtHandler(None, self.oglcanvas) evthandler.SetShape(shape) evthandler.SetPreviousHandler(shape.GetEventHandler()) shape.SetEventHandler(evthandler)
def __init__(self, canvas=None, frame=None, zoom=5.0, static=False, **kwargs): self.kwargs = kwargs self.zoom = zoom self.frame = frame self.canvas = canvas self.static = static name = kwargs['name'] kwargs['type'] type = kwargs['type'] x, y, w, h = self.set_coordinates(kwargs['x1'], kwargs['y1'], kwargs['x2'], kwargs['y2']) text = kwargs['text'] shape = self.shape = ogl.RectangleShape(w, h) if not static: shape.SetDraggable(True, True) shape.SetX(x) shape.SetY(y) #if pen: shape.SetPen(pen) #if brush: shape.SetBrush(brush) shape.SetBrush(wx.TRANSPARENT_BRUSH) if type not in ('L', 'B', 'BC'): if not static: pen = wx.LIGHT_GREY_PEN else: pen = wx.RED_PEN shape.SetPen(pen) self.text = kwargs['text'] evthandler = MyEvtHandler(self.evt_callback) evthandler.SetShape(shape) evthandler.SetPreviousHandler(shape.GetEventHandler()) shape.SetEventHandler(evthandler) shape.SetCentreResize(False) shape.SetMaintainAspectRatio(False) canvas.AddShape(shape)
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()
def test_lib_oglShapeRegion(self): ogl.OGLInitialize() osc = ogl.ShapeCanvas(self.frame) self.diagram = ogl.Diagram() osc.SetDiagram(self.diagram) self.diagram.SetCanvas(osc) aShape = ogl.RectangleShape(w=50, h=50) aShape.SetCanvas(osc) self.diagram.AddShape(aShape) region1 = ogl.ShapeRegion() region1.SetText('DividedShape') region1.SetProportions(0.0, 0.2) region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ) aShape.AddRegion(region1)
def BootStrap(self): # Add some shapes y = 30 for x in range(30, 1200, 70): shape = ogl.RectangleShape(60, 60) shape.SetX(x) shape.SetY(y) self.shapecanvas.AddShape(shape) y += 70 self.shapecanvas.GetDiagram().ShowAll(1) # Move the shapes, on a timer self.lastshape = 0 self.timer = wx.Timer(self, wx.ID_ANY) self.Bind(wx.EVT_TIMER, self.update, self.timer) self.timer.Start(100)
def createNodeShape(self, node): # FROM SPRING LAYOUT shape = ogl.RectangleShape(node.width, node.height) shape.AddText(node.id) setpos(shape, node.left, node.top) #shape.SetDraggable(True, True) self.AddShape(shape) node.shape = shape shape.node = node # wire in the event handler for the new shape evthandler = UmlShapeHandler( None, self.frame, self ) # just init the handler with whatever will be convenient for it to know. evthandler.SetShape(shape) evthandler.SetPreviousHandler(shape.GetEventHandler()) shape.SetEventHandler(evthandler) self.new_evthandler_housekeeping(evthandler)
def test_lib_oglDivisonShape(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) # create a division in the composite aShape.MakeContainer() # add a shape to the original division shape2 = ogl.RectangleShape(40, 60) aShape.GetDivisions()[0].AddChild(shape2)
def BootStrap(self): y = 0 for x in range(0, 1200, 70): shape = ogl.RectangleShape(60, 60) shape.AddText("%d,%d" % (x, y)) setpos(shape, x, y) self.umlwin.AddShape(shape) y += 70 self.umlwin.GetDiagram().ShowAll(1) print("bounds", self.GetBoundsAllShapes()) print("canvas.GetVirtualSize()", self.umlwin.GetVirtualSize()) print("canvas.GetSize()", self.umlwin.GetSize()) print("frame.GetVirtualSize()", self.frame.GetVirtualSize()) print("frame.GetSize()", self.frame.GetSize()) print("frame.GetClientSize()", self.frame.GetClientSize()) # MAGIC solution !!! width, height = self.GetBoundsAllShapes() self.umlwin.SetScrollbars(1, 1, width, height)
def __init__(self, canvas): ogl.CompositeShape.__init__(self) self.SetCanvas(canvas) # create a division in the composite self.MakeContainer() # add a shape to the original division shape2 = ogl.RectangleShape(40, 60) self.GetDivisions()[0].AddChild(shape2) # now divide the division so we get 2 self.GetDivisions()[0].Divide(wx.HORIZONTAL) # and add a shape to the second division (and move it to the # centre of the division) shape3 = ogl.CircleShape(40) shape3.SetBrush(wx.CYAN_BRUSH) self.GetDivisions()[1].AddChild(shape3) shape3.SetX(self.GetDivisions()[1].GetX()) for division in self.GetDivisions(): division.SetSensitivityFilter(0)
def MyAddShape(self, elt, x, y, W, H): if elt.Type == 'template': print 'adding shape template', elt.name, elt['card width'], elt[ 'card height'] brush = None pen = wx.BLACK_PEN if elt.Type == 'template': pen = wx.RED_PEN text = elt.name W = W or 85 H = H or 50 if elt.Type in ("staticimage", ): shape = ogl.BitmapShape() import os.path if elt['default'] and os.path.isfile(elt['default']): shape = ogl.BitmapShape() filename = elt['default'] #bmp=wx.Bitmap(filename) #bmp=bmp.ConvertToImage().Rescale(elt['width'],elt['height']).ConvertToBitmap() if elt['mask'] and os.path.isfile(elt['mask']): mask = wx.Bitmap(elt['mask']) bmp.SetMask(wx.Mask(mask)) shape.SetBitmap(bmp) else: dlg = wx.FileDialog( self, "Choose a Static Image for %s. Cancel for Dynamic." % elt.name, self.Parent.dir, "", "All Files(*.*)|*.*", wx.OPEN) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() #Change dir in parent from os.path import split self.Parent.dir = split(filename)[0] # Your code shape = ogl.BitmapShape() bmp = wx.Bitmap(filename) bmp = bmp.ConvertToImage().Rescale( elt['width'], elt['height']).ConvertToBitmap() if elt['mask'] and os.path.isfile(elt['mask']): mask = wx.Bitmap(elt['mask']) bmp.SetMask(wx.Mask(mask)) shape.SetBitmap(bmp) else: shape = ogl.RectangleShape(50, 50) finally: dlg.Destroy() #shape.SetSize(85,50,False) else: shape = BGMShape(elt) shape = ogl.RectangleShape(W, H) ########if elt.Type in ("image",): ######## import os.path ######## if elt['default'] and os.path.isfile(elt['default']): ######## shape=ogl.BitmapShape() ######## filename=elt['default'] ######## bmp=wx.Bitmap(filename) ######## bmp=bmp.ConvertToImage().Rescale(elt['width'],elt['height']).ConvertToBitmap() ######## if elt['mask'] and os.path.isfile(elt['mask']): ######## mask=wx.Bitmap(elt['mask']) ######## bmp.SetMask(wx.Mask(mask)) ######## shape.SetBitmap(bmp) ######## else: ######## shape=ogl.RectangleShape(50, 50) ########elif elt.Type in ('Set','Info'): ######## shape=ogl.Shape() ########else: ######## shape=ogl.RectangleShape(W, H) if elt.Type != 'template': shape.SetDraggable(True, True) else: shape.SetDraggable(False, False) shape.SetCanvas(self) shape.SetX(x) shape.SetY(y) #Custom stuff shape.text = text if pen: shape.SetPen(pen) if brush: shape.SetBrush(brush) if text: if elt.Type not in ('staticimage', ): for line in text.split('\n'): shape.AddText(line) #shape.SetShadowMode(ogl.SHADOW_RIGHT) self.diagram.AddShape(shape) shape.Show(True) evthandler = MyEvtHandler() evthandler.SetShape(shape) evthandler.SetPreviousHandler(shape.GetEventHandler()) shape.SetEventHandler(evthandler) self.shapes.append(shape) shape.SetCentreResize(False) shape.elt = elt if elt.Type == "template": print 'done adding', elt['card width'], elt['card height'] return shape
def __init__(self, canvas, component, wave_display): """__init__(self, canvas, component) Constructor for ComponentShape. Sets up default shape sizes, regions, and constraints.""" ogl.CompositeShape.__init__(self) self.compSizeX = 150 self.compSizeY = 100 ogl.DividedShape.__init__(self, self.compSizeX, self.compSizeY) self.SetCanvas(canvas) self.component = component self.canvas = canvas self.wave_display = wave_display # Stores reference to encapsulating object - handles tool updates self.portSizeX = 10 self.portSizeY = 10 self.gaugeSizeX = 50 self.gaugeSizeY = self.portSizeY self.portSpacing = 4 nameRegion = ogl.ShapeRegion() nameRegion.SetText(component.name) nameRegion.SetProportions(0.0, 0.1) nameRegion.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ) #nameRegion.SetFont(wx.Font(8, wx.SWISS, wx.BOLD, wx.BOLD)) self.AddRegion(nameRegion) self.SetRegionSizes() self.ReformatRegions(canvas) self.constraining_shape = ogl.RectangleShape(self.compSizeX, self.compSizeY) self.uses_shapes = [] self.prov_shapes = [] self.gauge_shapes = [] self.active_provides_port = None self.constraining_shape.SetBrush(wx.GREY_BRUSH) self.AddChild(self.constraining_shape) for p in component.ports: self.addPort(p) uses_constraints = [] provides_constraints = [] uses_constraints = self.createPortConstraints(self.constraining_shape, self.uses_shapes,"RIGHT") provides_constraints = self.createPortConstraints(self.constraining_shape, self.prov_shapes,"LEFT") for x in uses_constraints: self.AddConstraint(x) for x in provides_constraints: self.AddConstraint(x) self.setupTimingDisplay() self.Recompute() # If we don't do this, the shapes will be able to move on their # own, instead of moving the composite self.constraining_shape.SetDraggable(False) for x in self.uses_shapes: x.SetDraggable(False) for x in self.prov_shapes: x.SetDraggable(False) # If we don't do this the shape will take all left-clicks for itself self.constraining_shape.SetSensitivityFilter(0) # Setup a wx.Window so that we can support "right-click"ing self.window = wx.Window(self.GetCanvas(), id=-1, size=wx.Size(-1,-1)) self.window.Show(False) self.compPopup = wx.Menu(title='') self.usesMenu = wx.Menu(title='') self.providesMenu = wx.Menu(title='') self._init_compPopup_Items(self.compPopup)
def __init__(self, parent, log, frame): ogl.ShapeCanvas.__init__(self, parent) maxWidth = 1000 maxHeight = 1000 self.SetScrollbars(20, 20, maxWidth/20, maxHeight/20) self.log = log self.frame = frame self.SetBackgroundColour("LIGHT BLUE") #wx.WHITE) self.diagram = ogl.Diagram() self.SetDiagram(self.diagram) self.diagram.SetCanvas(self) self.shapes = [] self.save_gdi = [] rRectBrush = wx.Brush("MEDIUM TURQUOISE", wx.SOLID) dsBrush = wx.Brush("WHEAT", wx.SOLID) self.MyAddShape( CompositeDivisionShape(self), 270, 310, wx.BLACK_PEN, wx.BLUE_BRUSH, "Division" ) self.MyAddShape( CompositeShape(self), 100, 260, wx.BLACK_PEN, wx.RED_BRUSH, "Composite" ) self.MyAddShape( ogl.CircleShape(80), 75, 110, wx.Pen(wx.BLUE, 3), wx.GREEN_BRUSH, "Circle" ) self.MyAddShape( ogl.TextShape(120, 45), 160, 35, wx.GREEN_PEN, wx.LIGHT_GREY_BRUSH, "OGL is now a\npure Python lib!" ) self.MyAddShape( ogl.RectangleShape(85, 50), 305, 60, wx.BLACK_PEN, wx.LIGHT_GREY_BRUSH, "Rectangle" ) self.MyAddShape( DrawnShape(), 500, 80, wx.BLACK_PEN, wx.BLACK_BRUSH, "DrawnShape" ) ds = self.MyAddShape( DividedShape(140, 150, self), 520, 265, wx.BLACK_PEN, dsBrush, '' ) self.MyAddShape( DiamondShape(90, 90), 355, 260, wx.Pen(wx.BLUE, 3, wx.DOT), wx.RED_BRUSH, "Polygon" ) self.MyAddShape( RoundedRectangleShape(95, 70), 345, 145, wx.Pen(wx.RED, 2), rRectBrush, "Rounded Rect" ) bmp = images.Test2.GetBitmap() mask = wx.Mask(bmp, wx.BLUE) bmp.SetMask(mask) s = ogl.BitmapShape() s.SetBitmap(bmp) self.MyAddShape(s, 225, 130, None, None, "Bitmap") #dc = wx.ClientDC(self) #self.PrepareDC(dc) for x in range(len(self.shapes)): fromShape = self.shapes[x] if x+1 == len(self.shapes): toShape = self.shapes[0] else: toShape = self.shapes[x+1] line = ogl.LineShape() line.SetCanvas(self) line.SetPen(wx.BLACK_PEN) line.SetBrush(wx.BLACK_BRUSH) line.AddArrow(ogl.ARROW_ARROW) line.MakeLineControlPoints(2) fromShape.AddLine(line, toShape) self.diagram.AddShape(line) line.Show(True)
def __init__(self): wx.Frame.__init__(self, None, -1, "Demo", size=(500, 400), style=wx.DEFAULT_FRAME_STYLE) sizer = wx.BoxSizer(wx.VERTICAL) # put stuff into sizer canvas = ogl.ShapeCanvas(self) sizer.Add(canvas, 1, wx.GROW) canvas.SetBackgroundColour("LIGHT BLUE") # diagram = ogl.Diagram() canvas.SetDiagram(diagram) diagram.SetCanvas(canvas) def setpos(shape, x, y): width, height = shape.GetBoundingBoxMax() shape.SetX(x + width / 2) shape.SetY(y + height / 2) def getpos(shape): width, height = shape.GetBoundingBoxMax() x = shape.GetX() y = shape.GetY() return (x - width / 2, y - height / 2) shape = ogl.RectangleShape(60, 60) setpos(shape, 0, 0) canvas.AddShape(shape) shape = ogl.RectangleShape(160, 60) shape.SetTextColour('RED') setpos(shape, 160, 50) canvas.AddShape(shape) shape.AddText("Hello there") print[getpos(shape) for shape in canvas.GetDiagram().GetShapeList()] F = 'img_uml01.png' # wx.ImageFromBitmap(bitmap) and wx.BitmapFromImage(image) shape = ogl.BitmapShape() img = wx.Image(F, wx.BITMAP_TYPE_ANY) bmp = wx.BitmapFromImage(img) shape.SetBitmap(bmp) setpos(shape, 100, 260) canvas.AddShape(shape) shape = DiamondShape() setpos(shape, 10, 260) canvas.AddShape(shape) shape = Andy1Shape(100, 40) setpos(shape, 11, 111) canvas.AddShape(shape) shape = ogl.EllipseShape(120, 70) setpos(shape, 81, 150) shape.SetBrush(wx.Brush("WHEAT", wx.TRANSPARENT)) shape.AddText("<<Pattern>>") shape.AddText("Observer") shape.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1, wx.DOT)) canvas.AddShape(shape) diagram.ShowAll(1) # apply sizer self.SetSizer(sizer) self.SetAutoLayout(1) self.Show(1)
def __init__(self, canvas=None, frame=None, zoom=5.0, static=False, **kwargs): self.kwargs = kwargs self.zoom = zoom self.frame = frame self.canvas = canvas self.static = static name = kwargs['name'] type = kwargs['type'] x, y, w, h = self.set_coordinates(kwargs['x1'], kwargs['y1'], kwargs['x2'], kwargs['y2']) text = kwargs['text'] # If type is image, display it. if (type.lower() == 'i'): if os.path.exists(self.text): img = wx.Image(self.text) img.Rescale(w, h, quality=wx.IMAGE_QUALITY_HIGH) bmp = wx.BitmapFromImage(img) self.shape = ogl.BitmapShape() self.shape.SetBitmap(bmp) self.shape.SetFilename(self.text) shape = self.shape else: shape = self.shape = ogl.RectangleShape(w, h) else: shape = self.shape = ogl.RectangleShape(w, h) shape.SetMaintainAspectRatio(False) if static: shape.SetDraggable(False) shape.SetX(x) shape.SetY(y) #if pen: shape.SetPen(pen) #if brush: shape.SetBrush(brush) shape.SetBrush(wx.TRANSPARENT_BRUSH) if type not in ('L', 'B', 'BC'): if not static: pen = wx.LIGHT_GREY_PEN else: pen = wx.RED_PEN shape.SetPen(pen) self.text = kwargs['text'] evthandler = MyEvtHandler(self.evt_callback) evthandler.SetShape(shape) evthandler.SetPreviousHandler(shape.GetEventHandler()) shape.SetEventHandler(evthandler) shape.SetCentreResize(False) canvas.AddShape(shape)
import wx from fbogl1_gen import MyFrame2 import wx.lib.ogl as ogl app = wx.App() ogl.OGLInitialize() frame = MyFrame2(None) frame.Show() frame.SetSize((400, 400)) frame.canvas.SetBackgroundColour("LIGHT BLUE") # Optional - add a shape shape = ogl.RectangleShape(60, 60) shape.SetX(50) shape.SetY(50) frame.canvas.AddShape(shape) frame.canvas.GetDiagram().ShowAll(True) app.MainLoop()