]>
git.saurik.com Git - wxWidgets.git/blob - 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
.SetScrollbars(20, 20, maxWidth
/20, maxHeight
/20)
124 self
.SetBackgroundColour(wxWHITE
)
125 self
.diagram
= wxDiagram()
126 self
.SetDiagram(self
.diagram
)
127 self
.diagram
.SetCanvas(self
)
130 rRectBrush
= wxBrush(wxNamedColour("MEDIUM TURQUOISE"), wxSOLID
)
132 self
.MyAddShape(wxCircleShape(80), 100, 100, wxPen(wxBLUE
, 3), wxGREEN_BRUSH
, "Circle")
133 self
.MyAddShape(wxRectangleShape(85, 50), 305, 60, wxBLACK_PEN
, wxLIGHT_GREY_BRUSH
, "Rectangle")
134 self
.MyAddShape(DiamondShape(90, 90), 345, 235, wxPen(wxBLUE
, 3, wxDOT
), wxRED_BRUSH
, "Polygon")
135 self
.MyAddShape(RoundedRectangleShape(95,70), 140, 255, wxPen(wxRED
, 1), rRectBrush
, "Rounded Rect")
137 dc
= wxClientDC(self
)
139 for x
in range(len(self
.shapes
)):
140 fromShape
= self
.shapes
[x
]
141 if x
+1 == len(self
.shapes
):
142 toShape
= self
.shapes
[0]
144 toShape
= self
.shapes
[x
+1]
147 line
.SetPen(wxBLACK_PEN
)
148 line
.SetBrush(wxBLACK_BRUSH
)
149 line
.AddArrow(ARROW_ARROW
)
150 line
.MakeLineControlPoints(2)
151 fromShape
.AddLine(line
, toShape
)
152 self
.diagram
.AddShape(line
)
155 # for some reason, the shapes have to be moved for the line to show up...
156 fromShape
.Move(dc
, fromShape
.GetX(), fromShape
.GetY())
160 def MyAddShape(self
, shape
, x
, y
, pen
, brush
, text
):
161 shape
.SetDraggable(true
)
162 shape
.SetCanvas(self
)
166 shape
.SetBrush(brush
)
168 #shape.SetShadowMode(SHADOW_RIGHT)
169 self
.diagram
.AddShape(shape
)
172 evthandler
= MyEvtHandler(self
.log
, self
.frame
)
173 evthandler
.SetShape(shape
)
174 evthandler
.SetPreviousHandler(shape
.GetEventHandler())
175 shape
.SetEventHandler(evthandler
)
177 self
.shapes
.append(shape
)
181 for shape
in self
.diagram
.GetShapeList():
182 if shape
.GetParent() == None:
183 shape
.SetCanvas(None)
187 #----------------------------------------------------------------------
189 def runTest(frame
, nb
, log
):
190 win
= TestWindow(nb
, log
, frame
)
193 #----------------------------------------------------------------------
196 cleanup
= wxOGLCleanUp
200 # when this module gets cleaned up then wxOGLCleanUp() will get called
211 The Object Graphics Library is a library supporting the creation and
212 manipulation of simple and complex graphic images on a canvas.