]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FloatCanvas.py
3 #print "running:", wx.__version__
4 ##First, make sure Numeric or numarray can be imported.
10 # Numeric isn't there, let's try numarray
12 import numarray
as Numeric
13 import numarray
.random_array
as RandomArray
16 # numarray isn't there either
19 "The FloatCanvas requires either the Numeric or numarray module\n\n"
20 "You can get them at:\n"
21 "http://sourceforge.net/projects/numpy\n\n"
22 "NOTE: The Numeric module is substantially faster than numarray for this\n"
23 "purpose, if you have lots of objects\n"
26 #---------------------------------------------------------------------------
29 def BuildDrawFrame(): # this gets called when needed, rather than on import
31 from floatcanvas
import NavCanvas
, FloatCanvas
, Resources
32 except ImportError: # if it's not there locally, try the wxPython lib.
33 from wx
.lib
.floatcanvas
import NavCanvas
, FloatCanvas
, Resources
34 import wx
.lib
.colourdb
37 class DrawFrame(wx
.Frame
):
40 A frame used for the FloatCanvas Demo
45 def __init__(self
,parent
, id,title
,position
,size
):
46 wx
.Frame
.__init
__(self
,parent
, id,title
,position
, size
)
49 MenuBar
= wx
.MenuBar()
52 item
= file_menu
.Append(-1, "&Close","Close this frame")
53 self
.Bind(wx
.EVT_MENU
, self
.OnQuit
, item
)
55 item
= file_menu
.Append(-1, "&SavePNG","Save the current image as a PNG")
56 self
.Bind(wx
.EVT_MENU
, self
.OnSavePNG
, item
)
57 MenuBar
.Append(file_menu
, "&File")
61 item
= draw_menu
.Append(-1, "&Clear","Clear the Canvas")
62 self
.Bind(wx
.EVT_MENU
, self
.Clear
, item
)
64 item
= draw_menu
.Append(-1, "&Draw Test","Run a test of drawing random components")
65 self
.Bind(wx
.EVT_MENU
, self
.DrawTest
, item
)
67 item
= draw_menu
.Append(-1, "&Line Test","Run a test of drawing random lines")
68 self
.Bind(wx
.EVT_MENU
, self
.LineTest
, item
)
70 item
= draw_menu
.Append(-1, "Draw &Map","Run a test of drawing a map")
71 self
.Bind(wx
.EVT_MENU
, self
.DrawMap
, item
)
73 item
= draw_menu
.Append(-1, "&Text Test","Run a test of text drawing")
74 self
.Bind(wx
.EVT_MENU
, self
.TestText
, item
)
76 item
= draw_menu
.Append(-1, "&ScaledText Test","Run a test of text drawing")
77 self
.Bind(wx
.EVT_MENU
, self
.TestScaledText
, item
)
79 item
= draw_menu
.Append(-1, "&ScaledTextBox Test","Run a test of the Scaled Text Box")
80 self
.Bind(wx
.EVT_MENU
, self
.TestScaledTextBox
, item
)
82 item
= draw_menu
.Append(-1, "&Bitmap Test","Run a test of the Bitmap Object")
83 self
.Bind(wx
.EVT_MENU
, self
.TestBitmap
, item
)
85 item
= draw_menu
.Append(-1, "&Hit Test","Run a test of the hit test code")
86 self
.Bind(wx
.EVT_MENU
, self
.TestHitTest
, item
)
88 item
= draw_menu
.Append(-1, "Hit Test &Foreground","Run a test of the hit test code with a foreground Object")
89 self
.Bind(wx
.EVT_MENU
, self
.TestHitTestForeground
, item
)
91 item
= draw_menu
.Append(-1, "&Animation","Run a test of Animation")
92 self
.Bind(wx
.EVT_MENU
, self
.TestAnimation
, item
)
94 #item = draw_menu.Append(-1, "&Speed","Run a test of Drawing Speed")
95 #self.Bind(wx.EVT_MENU, self.SpeedTest, item)
97 item
= draw_menu
.Append(-1, "Change &Properties","Run a test of Changing Object Properties")
98 self
.Bind(wx
.EVT_MENU
, self
.PropertiesChangeTest
, item
)
100 item
= draw_menu
.Append(-1, "&Arrows","Run a test of Arrows")
101 self
.Bind(wx
.EVT_MENU
, self
.ArrowTest
, item
)
103 item
= draw_menu
.Append(-1, "&Hide","Run a test of the Show() Hide() Show() and methods")
104 self
.Bind(wx
.EVT_MENU
, self
.HideTest
, item
)
106 MenuBar
.Append(draw_menu
, "&Tests")
108 view_menu
= wx
.Menu()
109 item
= view_menu
.Append(-1, "Zoom to &Fit","Zoom to fit the window")
110 self
.Bind(wx
.EVT_MENU
, self
.ZoomToFit
, item
)
111 MenuBar
.Append(view_menu
, "&View")
113 help_menu
= wx
.Menu()
114 item
= help_menu
.Append(-1, "&About",
115 "More information About this program")
116 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, item
)
117 MenuBar
.Append(help_menu
, "&Help")
119 self
.SetMenuBar(MenuBar
)
121 self
.CreateStatusBar()
125 self
.Canvas
= NavCanvas
.NavCanvas(self
,
127 BackgroundColor
= "DARK SLATE BLUE")
129 self
.MsgWindow
= wx
.TextCtrl(self
, wx
.ID_ANY
,
130 "Look Here for output from events\n",
131 style
= (wx
.TE_MULTILINE |
136 ##Create a sizer to manage the Canvas and message window
137 MainSizer
= wx
.BoxSizer(wx
.VERTICAL
)
138 MainSizer
.Add(self
.Canvas
, 4, wx
.EXPAND
)
139 MainSizer
.Add(self
.MsgWindow
, 1, wx
.EXPAND | wx
.ALL
, 5)
141 self
.SetSizer(MainSizer
)
142 wx
.EVT_CLOSE(self
, self
.OnCloseWindow
)
144 FloatCanvas
.EVT_MOTION(self
.Canvas
, self
.OnMove
)
146 self
.EventsAreBound
= False
148 ## getting all the colors for random objects
149 wx
.lib
.colourdb
.updateColourDB()
150 self
.colors
= wx
.lib
.colourdb
.getColourList()
156 self
.MsgWindow
.AppendText(text
)
157 if not text
[-1] == "\n":
158 self
.MsgWindow
.AppendText("\n")
161 def BindAllMouseEvents(self
):
162 if not self
.EventsAreBound
:
163 ## Here is how you catch FloatCanvas mouse events
164 FloatCanvas
.EVT_LEFT_DOWN(self
.Canvas
, self
.OnLeftDown
)
165 FloatCanvas
.EVT_LEFT_UP(self
.Canvas
, self
.OnLeftUp
)
166 FloatCanvas
.EVT_LEFT_DCLICK(self
.Canvas
, self
.OnLeftDouble
)
168 FloatCanvas
.EVT_MIDDLE_DOWN(self
.Canvas
, self
.OnMiddleDown
)
169 FloatCanvas
.EVT_MIDDLE_UP(self
.Canvas
, self
.OnMiddleUp
)
170 FloatCanvas
.EVT_MIDDLE_DCLICK(self
.Canvas
, self
.OnMiddleDouble
)
172 FloatCanvas
.EVT_RIGHT_DOWN(self
.Canvas
, self
.OnRightDown
)
173 FloatCanvas
.EVT_RIGHT_UP(self
.Canvas
, self
.OnRightUp
)
174 FloatCanvas
.EVT_RIGHT_DCLICK(self
.Canvas
, self
.OnRightDouble
)
176 FloatCanvas
.EVT_MOUSEWHEEL(self
.Canvas
, self
.OnWheel
)
177 self
.EventsAreBound
= True
179 def UnBindAllMouseEvents(self
):
180 ## Here is how you unbind FloatCanvas mouse events
181 FloatCanvas
.EVT_LEFT_DOWN(self
.Canvas
, None )
182 FloatCanvas
.EVT_LEFT_UP(self
.Canvas
, None )
183 FloatCanvas
.EVT_LEFT_DCLICK(self
.Canvas
, None)
185 FloatCanvas
.EVT_MIDDLE_DOWN(self
.Canvas
, None )
186 FloatCanvas
.EVT_MIDDLE_UP(self
.Canvas
, None )
187 FloatCanvas
.EVT_MIDDLE_DCLICK(self
.Canvas
, None )
189 FloatCanvas
.EVT_RIGHT_DOWN(self
.Canvas
, None )
190 FloatCanvas
.EVT_RIGHT_UP(self
.Canvas
, None )
191 FloatCanvas
.EVT_RIGHT_DCLICK(self
.Canvas
, None )
193 FloatCanvas
.EVT_MOUSEWHEEL(self
.Canvas
, None )
194 FloatCanvas
.EVT_LEFT_DOWN(self
.Canvas
, None )
195 FloatCanvas
.EVT_LEFT_UP(self
.Canvas
, None )
196 FloatCanvas
.EVT_LEFT_DCLICK(self
.Canvas
, None)
198 FloatCanvas
.EVT_MIDDLE_DOWN(self
.Canvas
, None )
199 FloatCanvas
.EVT_MIDDLE_UP(self
.Canvas
, None )
200 FloatCanvas
.EVT_MIDDLE_DCLICK(self
.Canvas
, None )
202 FloatCanvas
.EVT_RIGHT_DOWN(self
.Canvas
, None )
203 FloatCanvas
.EVT_RIGHT_UP(self
.Canvas
, None )
204 FloatCanvas
.EVT_RIGHT_DCLICK(self
.Canvas
, None )
206 FloatCanvas
.EVT_MOUSEWHEEL(self
.Canvas
, None )
208 self
.EventsAreBound
= False
211 def PrintCoords(self
,event
):
212 #print "coords are: %s"%(event.Coords,)
213 #print "pixel coords are: %s\n"%(event.GetPosition(),)
214 self
.Log("coords are: %s"%(event
.Coords
,))
215 self
.Log("pixel coords are: %s\n"%(event
.GetPosition(),))
217 def OnSavePNG(self
, event
=None):
220 self
, message
="Save file as ...", defaultDir
=os
.getcwd(),
221 defaultFile
="", wildcard
="*.png", style
=wx
.SAVE
223 if dlg
.ShowModal() == wx
.ID_OK
:
225 if not(path
[-4:].lower() == ".png"):
227 self
.Canvas
.SaveAsImage(path
)
230 def OnLeftDown(self
, event
):
232 self
.PrintCoords(event
)
234 def OnLeftUp(self
, event
):
236 self
.PrintCoords(event
)
238 def OnLeftDouble(self
, event
):
239 self
.Log("LeftDouble")
240 self
.PrintCoords(event
)
242 def OnMiddleDown(self
, event
):
243 self
.Log("MiddleDown")
244 self
.PrintCoords(event
)
246 def OnMiddleUp(self
, event
):
248 self
.PrintCoords(event
)
250 def OnMiddleDouble(self
, event
):
251 self
.Log("MiddleDouble")
252 self
.PrintCoords(event
)
254 def OnRightDown(self
, event
):
255 self
.Log("RightDown")
256 self
.PrintCoords(event
)
258 def OnRightUp(self
, event
):
259 self
.Log("RightDown")
260 self
.PrintCoords(event
)
262 def OnRightDouble(self
, event
):
263 self
.Log("RightDouble")
264 self
.PrintCoords(event
)
266 def OnWheel(self
, event
):
267 self
.Log("Mouse Wheel")
268 self
.PrintCoords(event
)
269 Rot
= event
.GetWheelRotation()
270 Rot
= Rot
/ abs(Rot
) * 0.1
271 if event
.ControlDown(): # move left-right
272 self
.Canvas
.MoveImage( (Rot
, 0), "Panel" )
274 self
.Canvas
.MoveImage( (0, Rot
), "Panel" )
276 def OnMove(self
, event
):
278 Updates the status bar with the world coordinates
280 self
.SetStatusText("%.2f, %.2f"%tuple(event
.Coords
))
282 def OnAbout(self
, event
):
283 dlg
= wx
.MessageDialog(self
,
284 "This is a small program to demonstrate\n"
285 "the use of the FloatCanvas\n",
287 wx
.OK | wx
.ICON_INFORMATION
)
291 def ZoomToFit(self
,event
):
292 self
.Canvas
.ZoomToBB()
294 def Clear(self
,event
= None):
295 self
.UnBindAllMouseEvents()
296 self
.Canvas
.ClearAll()
297 self
.Canvas
.SetProjectionFun(None)
300 def OnQuit(self
,event
):
303 def OnCloseWindow(self
, event
):
306 def DrawTest(self
,event
=None):
312 self
.BindAllMouseEvents()
316 Canvas
.SetProjectionFun(None)
318 ############# Random tests of everything ##############
322 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
323 lw
= random
.randint(1,5)
324 cf
= random
.randint(0,len(colors
)-1)
325 wh
= (random
.randint(1,5), random
.randint(1,5))
326 Canvas
.AddRectangle(xy
, wh
, LineWidth
= lw
, FillColor
= colors
[cf
])
330 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
331 lw
= random
.randint(1,5)
332 cf
= random
.randint(0,len(colors
)-1)
333 h
= random
.randint(1,5)
334 w
= random
.randint(1,5)
335 Canvas
.AddEllipse(xy
, (h
,w
), LineWidth
= lw
,FillColor
= colors
[cf
])
339 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
340 D
= random
.randint(1,50)
341 cf
= random
.randint(0,len(colors
)-1)
342 Canvas
.AddPoint(xy
, Color
= colors
[cf
], Diameter
= D
)
346 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
347 S
= random
.randint(1, 50)
348 cf
= random
.randint(0,len(colors
)-1)
349 Canvas
.AddSquarePoint(xy
, Color
= colors
[cf
], Size
= S
)
353 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
354 D
= random
.randint(1,5)
355 lw
= random
.randint(1,5)
356 cf
= random
.randint(0,len(colors
)-1)
357 cl
= random
.randint(0,len(colors
)-1)
358 Canvas
.AddCircle(xy
, D
, LineWidth
= lw
, LineColor
= colors
[cl
], FillColor
= colors
[cf
])
359 Canvas
.AddText("Circle # %i"%(i), xy
, Size
= 12, BackgroundColor
= None, Position
= "cc")
363 for j
in range(random
.randint(2,10)):
364 point
= (random
.randint(Range
[0],Range
[1]),random
.randint(Range
[0],Range
[1]))
366 lw
= random
.randint(1,10)
367 cf
= random
.randint(0,len(colors
)-1)
368 cl
= random
.randint(0,len(colors
)-1)
369 Canvas
.AddLine(points
, LineWidth
= lw
, LineColor
= colors
[cl
])
373 for j
in range(random
.randint(2,6)):
374 point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
376 lw
= random
.randint(1,6)
377 cf
= random
.randint(0,len(colors
)-1)
378 cl
= random
.randint(0,len(colors
)-1)
379 Canvas
.AddPolygon(points
,
381 LineColor
= colors
[cl
],
382 FillColor
= colors
[cf
],
388 points
= RandomArray
.uniform(Range
[0],Range
[1],(100,2))
389 cf
= random
.randint(0,len(colors
)-1)
390 D
= random
.randint(1,4)
391 Canvas
.AddPointSet(points
, Color
= colors
[cf
], Diameter
= D
)
394 String
= "Unscaled text"
396 ts
= random
.randint(10,40)
397 cf
= random
.randint(0,len(colors
)-1)
398 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
399 Canvas
.AddText(String
, xy
, Size
= ts
, Color
= colors
[cf
], Position
= "cc")
402 String
= "Scaled text"
404 ts
= random
.random()*3 + 0.2
405 cf
= random
.randint(0,len(colors
)-1)
406 Point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
407 Canvas
.AddScaledText(String
, Point
, Size
= ts
, Color
= colors
[cf
], Position
= "cc")
411 Points
= RandomArray
.uniform(Range
[0], Range
[1], (N
,2) )
413 Canvas
.AddArrow(Points
[i
],
414 random
.uniform(20,100),
415 Direction
= random
.uniform(0,360),
416 LineWidth
= random
.uniform(1,5),
417 LineColor
= colors
[random
.randint(0,len(colors
)-1)],
418 ArrowHeadAngle
= random
.uniform(20,90))
422 def TestAnimation(self
,event
=None):
425 In this test, a relatively complex background is drawn, and
426 a simple object placed in the foreground is moved over
427 it. This demonstrates how to use the InForeground attribute
428 to make an object in the foregorund draw fast, without
429 having to re-draw the whole background.
436 self
.UnBindAllMouseEvents()
440 Canvas
.SetProjectionFun(None)
442 ## Random tests of everything:
446 xy
= (random
.uniform(Range
[0],Range
[1]), random
.uniform(Range
[0],Range
[1]))
447 lw
= random
.randint(1,5)
448 cf
= random
.randint(0,len(colors
)-1)
449 wh
= (random
.randint(1,5), random
.randint(1,5) )
450 Canvas
.AddRectangle(xy
, wh
, LineWidth
= lw
, FillColor
= colors
[cf
])
454 xy
= (random
.uniform(Range
[0],Range
[1]), random
.uniform(Range
[0],Range
[1]))
455 lw
= random
.randint(1,5)
456 cf
= random
.randint(0,len(colors
)-1)
457 wh
= (random
.randint(1,5), random
.randint(1,5) )
458 Canvas
.AddEllipse(xy
, wh
, LineWidth
= lw
, FillColor
= colors
[cf
])
462 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
463 D
= random
.randint(1,5)
464 lw
= random
.randint(1,5)
465 cf
= random
.randint(0,len(colors
)-1)
466 cl
= random
.randint(0,len(colors
)-1)
467 Canvas
.AddCircle(xy
, D
, LineWidth
= lw
, LineColor
= colors
[cl
], FillColor
= colors
[cf
])
468 Canvas
.AddText("Circle # %i"%(i), xy
, Size
= 12, BackgroundColor
= None, Position
= "cc")
473 for j
in range(random
.randint(2,10)):
474 point
= (random
.randint(Range
[0],Range
[1]),random
.randint(Range
[0],Range
[1]))
476 lw
= random
.randint(1,10)
477 cf
= random
.randint(0,len(colors
)-1)
478 cl
= random
.randint(0,len(colors
)-1)
479 Canvas
.AddLine(points
, LineWidth
= lw
, LineColor
= colors
[cl
])
484 for j
in range(random
.randint(2,6)):
485 point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
487 lw
= random
.randint(1,6)
488 cf
= random
.randint(0,len(colors
)-1)
489 cl
= random
.randint(0,len(colors
)-1)
490 Canvas
.AddPolygon(points
,
492 LineColor
= colors
[cl
],
493 FillColor
= colors
[cf
],
497 String
= "Scaled text"
499 ts
= random
.random()*3 + 0.2
500 cf
= random
.randint(0,len(colors
)-1)
501 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
502 Canvas
.AddScaledText(String
, xy
, Size
= ts
, Color
= colors
[cf
], Position
= "cc")
505 # Now the Foreground Object:
506 C
= Canvas
.AddCircle((0,0), 7, LineWidth
= 2,LineColor
= "Black",FillColor
= "Red", InForeground
= True)
507 T
= Canvas
.AddScaledText("Click to Move", (0,0), Size
= 0.6, Position
= 'cc', InForeground
= True)
508 C
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.MoveMe
)
511 self
.Timer
= wx
.PyTimer(self
.ShowFrame
)
512 self
.FrameDelay
= 50 # milliseconds
517 Object
= self
.MovingObject
519 if self
.TimeStep
< self
.NumTimeSteps
:
521 if x
> Range
[1] or x
< Range
[0]:
523 if y
> Range
[1] or y
< Range
[0]:
525 Object
.Move( (self
.dx
,self
.dy
) )
526 Object
.Text
.Move( (self
.dx
,self
.dy
))
529 wx
.GetApp().Yield(True)
534 def MoveMe(self
, Object
):
535 self
.MovingObject
= Object
537 self
.dx
= random
.uniform(Range
[0]/4,Range
[1]/4)
538 self
.dy
= random
.uniform(Range
[0]/4,Range
[1]/4)
541 self
.NumTimeSteps
= 200
543 self
.Timer
.Start(self
.FrameDelay
)
544 #print "Did %i frames in %f seconds"%(N, (time.time() - start) )
546 def TestHitTest(self
,event
=None):
549 self
.UnBindAllMouseEvents()
553 Canvas
.SetProjectionFun(None)
555 #Add a Hit-able rectangle
563 #Add one that is not HitAble
564 Canvas
.AddRectangle((x
,y
), (w
, h
), LineWidth
= 2)
565 Canvas
.AddText("Not Hit-able", (x
,y
), Size
= FontSize
, Position
= "bl")
569 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2)
570 R
.Name
= "Line Rectangle"
572 R
.HitLineWidth
= 5 # Makes it a little easier to hit
573 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectGotHit
)
574 Canvas
.AddText("Left Click Line", (x
,y
), Size
= FontSize
, Position
= "bl")
575 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
579 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
580 R
.Name
= color
+ "Rectangle"
581 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectGotHit
)
582 Canvas
.AddText("Left Click Fill", (x
, y
), Size
= FontSize
, Position
= "bl")
583 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
588 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
589 R
.Name
= color
+ " Rectangle"
590 R
.Bind(FloatCanvas
.EVT_FC_RIGHT_DOWN
, self
.RectGotHit
)
591 Canvas
.AddText("Right Click Fill", (x
, y
), Size
= FontSize
, Position
= "bl")
592 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
596 R
= Canvas
.AddEllipse((x
, y
), (w
, h
),LineWidth
= 2,FillColor
= color
)
597 R
.Name
= color
+" Ellipse"
598 R
.Bind(FloatCanvas
.EVT_FC_RIGHT_DOWN
, self
.RectGotHit
)
599 Canvas
.AddText("Right Click Fill", (x
, y
), Size
= FontSize
, Position
= "bl")
600 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
604 R
= Canvas
.AddCircle((x
+dx
/2, y
+dy
/2), dx
/4, LineWidth
= 2, FillColor
= color
)
605 R
.Name
= color
+ " Circle"
607 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DCLICK
, self
.RectGotHit
)
608 Canvas
.AddText("Left D-Click Fill", (x
, y
), Size
= FontSize
, Position
= "bl")
609 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
614 R
= Canvas
.AddCircle((x
+dx
/2, y
+dy
/2), dx
/4, LineWidth
= 2,FillColor
= color
)
615 R
.Name
= color
+ " Circle"
616 R
.Bind(FloatCanvas
.EVT_FC_LEFT_UP
, self
.RectGotHit
)
617 Canvas
.AddText("Left Up Fill", (x
, y
), Size
= FontSize
, Position
= "bl")
618 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
622 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
623 R
.Name
= color
+ " Rectangle"
624 R
.Bind(FloatCanvas
.EVT_FC_MIDDLE_DOWN
, self
.RectGotHit
)
625 Canvas
.AddText("Middle Down", (x
, y
), Size
= FontSize
, Position
= "bl")
626 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
630 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
631 R
.Name
= color
+ " Rectangle"
632 R
.Bind(FloatCanvas
.EVT_FC_MIDDLE_UP
, self
.RectGotHit
)
633 Canvas
.AddText("Middle Up", (x
, y
), Size
= FontSize
, Position
= "bl")
634 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
639 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
640 R
.Name
= color
+ " Rectangle"
641 R
.Bind(FloatCanvas
.EVT_FC_MIDDLE_DCLICK
, self
.RectGotHit
)
642 Canvas
.AddText("Middle DoubleClick", (x
, y
), Size
= FontSize
, Position
= "bl")
643 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
647 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
648 R
.Name
= color
+ " Rectangle"
649 R
.Bind(FloatCanvas
.EVT_FC_RIGHT_UP
, self
.RectGotHit
)
650 Canvas
.AddText("Right Up", (x
, y
), Size
= FontSize
, Position
= "bl")
651 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
655 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
656 R
.Name
= color
+ " Rectangle"
657 R
.Bind(FloatCanvas
.EVT_FC_RIGHT_DCLICK
, self
.RectGotHit
)
658 Canvas
.AddText("Right Double Click", (x
, y
), Size
= FontSize
, Position
= "bl")
659 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
663 color
= "MEDIUM GOLDENROD"
664 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
666 R
.Bind(FloatCanvas
.EVT_FC_RIGHT_DOWN
, self
.RectGotHitRight
)
667 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectGotHitLeft
)
668 Canvas
.AddText("L and R Click", (x
, y
), Size
= FontSize
, Position
= "bl")
669 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
673 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
674 R
.Name
= color
+ " Rectangle"
675 R
.Bind(FloatCanvas
.EVT_FC_ENTER_OBJECT
, self
.RectMouseOver
)
676 Canvas
.AddText("Mouse Enter", (x
, y
), Size
= FontSize
, Position
= "bl")
677 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
680 color
= "MEDIUM VIOLET RED"
681 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
683 R
.Bind(FloatCanvas
.EVT_FC_LEAVE_OBJECT
, self
.RectMouseLeave
)
684 Canvas
.AddText("Mouse Leave", (x
, y
), Size
= FontSize
, Position
= "bl")
685 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
690 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
)
692 R
.Bind(FloatCanvas
.EVT_FC_ENTER_OBJECT
, self
.RectMouseOver
)
693 R
.Bind(FloatCanvas
.EVT_FC_LEAVE_OBJECT
, self
.RectMouseLeave
)
694 Canvas
.AddText("Enter and Leave", (x
, y
), Size
= FontSize
, Position
= "bl")
695 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
699 R
= Canvas
.AddRectangle((x
, y
), (w
+12, h
), LineColor
= None, FillColor
= color
)
701 R
.Bind(FloatCanvas
.EVT_FC_ENTER_OBJECT
, self
.RectMouseOver
)
702 R
.Bind(FloatCanvas
.EVT_FC_LEAVE_OBJECT
, self
.RectMouseLeave
)
703 Canvas
.AddText("Mouse Enter&Leave", (x
, y
), Size
= FontSize
, Position
= "bl")
704 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
708 R
= Canvas
.AddRectangle((x
-12, y
), (w
+12, h
), LineColor
= None, FillColor
= color
)
710 R
.Bind(FloatCanvas
.EVT_FC_ENTER_OBJECT
, self
.RectMouseOver
)
711 R
.Bind(FloatCanvas
.EVT_FC_LEAVE_OBJECT
, self
.RectMouseLeave
)
712 Canvas
.AddText("Mouse ENter&Leave", (x
, y
), Size
= FontSize
, Position
= "bl")
713 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
717 L
= Canvas
.AddLine(( (x
, y
), (x
+10, y
+10), (x
+w
, y
+h
) ), LineWidth
= 2, LineColor
= "Red")
719 L
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectGotHitLeft
)
720 Canvas
.AddText("Left Down", (x
, y
), Size
= FontSize
, Position
= "bl")
721 Canvas
.AddText(L
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
725 Points
= Numeric
.array(( (x
, y
), (x
, y
+2.*h
/3), (x
+w
, y
+h
), (x
+w
, y
+h
/2.), (x
+ 2.*w
/3, y
+h
/2.), (x
+ 2.*w
/3,y
) ), Numeric
.Float
)
726 R
= Canvas
.AddPolygon(Points
, LineWidth
= 2, FillColor
= color
)
727 R
.Name
= color
+ " Polygon"
728 R
.Bind(FloatCanvas
.EVT_FC_RIGHT_DOWN
, self
.RectGotHitRight
)
729 Canvas
.AddText("RIGHT_DOWN", (x
, y
), Size
= FontSize
, Position
= "bl")
730 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
734 Points
= Numeric
.array(( (x
, y
), (x
, y
+2.*h
/3), (x
+w
, y
+h
), (x
+w
, y
+h
/2.), (x
+ 2.*w
/3, y
+h
/2.), (x
+ 2.*w
/3,y
) ), Numeric
.Float
)
735 R
= Canvas
.AddPointSet(Points
, Diameter
= 4, Color
= color
)
737 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.PointSetGotHit
)
738 Canvas
.AddText("LEFT_DOWN", (x
, y
), Size
= FontSize
, Position
= "bl")
739 Canvas
.AddText(R
.Name
, (x
, y
+h
), Size
= FontSize
, Position
= "tl")
743 T
= Canvas
.AddText("Hit-able Text", (x
, y
), Size
= 15, Color
= "Red", Position
= 'tl')
744 T
.Name
= "Hit-able Text"
745 T
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectGotHitLeft
)
746 Canvas
.AddText("Left Down", (x
, y
), Size
= FontSize
, Position
= "bl")
749 T
= Canvas
.AddScaledText("Scaled Text", (x
, y
), Size
= 1./2*h
, Color
= "Pink", Position
= 'bl')
750 Canvas
.AddPointSet( (x
, y
), Diameter
= 3)
751 T
.Name
= "Scaled Text"
752 T
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectGotHitLeft
)
753 Canvas
.AddText("Left Down", (x
, y
), Size
= FontSize
, Position
= "tl")
758 #Points = Numeric.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), Numeric.Float)
759 R
= Canvas
.AddSquarePoint(Point
, Size
= 8, Color
= color
)
760 R
.Name
= "SquarePoint"
761 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectGotHit
)
762 Canvas
.AddText("LEFT_DOWN", (x
, y
), Size
= FontSize
, Position
= "bl")
763 Canvas
.AddText(R
.Name
, (x
, y
), Size
= FontSize
, Position
= "tl")
766 self
.Canvas
.ZoomToBB()
768 def TestHitTestForeground(self
,event
=None):
771 self
.UnBindAllMouseEvents()
775 Canvas
.SetProjectionFun(None)
777 #Add a Hitable rectangle
785 R
= Canvas
.AddRectangle((x
, y
), (w
, h
), LineWidth
= 2, FillColor
= color
, InForeground
= False)
786 R
.Name
= color
+ "Rectangle"
788 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectGotHit
)
789 Canvas
.AddText("Left Click Fill", (x
, y
), Position
= "bl")
790 Canvas
.AddText(R
.Name
, (x
, y
+h
), Position
= "tl")
792 ## A set of Rectangles that move together
794 ## NOTE: In a real app, it might be better to create a new
795 ## custom FloatCanvas DrawObject
797 self
.MovingRects
= []
801 R
= Canvas
.AddRectangle((x
, y
), WH
, LineWidth
= 2, FillColor
= color
, InForeground
= True)
803 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectMoveLeft
)
804 L
= Canvas
.AddText("Left", (x
+ w
/4, y
+ h
/4), Position
= "cc", InForeground
= True)
805 self
.MovingRects
.extend( (R
,L
) )
808 R
= Canvas
.AddRectangle((x
, y
), WH
, LineWidth
= 2, FillColor
= color
, InForeground
= True)
810 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectMoveRight
)
811 L
= Canvas
.AddText("Right", (x
+ w
/4, y
+ h
/4), Position
= "cc", InForeground
= True)
812 self
.MovingRects
.extend( (R
,L
) )
816 R
= Canvas
.AddRectangle((x
, y
), WH
, LineWidth
= 2, FillColor
= color
, InForeground
= True)
818 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectMoveUp
)
819 L
= Canvas
.AddText("Up", (x
+ w
/4, y
+ h
/4), Position
= "cc", InForeground
= True)
820 self
.MovingRects
.extend( (R
,L
) )
824 R
= Canvas
.AddRectangle((x
, y
), WH
, LineWidth
= 2, FillColor
= color
, InForeground
= True)
826 R
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RectMoveDown
)
827 L
= Canvas
.AddText("Down", (x
+ w
/4, y
+ h
/4), Position
= "cc", InForeground
= True)
828 self
.MovingRects
.extend( (R
,L
) )
830 self
.Canvas
.ZoomToBB()
832 def RectMoveLeft(self
,Object
):
833 self
.MoveRects("left")
835 def RectMoveRight(self
,Object
):
836 self
.MoveRects("right")
838 def RectMoveUp(self
,Object
):
841 def RectMoveDown(self
,Object
):
842 self
.MoveRects("down")
844 def MoveRects(self
, Dir
):
845 for Object
in self
.MovingRects
:
847 if Dir
== "left": X
-= 10
848 elif Dir
== "right": X
+= 10
849 elif Dir
== "up": Y
+= 10
850 elif Dir
== "down": Y
-= 10
851 Object
.SetPoint((X
,Y
))
854 def PointSetGotHit(self
, Object
):
855 self
.Log(Object
.Name
+ "Got Hit\n")
857 def RectGotHit(self
, Object
):
858 self
.Log(Object
.Name
+ "Got Hit\n")
860 def RectGotHitRight(self
, Object
):
861 self
.Log(Object
.Name
+ "Got Hit With Right\n")
863 def RectGotHitLeft(self
, Object
):
864 self
.Log(Object
.Name
+ "Got Hit with Left\n")
866 def RectMouseOver(self
, Object
):
867 self
.Log("Mouse entered:" + Object
.Name
)
869 def RectMouseLeave(self
, Object
):
870 self
.Log("Mouse left " + Object
.Name
)
873 def TestText(self
, event
= None):
876 self
.BindAllMouseEvents()
879 Canvas
.SetProjectionFun(None)
883 ## Add a non-visible rectangle, just to get a Bounding Box
884 ## Text objects have a zero-size bounding box, because it changes with zoom
885 Canvas
.AddRectangle((-10,-10),
892 self
.Canvas
.AddText("Top Left",Point
,Size
= 14,Color
= "Yellow",BackgroundColor
= "Blue", Position
= "tl")
893 self
.Canvas
.AddText("Bottom Left",Point
,Size
= 14,Color
= "Cyan",BackgroundColor
= "Black",Position
= "bl")
894 self
.Canvas
.AddText("Top Right",Point
,Size
= 14,Color
= "Black",BackgroundColor
= "Cyan",Position
= "tr")
895 self
.Canvas
.AddText("Bottom Right",Point
,Size
= 14,Color
= "Blue",BackgroundColor
= "Yellow",Position
= "br")
896 Canvas
.AddPointSet((Point
), Color
= "White", Diameter
= 2)
900 Canvas
.AddPointSet((Point
), Color
= "White", Diameter
= 2)
901 self
.Canvas
.AddText("Top Center",Point
,Size
= 14,Color
= "Black",Position
= "tc")
902 self
.Canvas
.AddText("Bottom Center",Point
,Size
= 14,Color
= "White",Position
= "bc")
906 Canvas
.AddPointSet((Point
), Color
= "White", Diameter
= 2)
907 self
.Canvas
.AddText("Center Right",Point
,Size
= 14,Color
= "Black",Position
= "cr")
908 self
.Canvas
.AddText("Center Left",Point
,Size
= 14,Color
= "Black",Position
= "cl")
912 Canvas
.AddPointSet((Point
), Color
= "White", Diameter
= 2)
913 self
.Canvas
.AddText("Center Center",
918 self
.Canvas
.AddText("40 Pixels", (-10,8), Size
= 40)
919 self
.Canvas
.AddText("20 Pixels", (-10,5), Size
= 20)
920 self
.Canvas
.AddText("10 Pixels", (-10,3), Size
= 10)
922 self
.Canvas
.AddText("MODERN Font", (-10, 0), Family
= wx
.MODERN
)
923 self
.Canvas
.AddText("DECORATIVE Font", (-10, -1), Family
= wx
.DECORATIVE
)
924 self
.Canvas
.AddText("ROMAN Font", (-10, -2), Family
= wx
.ROMAN
)
925 self
.Canvas
.AddText("SCRIPT Font", (-10, -3), Family
= wx
.SCRIPT
)
926 self
.Canvas
.AddText("ROMAN BOLD Font", (-10, -4), Family
= wx
.ROMAN
, Weight
=wx
.BOLD
)
927 self
.Canvas
.AddText("ROMAN ITALIC BOLD Font", (-10, -5), Family
= wx
.ROMAN
, Weight
=wx
.BOLD
, Style
=wx
.ITALIC
)
929 # NOTE: this font exists on my Linux box..who knows were else you'll find it!
930 Font
= wx
.Font(20, wx
.DEFAULT
, wx
.ITALIC
, wx
.NORMAL
, False, "zapf chancery")
931 self
.Canvas
.AddText("zapf chancery Font", (-10, -6), Font
= Font
)
933 self
.Canvas
.ZoomToBB()
935 def TestScaledText(self
, event
= None):
938 self
.BindAllMouseEvents()
941 Canvas
.SetProjectionFun(None)
945 T
= Canvas
.AddScaledText("Top Left",
949 BackgroundColor
= "Blue",
951 T
= Canvas
.AddScaledText("Bottom Left",Point
,Size
= 5,Color
= "Cyan",BackgroundColor
= "Black",Position
= "bl")
952 T
= Canvas
.AddScaledText("Top Right",Point
,Size
= 5,Color
= "Black",BackgroundColor
= "Cyan",Position
= "tr")
953 T
= Canvas
.AddScaledText("Bottom Right",Point
,Size
= 5,Color
= "Blue",BackgroundColor
= "Yellow",Position
= "br")
954 Canvas
.AddPointSet((Point
), Color
= "Red", Diameter
= 4)
959 Canvas
.AddScaledText("Top Center",Point
,Size
= 7,Color
= "Black",Position
= "tc")
960 Canvas
.AddScaledText("Bottom Center",Point
,Size
= 7,Color
= "White",Position
= "bc")
961 Canvas
.AddPointSet((Point
), Color
= "White", Diameter
= 4)
965 Canvas
.AddScaledText("Center Right",Point
,Size
= 9,Color
= "Black",Position
= "cr")
966 Canvas
.AddScaledText("Center Left",Point
,Size
= 9,Color
= "Black",Position
= "cl")
967 Canvas
.AddPointSet((Point
), Color
= "White", Diameter
= 4)
971 self
.Canvas
.AddScaledText("MODERN Font", (x
, 0), Size
= 7, Family
= wx
.MODERN
, Color
= (0,0,0))
972 self
.Canvas
.AddScaledText("DECORATIVE Font", (x
, -10), Size
= 7, Family
= wx
.DECORATIVE
, Color
= (0,0,1))
973 self
.Canvas
.AddScaledText("ROMAN Font", (x
, -20), Size
= 7, Family
= wx
.ROMAN
)
974 self
.Canvas
.AddScaledText("SCRIPT Font", (x
, -30), Size
= 7, Family
= wx
.SCRIPT
)
975 self
.Canvas
.AddScaledText("ROMAN BOLD Font", (x
, -40), Size
= 7, Family
= wx
.ROMAN
, Weight
=wx
.BOLD
)
976 self
.Canvas
.AddScaledText("ROMAN ITALIC BOLD Font", (x
, -50), Size
= 7, Family
= wx
.ROMAN
, Weight
=wx
.BOLD
, Style
=wx
.ITALIC
)
977 Canvas
.AddPointSet((x
,0), Color
= "White", Diameter
= 4)
980 # NOTE: this font exists on my Linux box..who knows were else you'll find it!
982 Font
= wx
.Font(12, wx
.DEFAULT
, wx
.ITALIC
, wx
.NORMAL
, False, "zapf chancery")
983 T
= self
.Canvas
.AddScaledText("zapf chancery Font", Point
, Size
= 20, Font
= Font
, Position
= 'bc')
986 Font
= wx
.Font(12, wx
.DEFAULT
, wx
.ITALIC
, wx
.NORMAL
, False, "bookman")
987 T
= self
.Canvas
.AddScaledText("Bookman Font", Point
, Size
= 8, Font
= Font
)
989 self
.Canvas
.ZoomToBB()
991 def TestScaledTextBox(self
, event
= None):
994 self
.UnBindAllMouseEvents()
997 Canvas
.SetProjectionFun(None)
1000 Box
= Canvas
.AddScaledTextBox("A Two Line\nString",
1004 BackgroundColor
= None,
1006 LineStyle
= "Solid",
1016 InForeground
= False)
1019 Box
= Canvas
.AddScaledTextBox("A Two Line\nString",
1023 Box
= Canvas
.AddScaledTextBox("A Two Line\nString",
1026 BackgroundColor
= "Yellow",
1028 LineStyle
= "Solid",
1030 Family
= wx
.TELETYPE
,
1033 Box
= Canvas
.AddScaledTextBox("A String\nThis box is clickable",
1036 BackgroundColor
= "Yellow",
1038 LineStyle
= "Solid",
1040 Family
= wx
.TELETYPE
,
1043 Box
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.binding2
)
1045 Canvas
.AddPoint(Point
, Diameter
= 4)
1048 Box
= Canvas
.AddScaledTextBox("A Two Line\nString",
1052 BackgroundColor
= 'Red',
1054 LineStyle
= "LongDash",
1058 Family
= wx
.TELETYPE
,
1064 InForeground
= False)
1066 Box
= Canvas
.AddScaledTextBox("A Two Line\nString",
1070 BackgroundColor
= 'Red',
1072 LineStyle
= "LongDash",
1076 Family
= wx
.TELETYPE
,
1082 InForeground
= False)
1084 Canvas
.AddPoint(Point
, Diameter
= 4)
1087 Box
= Canvas
.AddScaledTextBox("A Two Line\nString",
1091 BackgroundColor
= 'Red',
1093 LineStyle
= "LongDash",
1097 Family
= wx
.TELETYPE
,
1103 InForeground
= False)
1105 Box
= Canvas
.AddScaledTextBox("A three\nLine\nString",
1109 BackgroundColor
= 'Red',
1111 LineStyle
= "LongDash",
1115 Family
= wx
.TELETYPE
,
1121 InForeground
= False)
1124 Canvas
.AddPoint(Point
, Diameter
= 4)
1126 Box
= Canvas
.AddScaledTextBox("Some Auto Wrapped Text. There is enough to do.",
1129 BackgroundColor
= 'White',
1133 Family
= wx
.TELETYPE
,
1136 Box
= Canvas
.AddScaledTextBox("Some more auto wrapped text. Wrapped to a different width.\n\nThis is another paragraph.",
1139 BackgroundColor
= 'White',
1146 Point
= Numeric
.array((100, -20), Numeric
.Float
)
1147 Box
= Canvas
.AddScaledTextBox("Here is even more auto wrapped text. This time the line spacing is set to 0.8. \n\nThe Padding is set to 0.",
1150 BackgroundColor
= 'White',
1158 Canvas
.AddPoint(Point
, "Red", 2)
1160 Point
= Numeric
.array((0, -40), Numeric
.Float
)
1161 # Point = Numeric.array((0, 0), Numeric.Float)
1162 for Position
in ["tl", "bl", "tr", "br"]:
1163 # for Position in ["br"]:
1164 Box
= Canvas
.AddScaledTextBox("Here is a\nfour liner\nanother line\nPosition=%s"%Position
,
1168 BackgroundColor
= None,#'LightBlue',
1170 LineColor
= "White",
1174 Position
= Position
,
1177 Canvas
.AddPoint(Point
, "Red", 4)
1179 Point
= Numeric
.array((-20, 60), Numeric
.Float
)
1180 Box
= Canvas
.AddScaledTextBox("Here is some\ncentered\ntext",
1184 BackgroundColor
= 'LightBlue',
1186 LineColor
= "White",
1191 Alignment
= "center",
1195 Point
= Numeric
.array((-20, 20), Numeric
.Float
)
1196 Box
= Canvas
.AddScaledTextBox("Here is some\nright aligned\ntext",
1200 BackgroundColor
= 'LightBlue',
1206 Alignment
= "right",
1210 Point
= Numeric
.array((100, -60), Numeric
.Float
)
1211 Box
= Canvas
.AddScaledTextBox("Here is some auto wrapped text. This time it is centered, rather than right aligned.\n\nThe Padding is set to 2.",
1214 BackgroundColor
= 'White',
1221 Alignment
= 'center',
1227 self
.Canvas
.ZoomToBB()
1229 def binding2(self
, event
):
1230 self
.Log("I'm the TextBox")
1232 def TestBitmap(self
, event
= None):
1235 self
.UnBindAllMouseEvents()
1236 Canvas
= self
.Canvas
1238 Canvas
.SetProjectionFun(None)
1240 Canvas
.AddRectangle((10, 20),
1246 bmp
= Resources
.getMagPlusBitmap()
1248 Canvas
.AddText("These are Unscaled Bitmaps:", (140, 90))
1251 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "cc" )
1252 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1255 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "br" )
1256 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1259 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "bl" )
1260 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1263 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "tr" )
1264 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1267 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "tl" )
1268 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1271 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "cr" )
1272 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1275 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "cl" )
1276 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1279 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "tc" )
1280 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1283 BitMap
= Canvas
.AddBitmap(bmp
, Point
, Position
= "bc" )
1284 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1286 Canvas
.AddScaledText("These are Scaled Bitmaps:", (220, -60), Size
= 10, Position
= "tr")
1288 BitMap
= Canvas
.AddScaledBitmap(bmp
, Point
, Height
= 50, Position
= "bc" )
1289 BitMap
= Canvas
.AddScaledBitmap(bmp
, Point
, Height
= 50, Position
= "tc" )
1290 Canvas
.AddPoint(Point
, Diameter
=4, Color
="Green")
1293 BitMap
= Canvas
.AddScaledBitmap(Resources
.getMondrianImage(), Point
, Height
= 50)
1295 self
.Canvas
.ZoomToBB()
1297 def DrawMap(self
,event
= None):
1300 self
.BindAllMouseEvents()
1302 ## Test of Actual Map Data
1303 self
.Canvas
.ClearAll()
1304 self
.Canvas
.SetProjectionFun("FlatEarth")
1305 #start = time.clock()
1306 self
.Log("Loading Map from a File")
1307 wx
.GetApp().Yield() # so log text will get displayed now.
1308 Shorelines
= self
.Read_MapGen(os
.path
.join("data",'world.dat'),stats
= 0)
1309 #print "It took %f seconds to load %i shorelines"%(time.clock() - start,len(Shorelines) )
1310 #start = time.clock()
1311 for segment
in Shorelines
:
1312 self
.Canvas
.AddLine(segment
)
1313 #print "It took %f seconds to add %i shorelines"%(time.clock() - start,len(Shorelines) )
1314 #start = time.clock()
1315 self
.Canvas
.ZoomToBB()
1316 #print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) )
1319 def LineTest(self
,event
= None):
1323 colors
= self
.colors
1325 ## Test of drawing lots of lines
1326 Canvas
= self
.Canvas
1328 Canvas
.SetProjectionFun(None)
1329 #start = time.clock()
1333 for i
in range(2000):
1334 points
= (random
.randint(Range
[0],Range
[1]),
1335 random
.randint(Range
[0],Range
[1]),
1336 random
.randint(Range
[0],Range
[1]),
1337 random
.randint(Range
[0],Range
[1]))
1338 linepoints
.append(points
)
1339 linewidths
.append(random
.randint(1,10) )
1340 linecolors
.append(random
.randint(0,len(colors
)-1) )
1341 for (points
,color
,width
) in zip(linepoints
,linecolors
,linewidths
):
1342 Canvas
.AddLine((points
[0:2],points
[2:4]), LineWidth
= width
, LineColor
= colors
[color
])
1343 #print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) )
1344 #start = time.clock()
1346 #print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
1348 def SpeedTest(self
,event
=None):
1350 BigRange
= (-1000,1000)
1351 colors
= self
.colors
1353 self
.UnBindAllMouseEvents()
1354 Canvas
= self
.Canvas
1357 Canvas
.SetProjectionFun(None)
1361 for i
in range(1000):
1362 Point
= (random
.uniform(BigRange
[0],BigRange
[1]),random
.uniform(BigRange
[0],BigRange
[1]))
1363 coords
.append( (Point
) )
1364 print "Drawing the Points"
1365 start
= time
.clock()
1366 for Point
in coords
:
1367 Canvas
.AddPoint(Point
, Diameter
= 4)
1368 print "It took %s seconds to add the points"%(time
.clock() - start
)
1371 def PropertiesChangeTest(self
,event
=None):
1375 colors
= self
.colors
1377 self
.UnBindAllMouseEvents()
1378 Canvas
= self
.Canvas
1381 Canvas
.SetProjectionFun(None)
1383 self
.ColorObjectsAll
= []
1384 self
.ColorObjectsLine
= []
1385 self
.ColorObjectsColor
= []
1386 self
.ColorObjectsText
= []
1387 ##One of each object:
1389 Point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1390 lw
= random
.randint(1,5)
1391 cf
= random
.randint(0,len(colors
)-1)
1392 wh
= ( random
.randint(1,5), random
.randint(1,5) )
1393 self
.Rectangle
= Canvas
.AddRectangle(Point
, wh
, LineWidth
= lw
, FillColor
= colors
[cf
])
1394 self
.ColorObjectsAll
.append(self
.Rectangle
)
1397 Point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1398 lw
= random
.randint(1,5)
1399 cf
= random
.randint(0,len(colors
)-1)
1400 wh
= ( random
.randint(1,5), random
.randint(1,5) )
1401 self
.Ellipse
= Canvas
.AddEllipse(Point
, wh
, LineWidth
= lw
, FillColor
= colors
[cf
])
1402 self
.ColorObjectsAll
.append(self
.Ellipse
)
1405 xy
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1406 D
= random
.randint(1,50)
1407 lw
= random
.randint(1,5)
1408 cf
= random
.randint(0,len(colors
)-1)
1409 cl
= random
.randint(0,len(colors
)-1)
1410 self
.ColorObjectsColor
.append(Canvas
.AddPoint(xy
, colors
[cf
], D
))
1413 Point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1414 D
= random
.randint(1,5)
1415 lw
= random
.randint(1,5)
1416 cf
= random
.randint(0,len(colors
)-1)
1417 cl
= random
.randint(0,len(colors
)-1)
1418 self
.Circle
= Canvas
.AddCircle(Point
, D
, LineWidth
= lw
, LineColor
= colors
[cl
], FillColor
= colors
[cf
])
1419 self
.ColorObjectsAll
.append(self
.Circle
)
1423 for j
in range(random
.randint(2,10)):
1424 point
= (random
.randint(Range
[0],Range
[1]),random
.randint(Range
[0],Range
[1]))
1425 points
.append(point
)
1426 lw
= random
.randint(1,10)
1427 cf
= random
.randint(0,len(colors
)-1)
1428 cl
= random
.randint(0,len(colors
)-1)
1429 self
.ColorObjectsLine
.append(Canvas
.AddLine(points
, LineWidth
= lw
, LineColor
= colors
[cl
]))
1433 ## for j in range(random.randint(2,6)):
1434 ## point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
1435 ## points.append(point)
1436 points
= RandomArray
.uniform(Range
[0],Range
[1],(6,2))
1437 lw
= random
.randint(1,6)
1438 cf
= random
.randint(0,len(colors
)-1)
1439 cl
= random
.randint(0,len(colors
)-1)
1440 self
.ColorObjectsAll
.append(Canvas
.AddPolygon(points
,
1442 LineColor
= colors
[cl
],
1443 FillColor
= colors
[cf
],
1444 FillStyle
= 'Solid'))
1447 points
= RandomArray
.uniform(Range
[0],Range
[1],(100,2))
1448 cf
= random
.randint(0,len(colors
)-1)
1449 D
= random
.randint(1,4)
1450 self
.PointSet
= Canvas
.AddPointSet(points
, Color
= colors
[cf
], Diameter
= D
)
1451 self
.ColorObjectsColor
.append(self
.PointSet
)
1454 point
= RandomArray
.uniform(Range
[0],Range
[1],(2,))
1455 cf
= random
.randint(0,len(colors
)-1)
1456 D
= random
.randint(1,4)
1457 self
.Point
= Canvas
.AddPoint(point
, Color
= colors
[cf
], Diameter
= D
)
1458 self
.ColorObjectsColor
.append(self
.Point
)
1461 String
= "Unscaled text"
1462 ts
= random
.randint(10,40)
1463 cf
= random
.randint(0,len(colors
)-1)
1464 Point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1465 self
.ColorObjectsText
.append(Canvas
.AddText(String
, Point
, Size
= ts
, Color
= colors
[cf
], Position
= "cc"))
1468 String
= "Scaled text"
1469 ts
= random
.random()*3 + 0.2
1470 cf
= random
.randint(0,len(colors
)-1)
1471 Point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1472 self
.ColorObjectsText
.append(Canvas
.AddScaledText(String
, Point
, Size
= ts
, Color
= colors
[cf
], Position
= "cc"))
1475 Button
= Canvas
.AddRectangle((-10, -12), (20, 3), LineStyle
= None, FillColor
= "Red")
1476 Canvas
.AddScaledText("Click Here To Change Properties",
1482 Button
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.ChangeProperties
)
1486 def ChangeProperties(self
, Object
= None):
1487 colors
= self
.colors
1490 for Object
in self
.ColorObjectsAll
:
1492 Object
.SetFillColor(colors
[random
.randint(0,len(colors
)-1)])
1493 Object
.SetLineColor(colors
[random
.randint(0,len(colors
)-1)])
1494 Object
.SetLineWidth(random
.randint(1,7))
1495 Object
.SetLineStyle(FloatCanvas
.DrawObject
.LineStyleList
.keys()[random
.randint(0,5)])
1496 for Object
in self
.ColorObjectsLine
:
1497 Object
.SetLineColor(colors
[random
.randint(0,len(colors
)-1)])
1498 Object
.SetLineWidth(random
.randint(1,7))
1499 Object
.SetLineStyle(FloatCanvas
.DrawObject
.LineStyleList
.keys()[random
.randint(0,5)])
1500 for Object
in self
.ColorObjectsColor
:
1501 Object
.SetColor(colors
[random
.randint(0,len(colors
)-1)])
1502 for Object
in self
.ColorObjectsText
:
1503 Object
.SetColor(colors
[random
.randint(0,len(colors
)-1)])
1504 Object
.SetBackgroundColor(colors
[random
.randint(0,len(colors
)-1)])
1505 self
.Circle
.SetDiameter(random
.randint(1,10))
1506 self
.PointSet
.SetDiameter(random
.randint(1,8))
1507 self
.Point
.SetDiameter(random
.randint(1,8))
1508 for Object
in (self
.Rectangle
, self
.Ellipse
):
1509 Point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1510 wh
= ( random
.randint(1,5), random
.randint(1,5) )
1511 Object
.SetShape(Point
, wh
)
1512 self
.Canvas
.Draw(Force
= True)
1514 def ArrowTest(self
,event
=None):
1516 self
.UnBindAllMouseEvents()
1517 Canvas
= self
.Canvas
1520 Canvas
.SetProjectionFun(None)
1522 # put in a rectangle to get a bounding box
1523 Canvas
.AddRectangle((0,0), (20,20), LineColor
= None)
1526 Canvas
.AddArrow((10,10),Length
= 40, Direction
= 0)
1527 Canvas
.AddArrow((10,10),Length
= 50, Direction
= 45 ,LineWidth
= 2, LineColor
= "Black", ArrowHeadAngle
= 20)
1528 Canvas
.AddArrow((10,10),Length
= 60, Direction
= 90 ,LineWidth
= 3, LineColor
= "Red", ArrowHeadAngle
= 30)
1529 Canvas
.AddArrow((10,10),Length
= 70, Direction
= 135,LineWidth
= 4, LineColor
= "Red", ArrowHeadAngle
= 40)
1530 Canvas
.AddArrow((10,10),Length
= 80, Direction
= 180,LineWidth
= 5, LineColor
= "Blue", ArrowHeadAngle
= 50)
1531 Canvas
.AddArrow((10,10),Length
= 90, Direction
= 225,LineWidth
= 4, LineColor
= "Blue", ArrowHeadAngle
= 60)
1532 Canvas
.AddArrow((10,10),Length
= 100,Direction
= 270,LineWidth
= 3, LineColor
= "Green", ArrowHeadAngle
= 70)
1533 Canvas
.AddArrow((10,10),Length
= 110,Direction
= 315,LineWidth
= 2, LineColor
= "Green", ArrowHeadAngle
= 90 )
1535 Canvas
.AddText("Clickable Arrow", (4,18), Position
= "bc")
1536 Arrow
= Canvas
.AddArrow((4,18), 80, Direction
= 90 ,LineWidth
= 3, LineColor
= "Red", ArrowHeadAngle
= 30)
1537 Arrow
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.ArrowClicked
)
1539 Canvas
.AddText("Changable Arrow", (16,4), Position
= "cc")
1540 self
.RotArrow
= Canvas
.AddArrow((16,4), 80, Direction
= 0 ,LineWidth
= 3, LineColor
= "Green", ArrowHeadAngle
= 30)
1541 self
.RotArrow
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.RotateArrow
)
1545 def ArrowClicked(self
,event
):
1546 print "The Arrow was Clicked"
1548 def RotateArrow(self
,event
):
1549 ##print "The Changeable Arrow was Clicked"
1550 ## You can do them either one at a time, or both at once
1551 ## Doing them both at once prevents the arrow points from being calculated twice
1552 #self.RotArrow.SetDirection(self.RotArrow.Direction + random.uniform(-90,90))
1553 #self.RotArrow.SetLength(self.RotArrow.Length + random.randint(-20,20))
1554 self
.RotArrow
.SetLengthDirection(self
.RotArrow
.Length
+ random
.randint(-20,20),
1555 self
.RotArrow
.Direction
+ random
.uniform(-90,90) )
1557 self
.Canvas
.Draw(Force
= True)
1559 def HideTest(self
, event
=None):
1562 self
.UnBindAllMouseEvents()
1563 Canvas
= self
.Canvas
1565 Canvas
.SetProjectionFun(None)
1569 # Create a couple random Polygons
1572 point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1573 points
.append(point
)
1574 Poly
= Canvas
.AddPolygon(points
,
1576 LineColor
= "Black",
1577 FillColor
= "LightBlue",
1578 FillStyle
= 'Solid')
1582 point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1583 points
.append(point
)
1584 Poly2
= Canvas
.AddPolygon(points
,
1586 LineColor
= "Black",
1587 FillColor
= "Purple",
1588 FillStyle
= 'Solid',
1589 InForeground
= True)
1591 HideButton
= Canvas
.AddScaledTextBox("Click To Hide\nBackground Polygon",
1594 BackgroundColor
="Red",
1599 HideButton
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.HidePoly
)
1600 HideButton
.HidePoly
= Poly
1602 HideButton2
= Canvas
.AddScaledTextBox("Click To Hide\nForeground Polygon",
1605 BackgroundColor
="Red",
1610 # Put a reference to the Polygon in the Button object
1611 HideButton2
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.HidePoly
)
1612 HideButton2
.HidePoly
= Poly2
1617 def HidePoly(self
, Button
):
1618 Poly
= Button
.HidePoly
1621 Button
.SetText(Button
.String
.replace("Hide","Show"))
1624 Button
.SetText(Button
.String
.replace("Show", "Hide"))
1625 self
.Canvas
.Draw(True)
1627 def TempTest(self
, event
= None):
1630 self
.UnBindAllMouseEvents()
1631 Canvas
= self
.Canvas
1633 Canvas
.SetProjectionFun(None)
1637 # Create a random Polygon
1640 point
= (random
.uniform(Range
[0],Range
[1]),random
.uniform(Range
[0],Range
[1]))
1641 points
.append(point
)
1642 Poly
= Canvas
.AddPolygon(points
,
1644 LineColor
= "Black",
1645 FillColor
= "LightBlue",
1646 FillStyle
= 'Solid')
1648 Poly
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.SelectPoly
)
1650 self
.SelectedPoly
= None
1651 self
.SelectPoints
= []
1652 self
.SelectedPoint
= None
1656 def SelectPoly(self
, Object
):
1657 print "In SelectPoly"
1658 Canvas
= self
.Canvas
1659 if Object
is self
.SelectedPoly
:
1662 #fixme: Do something to unselect the old one
1663 self
.SelectedPoly
= Object
1664 Canvas
.RemoveObjects(self
.SelectPoints
)
1665 self
.SelectPoints
= []
1666 # Draw points on the Vertices of the Selected Poly:
1667 for i
, point
in enumerate(Object
.Points
):
1668 P
= Canvas
.AddPointSet(point
, Diameter
= 6, Color
= "Red")
1670 P
.Bind(FloatCanvas
.EVT_FC_LEFT_DOWN
, self
.SelectPointHit
)
1671 self
.SelectPoints
.append(P
)
1675 def SelectPointHit(self
, Point
):
1676 print "Point Num: %i Hit"%Point
.VerticeNum
1677 self
.SelectedPoint
= Point
1679 def Read_MapGen(self
, filename
, stats
= 0,AllLines
=0):
1681 This function reads a MapGen Format file, and
1682 returns a list of NumPy arrays with the line segments in them.
1684 Each NumPy array in the list is an NX2 array of Python Floats.
1686 The demo should have come with a file, "world.dat" that is the
1687 shorelines of the whole world, in MapGen format.
1691 file = open(filename
,'rt')
1692 data
= file.readlines()
1693 data
= map(string
.strip
,data
)
1699 if line
== "# -b": #New segment beginning
1700 if segment
: Shorelines
.append(Numeric
.array(segment
))
1703 segment
.append(map(float,string
.split(line
)))
1704 if segment
: Shorelines
.append(Numeric
.array(segment
))
1707 NumSegments
= len(Shorelines
)
1709 for segment
in Shorelines
:
1710 NumPoints
= NumPoints
+ len(segment
)
1711 AvgPoints
= NumPoints
/ NumSegments
1712 print "Number of Segments: ", NumSegments
1713 print "Average Number of Points per segment: ",AvgPoints
1716 for segment
in Shorelines
:
1717 Lines
.append(segment
[0])
1718 for point
in segment
[1:-1]:
1721 Lines
.append(segment
[-1])
1727 #---------------------------------------------------------------------------
1729 if __name__
== "__main__":
1736 optlist
, args
= getopt
.getopt(sys
.argv
[1:],'l',["local",
1753 raise ImportError(errorText
)
1754 StartUpDemo
= "all" # the default
1756 if opt
[0] == "--all":
1758 elif opt
[0] == "--text":
1759 StartUpDemo
= "text"
1760 elif opt
[0] == "--map":
1762 elif opt
[0] == "--stext":
1763 StartUpDemo
= "stext"
1764 elif opt
[0] == "--stextbox":
1765 StartUpDemo
= "stextbox"
1766 elif opt
[0] == "--bitmap":
1767 StartUpDemo
= "bitmap"
1768 elif opt
[0] == "--hit":
1770 elif opt
[0] == "--hitf":
1771 StartUpDemo
= "hitf"
1772 elif opt
[0] == "--animate":
1773 StartUpDemo
= "animate"
1774 elif opt
[0] == "--speed":
1775 StartUpDemo
= "speed"
1776 elif opt
[0] == "--temp":
1777 StartUpDemo
= "temp"
1778 elif opt
[0] == "--props":
1779 StartUpDemo
= "props"
1780 elif opt
[0] == "--arrow":
1781 StartUpDemo
= "arrow"
1782 elif opt
[0] == "--hide":
1783 StartUpDemo
= "hide"
1785 class DemoApp(wx
.App
):
1789 Under the Draw menu, there are three options:
1791 *Draw Test: will put up a picture of a bunch of randomly generated
1792 objects, of each kind supported.
1794 *Draw Map: will draw a map of the world. Be patient, it is a big map,
1795 with a lot of data, and will take a while to load and draw (about 10 sec
1796 on my 450Mhz PIII). Redraws take about 2 sec. This demonstrates how the
1797 performance is not very good for large drawings.
1799 *Clear: Clears the Canvas.
1801 Once you have a picture drawn, you can zoom in and out and move about
1802 the picture. There is a tool bar with three tools that can be
1805 The magnifying glass with the plus is the zoom in tool. Once selected,
1806 if you click the image, it will zoom in, centered on where you
1807 clicked. If you click and drag the mouse, you will get a rubber band
1808 box, and the image will zoom to fit that box when you release it.
1810 The magnifying glass with the minus is the zoom out tool. Once selected,
1811 if you click the image, it will zoom out, centered on where you
1812 clicked. (note that this takes a while when you are looking at the map,
1813 as it has a LOT of lines to be drawn. The image is double buffered, so
1814 you don't see the drawing in progress)
1816 The hand is the move tool. Once selected, if you click and drag on the
1817 image, it will move so that the part you clicked on ends up where you
1818 release the mouse. Nothing is changed while you are dragging. The
1819 drawing is too slow for that.
1821 I'd like the cursor to change as you change tools, but the stock
1822 wxCursors didn't include anything I liked, so I stuck with the
1823 pointer. Please let me know if you have any nice cursor images for me to
1827 Any bugs, comments, feedback, questions, and especially code are welcome:
1831 Chris.Barker@noaa.gov
1835 def __init__(self
, *args
, **kwargs
):
1836 wx
.App
.__init
__(self
, *args
, **kwargs
)
1839 wx
.InitAllImageHandlers()
1840 DrawFrame
= BuildDrawFrame()
1841 frame
= DrawFrame(None, -1, "FloatCanvas Demo App",wx
.DefaultPosition
,(700,700))
1843 self
.SetTopWindow(frame
)
1846 ## check to see if the demo is set to start in a particular mode.
1847 if StartUpDemo
== "text":
1849 elif StartUpDemo
== "stext":
1850 frame
.TestScaledText()
1851 elif StartUpDemo
== "stextbox":
1852 frame
.TestScaledTextBox()
1853 elif StartUpDemo
== "bitmap":
1855 elif StartUpDemo
== "all":
1857 elif StartUpDemo
== "map":
1859 elif StartUpDemo
== "hit":
1861 elif StartUpDemo
== "hitf":
1862 "starting TestHitTestForeground"
1863 frame
.TestHitTestForeground()
1864 elif StartUpDemo
== "animate":
1865 "starting TestAnimation"
1866 frame
.TestAnimation()
1867 elif StartUpDemo
== "speed":
1868 "starting SpeedTest"
1870 elif StartUpDemo
== "temp":
1871 "starting temp Test"
1873 elif StartUpDemo
== "props":
1874 "starting PropertiesChange Test"
1875 frame
.PropertiesChangeTest()
1876 elif StartUpDemo
== "arrow":
1877 "starting arrow Test"
1879 elif StartUpDemo
== "hide":
1880 "starting Hide Test"
1885 app
= DemoApp(False)# put in True if you want output to go to it's own window.
1889 # It's not running stand-alone, set up for wxPython demo.
1890 # don't neeed wxversion here.
1893 ## TestPanel and runTest used for integration into wxPython Demo
1894 class TestPanel(wx
.Panel
):
1895 def __init__(self
, parent
, log
):
1897 wx
.Panel
.__init
__(self
, parent
, -1)
1901 note1
= wx
.StaticText(self
, -1, errorText
)
1902 note2
= wx
.StaticText(self
, -1, "This is what the FloatCanvas can look like:")
1903 S
= wx
.BoxSizer(wx
.VERTICAL
)
1905 S
.Add(note1
, 0, wx
.ALIGN_CENTER
)
1906 S
.Add(note2
, 0, wx
.ALIGN_CENTER | wx
.BOTTOM
, 4)
1907 S
.Add(wx
.StaticBitmap(self
,-1,images
.getFloatCanvasBitmap()),0,wx
.ALIGN_CENTER
)
1913 ## TestPanel and runTest used for integration into wxPython Demo
1914 class TestPanel(wx
.Panel
):
1915 def __init__(self
, parent
, log
):
1917 wx
.Panel
.__init
__(self
, parent
, -1)
1918 note1
= wx
.StaticText(self
, -1, "The FloatCanvas Demo needs")
1919 note2
= wx
.StaticText(self
, -1, "a separate frame")
1920 b
= wx
.Button(self
, -1, "Open Demo Frame Now")
1921 b
.Bind(wx
.EVT_BUTTON
, self
.OnButton
)
1923 S
= wx
.BoxSizer(wx
.VERTICAL
)
1925 S
.Add(note1
, 0, wx
.ALIGN_CENTER
)
1926 S
.Add(note2
, 0, wx
.ALIGN_CENTER | wx
.BOTTOM
, 5)
1927 S
.Add(b
, 0, wx
.ALIGN_CENTER | wx
.ALL
, 5)
1932 def OnButton(self
, evt
):
1933 DrawFrame
= BuildDrawFrame()
1934 frame
= DrawFrame(None, -1, "FloatCanvas Drawing Window",wx
.DefaultPosition
,(500,500))
1936 #win = wx.lib.plot.TestFrame(self, -1, "PlotCanvas Demo")
1940 def runTest(frame
, nb
, log
):
1941 win
= TestPanel(nb
, log
)
1944 # import to get the doc
1945 from wx
.lib
import floatcanvas
1946 overview
= floatcanvas
.__doc
__