X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f847103a32507f629c581fa900d95e97dfe16df0..d1b736b7968ceea4233f3fceecdb01173f68a9a3:/wxPython/demo/OGL.py diff --git a/wxPython/demo/OGL.py b/wxPython/demo/OGL.py index cb9b11e8ff..f0709c75a9 100644 --- a/wxPython/demo/OGL.py +++ b/wxPython/demo/OGL.py @@ -8,6 +8,10 @@ # o Changed to use the python version of OGL # o Added TextShape, CompositeShape and CompositeShape with divisions # +# 20040830 - Pierre Hjälm +# +# o Added DrawnShape +# import wx import wx.lib.ogl as ogl @@ -16,6 +20,38 @@ import images #---------------------------------------------------------------------- +class DrawnShape(ogl.DrawnShape): + def __init__(self): + ogl.DrawnShape.__init__(self) + + self.SetDrawnBrush(wx.WHITE_BRUSH) + self.SetDrawnPen(wx.BLACK_PEN) + self.DrawArc((0, -10), (30, 0), (-30, 0)) + + self.SetDrawnPen(wx.Pen("#ff8030")) + self.DrawLine((-30, 5), (30, 5)) + + self.SetDrawnPen(wx.Pen("#00ee10")) + self.DrawRoundedRectangle((-20, 10, 40, 10), 5) + + self.SetDrawnPen(wx.Pen("#9090f0")) + self.DrawEllipse((-30, 25, 60, 20)) + + self.SetDrawnTextColour(wx.BLACK) + self.SetDrawnFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL)) + self.DrawText("DrawText", (-26, 28)) + + self.SetDrawnBrush(wx.GREEN_BRUSH) + self.DrawPolygon([(-100, 5), (-45, 30), (-35, 20), (-30, 5)]) + + self.SetDrawnPen(wx.BLACK_PEN) + self.DrawLines([(30, -45), (40, -45), (40 ,45), (30, 45)]) + + # Make sure to call CalculateSize when all drawing is done + self.CalculateSize() + +#---------------------------------------------------------------------- + class DiamondShape(ogl.PolygonShape): def __init__(self, w=0.0, h=0.0): ogl.PolygonShape.__init__(self) @@ -175,7 +211,8 @@ class MyEvtHandler(ogl.ShapeEvtHandler): if shape.Selected(): shape.Select(False, dc) - canvas.Redraw(dc) + #canvas.Redraw(dc) + canvas.Refresh(False) else: redraw = False shapeList = canvas.GetDiagram().GetShapeList() @@ -194,7 +231,8 @@ class MyEvtHandler(ogl.ShapeEvtHandler): for s in toUnselect: s.Select(False, dc) - canvas.Redraw(dc) + ##canvas.Redraw(dc) + canvas.Refresh(False) self.UpdateStatusBar(shape) @@ -215,9 +253,11 @@ class MyEvtHandler(ogl.ShapeEvtHandler): def OnMovePost(self, dc, x, y, oldX, oldY, display): + shape = self.GetShape() ogl.ShapeEvtHandler.OnMovePost(self, dc, x, y, oldX, oldY, display) - self.UpdateStatusBar(self.GetShape()) - + self.UpdateStatusBar(shape) + if "wxMac" in wx.PlatformInfo: + shape.GetCanvas().Refresh(False) def OnRightClick(self, *dontcare): self.log.WriteText("%s\n" % self.GetShape()) @@ -247,7 +287,7 @@ class TestWindow(ogl.ShapeCanvas): self.MyAddShape( CompositeDivisionShape(self), - 310, 310, wx.BLACK_PEN, wx.BLUE_BRUSH, "Division" + 270, 310, wx.BLACK_PEN, wx.BLUE_BRUSH, "Division" ) self.MyAddShape( @@ -257,12 +297,12 @@ class TestWindow(ogl.ShapeCanvas): self.MyAddShape( ogl.CircleShape(80), - 100, 100, wx.Pen(wx.BLUE, 3), wx.GREEN_BRUSH, "Circle" + 75, 110, wx.Pen(wx.BLUE, 3), wx.GREEN_BRUSH, "Circle" ) self.MyAddShape( - ogl.TextShape(45, 30), - 205, 60, wx.GREEN_PEN, wx.LIGHT_GREY_BRUSH, "Text" + ogl.TextShape(120, 45), + 160, 35, wx.GREEN_PEN, wx.LIGHT_GREY_BRUSH, "OGL is now a\npure Python lib!" ) self.MyAddShape( @@ -270,14 +310,19 @@ class TestWindow(ogl.ShapeCanvas): 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), - 515, 145, wx.BLACK_PEN, dsBrush, '' + 520, 265, wx.BLACK_PEN, dsBrush, '' ) self.MyAddShape( DiamondShape(90, 90), - 445, 305, wx.Pen(wx.BLUE, 3, wx.DOT), wx.RED_BRUSH, "Polygon" + 355, 260, wx.Pen(wx.BLUE, 3, wx.DOT), wx.RED_BRUSH, "Polygon" ) self.MyAddShape( @@ -293,8 +338,8 @@ class TestWindow(ogl.ShapeCanvas): s.SetBitmap(bmp) self.MyAddShape(s, 225, 130, None, None, "Bitmap") - dc = wx.ClientDC(self) - self.PrepareDC(dc) + #dc = wx.ClientDC(self) + #self.PrepareDC(dc) for x in range(len(self.shapes)): fromShape = self.shapes[x] @@ -327,7 +372,9 @@ class TestWindow(ogl.ShapeCanvas): shape.SetY(y) if pen: shape.SetPen(pen) if brush: shape.SetBrush(brush) - if text: shape.AddText(text) + if text: + for line in text.split('\n'): + shape.AddText(line) #shape.SetShadowMode(ogl.SHADOW_RIGHT) self.diagram.AddShape(shape) shape.Show(True) @@ -375,14 +422,6 @@ Pierre Hj less likely to get rusty because nobody cares about the C++ lib any more. -
The Python version should be mostly drop-in compatible with the -wrapped C++ version, except for the location of the package -(wx.lib.ogl instead of wx.ogl) and that the base class methods are -called the normal Python way (superclass.Method(self, ...)) instead of the -hacky way that had to be done to support overloaded methods with the -old SWIG (self.base_Method(...)) - - """ if __name__ == '__main__':