示例#1
0
    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 ) 
示例#2
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
示例#3
0
    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)
示例#4
0
    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)