]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxOGL.py
2 from wxPython
.wx
import *
3 from wxPython
.ogl
import *
5 #----------------------------------------------------------------------
6 # This creates some pens and brushes that the OGL library uses.
10 #----------------------------------------------------------------------
12 class DiamondShape(wxPolygonShape
):
13 def __init__(self
, w
=0.0, h
=0.0):
14 wxPolygonShape
.__init
__(self
)
20 ## Either wxRealPoints or 2-tuples of floats works.
22 #points = [ wxRealPoint(0.0, -h/2.0),
23 # wxRealPoint(w/2.0, 0.0),
24 # wxRealPoint(0.0, h/2.0),
25 # wxRealPoint(-w/2.0, 0.0),
27 points
= [ (0.0, -h
/2.0),
36 #----------------------------------------------------------------------
38 class RoundedRectangleShape(wxRectangleShape
):
39 def __init__(self
, w
=0.0, h
=0.0):
40 wxRectangleShape
.__init
__(self
, w
, h
)
41 self
.SetCornerRadius(-0.3)
44 #----------------------------------------------------------------------
46 class MyEvtHandler(wxShapeEvtHandler
):
47 def __init__(self
, log
, frame
):
48 wxShapeEvtHandler
.__init
__(self
)
50 self
.statbarFrame
= frame
53 def UpdateStatusBar(self
, shape
):
54 x
,y
= shape
.GetX(), shape
.GetY()
55 width
, height
= shape
.GetBoundingBoxMax()
56 self
.statbarFrame
.SetStatusText("Pos: (%d,%d) Size: (%d, %d)" %
57 (x
, y
, width
, height
))
60 def OnLeftClick(self
, x
, y
, keys
= 0, attachment
= 0):
61 shape
= self
.GetShape()
62 canvas
= shape
.GetCanvas()
63 dc
= wxClientDC(canvas
)
67 shape
.Select(false
, dc
)
71 shapeList
= canvas
.GetDiagram().GetShapeList()
75 # If we unselect it now then some of the objects in
76 # shapeList will become invalid (the control points are
77 # shapes too!) and bad things will happen...
80 shape
.Select(true
, dc
)
87 self
.UpdateStatusBar(shape
)
90 def OnEndDragLeft(self
, x
, y
, keys
= 0, attachment
= 0):
91 shape
= self
.GetShape()
92 self
.base_OnEndDragLeft(x
, y
, keys
, attachment
)
93 if not shape
.Selected():
94 self
.OnLeftClick(x
, y
, keys
, attachment
)
95 self
.UpdateStatusBar(shape
)
98 def OnSize(self
, x
, y
):
99 self
.base_OnSize(x
, y
)
100 self
.UpdateStatusBar(self
.GetShape())
103 # def OnMovePost(self, dc, x, y, oldX, oldY, display):
104 # self.base_OnMovePost(dc, x, y, oldX, oldY, display)
105 # self.UpdateStatusBar(self.GetShape())
108 def OnRightClick(self
, *dontcare
):
109 self
.log
.WriteText("%s\n" % self
.GetShape())
112 #----------------------------------------------------------------------
114 class TestWindow(wxShapeCanvas
):
115 def __init__(self
, parent
, log
, frame
):
116 wxShapeCanvas
.__init
__(self
, parent
)
120 self
.SetBackgroundColour(wxWHITE
)
121 self
.diagram
= wxDiagram()
122 self
.SetDiagram(self
.diagram
)
123 self
.diagram
.SetCanvas(self
)
126 rRectBrush
= wxBrush(wxNamedColour("MEDIUM TURQUOISE"), wxSOLID
)
128 self
.MyAddShape(wxCircleShape(80), 100, 100, wxPen(wxBLUE
, 3), wxGREEN_BRUSH
, "Circle")
129 self
.MyAddShape(wxRectangleShape(85, 50), 305, 60, wxBLACK_PEN
, wxLIGHT_GREY_BRUSH
, "Rectangle")
130 self
.MyAddShape(DiamondShape(90, 90), 345, 235, wxPen(wxBLUE
, 3, wxDOT
), wxRED_BRUSH
, "Polygon")
131 self
.MyAddShape(RoundedRectangleShape(95,70), 140, 255, wxPen(wxRED
, 1), rRectBrush
, "Rounded Rect")
133 dc
= wxClientDC(self
)
135 for x
in range(len(self
.shapes
)):
136 fromShape
= self
.shapes
[x
]
137 if x
+1 == len(self
.shapes
):
138 toShape
= self
.shapes
[0]
140 toShape
= self
.shapes
[x
+1]
143 line
.SetPen(wxBLACK_PEN
)
144 line
.SetBrush(wxBLACK_BRUSH
)
145 line
.AddArrow(ARROW_ARROW
)
146 line
.MakeLineControlPoints(2)
147 fromShape
.AddLine(line
, toShape
)
148 self
.diagram
.AddShape(line
)
151 # for some reason, the shapes have to be moved for the line to show up...
152 fromShape
.Move(dc
, fromShape
.GetX(), fromShape
.GetY())
156 def MyAddShape(self
, shape
, x
, y
, pen
, brush
, text
):
157 shape
.SetDraggable(true
)
158 shape
.SetCanvas(self
)
162 shape
.SetBrush(brush
)
164 #shape.SetShadowMode(SHADOW_RIGHT)
165 self
.diagram
.AddShape(shape
)
168 evthandler
= MyEvtHandler(self
.log
, self
.frame
)
169 evthandler
.SetShape(shape
)
170 evthandler
.SetPreviousHandler(shape
.GetEventHandler())
171 shape
.SetEventHandler(evthandler
)
173 self
.shapes
.append(shape
)
177 for shape
in self
.diagram
.GetShapeList():
178 if shape
.GetParent() == None:
179 shape
.SetCanvas(None)
183 #----------------------------------------------------------------------
185 def runTest(frame
, nb
, log
):
186 win
= TestWindow(nb
, log
, frame
)
189 #----------------------------------------------------------------------
192 cleanup
= wxOGLCleanUp
196 # when this module gets cleaned up then wxOGLCleanUp() will get called
207 The Object Graphics Library is a library supporting the creation and
208 manipulation of simple and complex graphic images on a canvas.