| 1 | |
| 2 | |
| 3 | #print "running:", wx.__version__ |
| 4 | ##First, make sure Numeric or numarray can be imported. |
| 5 | try: |
| 6 | import Numeric |
| 7 | import RandomArray |
| 8 | haveNumeric = True |
| 9 | except ImportError: |
| 10 | # Numeric isn't there, let's try numarray |
| 11 | try: |
| 12 | import numarray as Numeric |
| 13 | import numarray.random_array as RandomArray |
| 14 | haveNumeric = True |
| 15 | except ImportError: |
| 16 | # numarray isn't there either |
| 17 | haveNumeric = False |
| 18 | errorText = ( |
| 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" |
| 24 | ) |
| 25 | |
| 26 | #--------------------------------------------------------------------------- |
| 27 | |
| 28 | |
| 29 | def BuildDrawFrame(): # this gets called when needed, rather than on import |
| 30 | try: |
| 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 |
| 35 | import time, random |
| 36 | |
| 37 | class DrawFrame(wx.Frame): |
| 38 | |
| 39 | """ |
| 40 | A frame used for the FloatCanvas Demo |
| 41 | |
| 42 | """ |
| 43 | |
| 44 | |
| 45 | def __init__(self,parent, id,title,position,size): |
| 46 | wx.Frame.__init__(self,parent, id,title,position, size) |
| 47 | |
| 48 | ## Set up the MenuBar |
| 49 | MenuBar = wx.MenuBar() |
| 50 | |
| 51 | file_menu = wx.Menu() |
| 52 | item = file_menu.Append(-1, "&Close","Close this frame") |
| 53 | self.Bind(wx.EVT_MENU, self.OnQuit, item) |
| 54 | |
| 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") |
| 58 | |
| 59 | draw_menu = wx.Menu() |
| 60 | |
| 61 | item = draw_menu.Append(-1, "&Clear","Clear the Canvas") |
| 62 | self.Bind(wx.EVT_MENU, self.Clear, item) |
| 63 | |
| 64 | item = draw_menu.Append(-1, "&Draw Test","Run a test of drawing random components") |
| 65 | self.Bind(wx.EVT_MENU, self.DrawTest, item) |
| 66 | |
| 67 | item = draw_menu.Append(-1, "&Line Test","Run a test of drawing random lines") |
| 68 | self.Bind(wx.EVT_MENU, self.LineTest, item) |
| 69 | |
| 70 | item = draw_menu.Append(-1, "Draw &Map","Run a test of drawing a map") |
| 71 | self.Bind(wx.EVT_MENU, self.DrawMap, item) |
| 72 | |
| 73 | item = draw_menu.Append(-1, "&Text Test","Run a test of text drawing") |
| 74 | self.Bind(wx.EVT_MENU, self.TestText, item) |
| 75 | |
| 76 | item = draw_menu.Append(-1, "&ScaledText Test","Run a test of text drawing") |
| 77 | self.Bind(wx.EVT_MENU, self.TestScaledText, item) |
| 78 | |
| 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) |
| 81 | |
| 82 | item = draw_menu.Append(-1, "&Bitmap Test","Run a test of the Bitmap Object") |
| 83 | self.Bind(wx.EVT_MENU, self.TestBitmap, item) |
| 84 | |
| 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) |
| 87 | |
| 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) |
| 90 | |
| 91 | item = draw_menu.Append(-1, "&Animation","Run a test of Animation") |
| 92 | self.Bind(wx.EVT_MENU, self.TestAnimation, item) |
| 93 | |
| 94 | #item = draw_menu.Append(-1, "&Speed","Run a test of Drawing Speed") |
| 95 | #self.Bind(wx.EVT_MENU, self.SpeedTest, item) |
| 96 | |
| 97 | item = draw_menu.Append(-1, "Change &Properties","Run a test of Changing Object Properties") |
| 98 | self.Bind(wx.EVT_MENU, self.PropertiesChangeTest, item) |
| 99 | |
| 100 | item = draw_menu.Append(-1, "&Arrows","Run a test of Arrows") |
| 101 | self.Bind(wx.EVT_MENU, self.ArrowTest, item) |
| 102 | |
| 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) |
| 105 | |
| 106 | MenuBar.Append(draw_menu, "&Tests") |
| 107 | |
| 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") |
| 112 | |
| 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") |
| 118 | |
| 119 | self.SetMenuBar(MenuBar) |
| 120 | |
| 121 | self.CreateStatusBar() |
| 122 | |
| 123 | |
| 124 | # Add the Canvas |
| 125 | self.Canvas = NavCanvas.NavCanvas(self, |
| 126 | Debug = 0, |
| 127 | BackgroundColor = "DARK SLATE BLUE") |
| 128 | |
| 129 | self.MsgWindow = wx.TextCtrl(self, wx.ID_ANY, |
| 130 | "Look Here for output from events\n", |
| 131 | style = (wx.TE_MULTILINE | |
| 132 | wx.TE_READONLY | |
| 133 | wx.SUNKEN_BORDER) |
| 134 | ) |
| 135 | |
| 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) |
| 140 | |
| 141 | self.SetSizer(MainSizer) |
| 142 | wx.EVT_CLOSE(self, self.OnCloseWindow) |
| 143 | |
| 144 | FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove ) |
| 145 | |
| 146 | self.EventsAreBound = False |
| 147 | |
| 148 | ## getting all the colors for random objects |
| 149 | wx.lib.colourdb.updateColourDB() |
| 150 | self.colors = wx.lib.colourdb.getColourList() |
| 151 | |
| 152 | |
| 153 | return None |
| 154 | |
| 155 | def Log(self, text): |
| 156 | self.MsgWindow.AppendText(text) |
| 157 | if not text[-1] == "\n": |
| 158 | self.MsgWindow.AppendText("\n") |
| 159 | |
| 160 | |
| 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 ) |
| 167 | |
| 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 ) |
| 171 | |
| 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 ) |
| 175 | |
| 176 | FloatCanvas.EVT_MOUSEWHEEL(self.Canvas, self.OnWheel ) |
| 177 | self.EventsAreBound = True |
| 178 | |
| 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) |
| 184 | |
| 185 | FloatCanvas.EVT_MIDDLE_DOWN(self.Canvas, None ) |
| 186 | FloatCanvas.EVT_MIDDLE_UP(self.Canvas, None ) |
| 187 | FloatCanvas.EVT_MIDDLE_DCLICK(self.Canvas, None ) |
| 188 | |
| 189 | FloatCanvas.EVT_RIGHT_DOWN(self.Canvas, None ) |
| 190 | FloatCanvas.EVT_RIGHT_UP(self.Canvas, None ) |
| 191 | FloatCanvas.EVT_RIGHT_DCLICK(self.Canvas, None ) |
| 192 | |
| 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) |
| 197 | |
| 198 | FloatCanvas.EVT_MIDDLE_DOWN(self.Canvas, None ) |
| 199 | FloatCanvas.EVT_MIDDLE_UP(self.Canvas, None ) |
| 200 | FloatCanvas.EVT_MIDDLE_DCLICK(self.Canvas, None ) |
| 201 | |
| 202 | FloatCanvas.EVT_RIGHT_DOWN(self.Canvas, None ) |
| 203 | FloatCanvas.EVT_RIGHT_UP(self.Canvas, None ) |
| 204 | FloatCanvas.EVT_RIGHT_DCLICK(self.Canvas, None ) |
| 205 | |
| 206 | FloatCanvas.EVT_MOUSEWHEEL(self.Canvas, None ) |
| 207 | |
| 208 | self.EventsAreBound = False |
| 209 | |
| 210 | |
| 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(),)) |
| 216 | |
| 217 | def OnSavePNG(self, event=None): |
| 218 | import os |
| 219 | dlg = wx.FileDialog( |
| 220 | self, message="Save file as ...", defaultDir=os.getcwd(), |
| 221 | defaultFile="", wildcard="*.png", style=wx.SAVE |
| 222 | ) |
| 223 | if dlg.ShowModal() == wx.ID_OK: |
| 224 | path = dlg.GetPath() |
| 225 | if not(path[-4:].lower() == ".png"): |
| 226 | path = path+".png" |
| 227 | self.Canvas.SaveAsImage(path) |
| 228 | |
| 229 | |
| 230 | def OnLeftDown(self, event): |
| 231 | self.Log("LeftDown") |
| 232 | self.PrintCoords(event) |
| 233 | |
| 234 | def OnLeftUp(self, event): |
| 235 | self.Log("LeftUp") |
| 236 | self.PrintCoords(event) |
| 237 | |
| 238 | def OnLeftDouble(self, event): |
| 239 | self.Log("LeftDouble") |
| 240 | self.PrintCoords(event) |
| 241 | |
| 242 | def OnMiddleDown(self, event): |
| 243 | self.Log("MiddleDown") |
| 244 | self.PrintCoords(event) |
| 245 | |
| 246 | def OnMiddleUp(self, event): |
| 247 | self.Log("MiddleUp") |
| 248 | self.PrintCoords(event) |
| 249 | |
| 250 | def OnMiddleDouble(self, event): |
| 251 | self.Log("MiddleDouble") |
| 252 | self.PrintCoords(event) |
| 253 | |
| 254 | def OnRightDown(self, event): |
| 255 | self.Log("RightDown") |
| 256 | self.PrintCoords(event) |
| 257 | |
| 258 | def OnRightUp(self, event): |
| 259 | self.Log("RightDown") |
| 260 | self.PrintCoords(event) |
| 261 | |
| 262 | def OnRightDouble(self, event): |
| 263 | self.Log("RightDouble") |
| 264 | self.PrintCoords(event) |
| 265 | |
| 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" ) |
| 273 | else: # move up-down |
| 274 | self.Canvas.MoveImage( (0, Rot), "Panel" ) |
| 275 | |
| 276 | def OnMove(self, event): |
| 277 | """ |
| 278 | Updates the status bar with the world coordinates |
| 279 | """ |
| 280 | self.SetStatusText("%.2f, %.2f"%tuple(event.Coords)) |
| 281 | |
| 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", |
| 286 | "About Me", |
| 287 | wx.OK | wx.ICON_INFORMATION) |
| 288 | dlg.ShowModal() |
| 289 | dlg.Destroy() |
| 290 | |
| 291 | def ZoomToFit(self,event): |
| 292 | self.Canvas.ZoomToBB() |
| 293 | |
| 294 | def Clear(self,event = None): |
| 295 | self.UnBindAllMouseEvents() |
| 296 | self.Canvas.ClearAll() |
| 297 | self.Canvas.SetProjectionFun(None) |
| 298 | self.Canvas.Draw() |
| 299 | |
| 300 | def OnQuit(self,event): |
| 301 | self.Close(True) |
| 302 | |
| 303 | def OnCloseWindow(self, event): |
| 304 | self.Destroy() |
| 305 | |
| 306 | def DrawTest(self,event=None): |
| 307 | wx.GetApp().Yield() |
| 308 | |
| 309 | Range = (-10,10) |
| 310 | colors = self.colors |
| 311 | |
| 312 | self.BindAllMouseEvents() |
| 313 | Canvas = self.Canvas |
| 314 | |
| 315 | Canvas.ClearAll() |
| 316 | Canvas.SetProjectionFun(None) |
| 317 | |
| 318 | ############# Random tests of everything ############## |
| 319 | |
| 320 | # Rectangles |
| 321 | for i in range(3): |
| 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]) |
| 327 | |
| 328 | # Ellipses |
| 329 | for i in range(3): |
| 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]) |
| 336 | |
| 337 | # Points |
| 338 | for i in range(5): |
| 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) |
| 343 | |
| 344 | # SquarePoints |
| 345 | for i in range(500): |
| 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) |
| 350 | |
| 351 | # Circles |
| 352 | for i in range(5): |
| 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") |
| 360 | # Lines |
| 361 | for i in range(5): |
| 362 | points = [] |
| 363 | for j in range(random.randint(2,10)): |
| 364 | point = (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1])) |
| 365 | points.append(point) |
| 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]) |
| 370 | # Polygons |
| 371 | for i in range(3): |
| 372 | points = [] |
| 373 | for j in range(random.randint(2,6)): |
| 374 | point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) |
| 375 | points.append(point) |
| 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, |
| 380 | LineWidth = lw, |
| 381 | LineColor = colors[cl], |
| 382 | FillColor = colors[cf], |
| 383 | FillStyle = 'Solid') |
| 384 | |
| 385 | ## Pointset |
| 386 | for i in range(4): |
| 387 | points = [] |
| 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) |
| 392 | |
| 393 | # Text |
| 394 | String = "Unscaled text" |
| 395 | for i in range(3): |
| 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") |
| 400 | |
| 401 | # Scaled Text |
| 402 | String = "Scaled text" |
| 403 | for i in range(3): |
| 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") |
| 408 | |
| 409 | # Arrows |
| 410 | N = 5 |
| 411 | Points = RandomArray.uniform(Range[0], Range[1], (N,2) ) |
| 412 | for i in range(N): |
| 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)) |
| 419 | |
| 420 | Canvas.ZoomToBB() |
| 421 | |
| 422 | def TestAnimation(self,event=None): |
| 423 | """ |
| 424 | |
| 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. |
| 430 | |
| 431 | """ |
| 432 | wx.GetApp().Yield() |
| 433 | Range = (-10,10) |
| 434 | self.Range = Range |
| 435 | |
| 436 | self.UnBindAllMouseEvents() |
| 437 | Canvas = self.Canvas |
| 438 | |
| 439 | Canvas.ClearAll() |
| 440 | Canvas.SetProjectionFun(None) |
| 441 | |
| 442 | ## Random tests of everything: |
| 443 | colors = self.colors |
| 444 | # Rectangles |
| 445 | for i in range(3): |
| 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]) |
| 451 | |
| 452 | # Ellipses |
| 453 | for i in range(3): |
| 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]) |
| 459 | |
| 460 | # Circles |
| 461 | for i in range(5): |
| 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") |
| 469 | |
| 470 | # Lines |
| 471 | for i in range(5): |
| 472 | points = [] |
| 473 | for j in range(random.randint(2,10)): |
| 474 | point = (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1])) |
| 475 | points.append(point) |
| 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]) |
| 480 | |
| 481 | # Polygons |
| 482 | for i in range(3): |
| 483 | points = [] |
| 484 | for j in range(random.randint(2,6)): |
| 485 | point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) |
| 486 | points.append(point) |
| 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, |
| 491 | LineWidth = lw, |
| 492 | LineColor = colors[cl], |
| 493 | FillColor = colors[cf], |
| 494 | FillStyle = 'Solid') |
| 495 | |
| 496 | # Scaled Text |
| 497 | String = "Scaled text" |
| 498 | for i in range(3): |
| 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") |
| 503 | |
| 504 | |
| 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) |
| 509 | C.Text = T |
| 510 | |
| 511 | self.Timer = wx.PyTimer(self.ShowFrame) |
| 512 | self.FrameDelay = 50 # milliseconds |
| 513 | |
| 514 | Canvas.ZoomToBB() |
| 515 | |
| 516 | def ShowFrame(self): |
| 517 | Object = self.MovingObject |
| 518 | Range = self.Range |
| 519 | if self.TimeStep < self.NumTimeSteps: |
| 520 | x,y = Object.XY |
| 521 | if x > Range[1] or x < Range[0]: |
| 522 | self.dx = -self.dx |
| 523 | if y > Range[1] or y < Range[0]: |
| 524 | self.dy = -self.dy |
| 525 | Object.Move( (self.dx,self.dy) ) |
| 526 | Object.Text.Move( (self.dx,self.dy)) |
| 527 | self.Canvas.Draw() |
| 528 | self.TimeStep += 1 |
| 529 | wx.GetApp().Yield(True) |
| 530 | else: |
| 531 | self.Timer.Stop() |
| 532 | |
| 533 | |
| 534 | def MoveMe(self, Object): |
| 535 | self.MovingObject = Object |
| 536 | Range = self.Range |
| 537 | self.dx = random.uniform(Range[0]/4,Range[1]/4) |
| 538 | self.dy = random.uniform(Range[0]/4,Range[1]/4) |
| 539 | #import time |
| 540 | #start = time.time() |
| 541 | self.NumTimeSteps = 200 |
| 542 | self.TimeStep = 1 |
| 543 | self.Timer.Start(self.FrameDelay) |
| 544 | #print "Did %i frames in %f seconds"%(N, (time.time() - start) ) |
| 545 | |
| 546 | def TestHitTest(self,event=None): |
| 547 | wx.GetApp().Yield() |
| 548 | |
| 549 | self.UnBindAllMouseEvents() |
| 550 | Canvas = self.Canvas |
| 551 | |
| 552 | Canvas.ClearAll() |
| 553 | Canvas.SetProjectionFun(None) |
| 554 | |
| 555 | #Add a Hit-able rectangle |
| 556 | w, h = 60, 20 |
| 557 | |
| 558 | dx = 80 |
| 559 | dy = 40 |
| 560 | x, y = 20, 20 |
| 561 | FontSize = 8 |
| 562 | |
| 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") |
| 566 | |
| 567 | |
| 568 | x += dx |
| 569 | R = Canvas.AddRectangle((x, y), (w, h), LineWidth = 2) |
| 570 | R.Name = "Line Rectangle" |
| 571 | R.HitFill = False |
| 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") |
| 576 | |
| 577 | x += dx |
| 578 | color = "Red" |
| 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") |
| 584 | |
| 585 | x = 20 |
| 586 | y += dy |
| 587 | color = "LightBlue" |
| 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") |
| 593 | |
| 594 | x += dx |
| 595 | color = "Grey" |
| 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") |
| 601 | |
| 602 | x += dx |
| 603 | color = "Brown" |
| 604 | R = Canvas.AddCircle((x+dx/2, y+dy/2), dx/4, LineWidth = 2, FillColor = color) |
| 605 | R.Name = color + " Circle" |
| 606 | R.HitFill = True |
| 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") |
| 610 | |
| 611 | x = 20 |
| 612 | y += dy |
| 613 | color = "Pink" |
| 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") |
| 619 | |
| 620 | x += dx |
| 621 | color = "White" |
| 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") |
| 627 | |
| 628 | x += dx |
| 629 | color = "AQUAMARINE" |
| 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") |
| 635 | |
| 636 | x = 20 |
| 637 | y += dy |
| 638 | color = "CORAL" |
| 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") |
| 644 | |
| 645 | x += dx |
| 646 | color = "CYAN" |
| 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") |
| 652 | |
| 653 | x += dx |
| 654 | color = "LIME GREEN" |
| 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") |
| 660 | |
| 661 | x = 20 |
| 662 | y += dy |
| 663 | color = "MEDIUM GOLDENROD" |
| 664 | R = Canvas.AddRectangle((x, y), (w, h), LineWidth = 2, FillColor = color) |
| 665 | R.Name = 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") |
| 670 | |
| 671 | x += dx |
| 672 | color = "SALMON" |
| 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") |
| 678 | |
| 679 | x += dx |
| 680 | color = "MEDIUM VIOLET RED" |
| 681 | R = Canvas.AddRectangle((x, y), (w, h), LineWidth = 2, FillColor = color) |
| 682 | R.Name = 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") |
| 686 | |
| 687 | x = 20 |
| 688 | y += dy |
| 689 | color = "SKY BLUE" |
| 690 | R = Canvas.AddRectangle((x, y), (w, h), LineWidth = 2, FillColor = color) |
| 691 | R.Name = 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") |
| 696 | |
| 697 | x += dx |
| 698 | color = "WHEAT" |
| 699 | R = Canvas.AddRectangle((x, y), (w+12, h), LineColor = None, FillColor = color) |
| 700 | R.Name = 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") |
| 705 | |
| 706 | x += dx |
| 707 | color = "KHAKI" |
| 708 | R = Canvas.AddRectangle((x-12, y), (w+12, h), LineColor = None, FillColor = color) |
| 709 | R.Name = 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") |
| 714 | |
| 715 | x = 20 |
| 716 | y += dy |
| 717 | L = Canvas.AddLine(( (x, y), (x+10, y+10), (x+w, y+h) ), LineWidth = 2, LineColor = "Red") |
| 718 | L.Name = "A Line" |
| 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") |
| 722 | |
| 723 | x += dx |
| 724 | color = "SEA GREEN" |
| 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") |
| 731 | |
| 732 | x += dx |
| 733 | color = "Red" |
| 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) |
| 736 | R.Name = "PointSet" |
| 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") |
| 740 | |
| 741 | x = 20 |
| 742 | y += dy |
| 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") |
| 747 | |
| 748 | x += dx |
| 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") |
| 754 | |
| 755 | x += dx |
| 756 | color = "Cyan" |
| 757 | Point = (x + w/2, y) |
| 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") |
| 764 | |
| 765 | |
| 766 | self.Canvas.ZoomToBB() |
| 767 | |
| 768 | def TestHitTestForeground(self,event=None): |
| 769 | wx.GetApp().Yield() |
| 770 | |
| 771 | self.UnBindAllMouseEvents() |
| 772 | Canvas = self.Canvas |
| 773 | |
| 774 | Canvas.ClearAll() |
| 775 | Canvas.SetProjectionFun(None) |
| 776 | |
| 777 | #Add a Hitable rectangle |
| 778 | w, h = 60, 20 |
| 779 | |
| 780 | dx = 80 |
| 781 | dy = 40 |
| 782 | x,y = 20, 20 |
| 783 | |
| 784 | color = "Red" |
| 785 | R = Canvas.AddRectangle((x, y), (w, h), LineWidth = 2, FillColor = color, InForeground = False) |
| 786 | R.Name = color + "Rectangle" |
| 787 | R.HitFill = True |
| 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") |
| 791 | |
| 792 | ## A set of Rectangles that move together |
| 793 | |
| 794 | ## NOTE: In a real app, it might be better to create a new |
| 795 | ## custom FloatCanvas DrawObject |
| 796 | |
| 797 | self.MovingRects = [] |
| 798 | WH = (w/2, h/2) |
| 799 | x += dx |
| 800 | color = "LightBlue" |
| 801 | R = Canvas.AddRectangle((x, y), WH, LineWidth = 2, FillColor = color, InForeground = True) |
| 802 | R.HitFill = 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) ) |
| 806 | |
| 807 | x += w/2 |
| 808 | R = Canvas.AddRectangle((x, y), WH, LineWidth = 2, FillColor = color, InForeground = True) |
| 809 | R.HitFill = 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) ) |
| 813 | |
| 814 | x -= w/2 |
| 815 | y += h/2 |
| 816 | R = Canvas.AddRectangle((x, y), WH, LineWidth = 2, FillColor = color, InForeground = True) |
| 817 | R.HitFill = 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) ) |
| 821 | |
| 822 | |
| 823 | x += w/2 |
| 824 | R = Canvas.AddRectangle((x, y), WH, LineWidth = 2, FillColor = color, InForeground = True) |
| 825 | R.HitFill = 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) ) |
| 829 | |
| 830 | self.Canvas.ZoomToBB() |
| 831 | |
| 832 | def RectMoveLeft(self,Object): |
| 833 | self.MoveRects("left") |
| 834 | |
| 835 | def RectMoveRight(self,Object): |
| 836 | self.MoveRects("right") |
| 837 | |
| 838 | def RectMoveUp(self,Object): |
| 839 | self.MoveRects("up") |
| 840 | |
| 841 | def RectMoveDown(self,Object): |
| 842 | self.MoveRects("down") |
| 843 | |
| 844 | def MoveRects(self, Dir): |
| 845 | for Object in self.MovingRects: |
| 846 | X,Y = Object.XY |
| 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)) |
| 852 | self.Canvas.Draw() |
| 853 | |
| 854 | def PointSetGotHit(self, Object): |
| 855 | self.Log(Object.Name + "Got Hit\n") |
| 856 | |
| 857 | def RectGotHit(self, Object): |
| 858 | self.Log(Object.Name + "Got Hit\n") |
| 859 | |
| 860 | def RectGotHitRight(self, Object): |
| 861 | self.Log(Object.Name + "Got Hit With Right\n") |
| 862 | |
| 863 | def RectGotHitLeft(self, Object): |
| 864 | self.Log(Object.Name + "Got Hit with Left\n") |
| 865 | |
| 866 | def RectMouseOver(self, Object): |
| 867 | self.Log("Mouse entered:" + Object.Name) |
| 868 | |
| 869 | def RectMouseLeave(self, Object): |
| 870 | self.Log("Mouse left " + Object.Name) |
| 871 | |
| 872 | |
| 873 | def TestText(self, event= None): |
| 874 | wx.GetApp().Yield() |
| 875 | |
| 876 | self.BindAllMouseEvents() |
| 877 | Canvas = self.Canvas |
| 878 | Canvas.ClearAll() |
| 879 | Canvas.SetProjectionFun(None) |
| 880 | |
| 881 | Point = (3, 0) |
| 882 | |
| 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), |
| 886 | (20,20), |
| 887 | LineWidth = 1, |
| 888 | LineColor = None) |
| 889 | |
| 890 | # Text |
| 891 | String = "Some text" |
| 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) |
| 897 | |
| 898 | Point = (3, 2) |
| 899 | |
| 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") |
| 903 | |
| 904 | Point = (3, 4) |
| 905 | |
| 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") |
| 909 | |
| 910 | Point = (3, -2) |
| 911 | |
| 912 | Canvas.AddPointSet((Point), Color = "White", Diameter = 2) |
| 913 | self.Canvas.AddText("Center Center", |
| 914 | Point, Size = 14, |
| 915 | Color = "Black", |
| 916 | Position = "cc") |
| 917 | |
| 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) |
| 921 | |
| 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) |
| 928 | |
| 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) |
| 932 | |
| 933 | self.Canvas.ZoomToBB() |
| 934 | |
| 935 | def TestScaledText(self, event= None): |
| 936 | wx.GetApp().Yield() |
| 937 | |
| 938 | self.BindAllMouseEvents() |
| 939 | Canvas = self.Canvas |
| 940 | Canvas.ClearAll() |
| 941 | Canvas.SetProjectionFun(None) |
| 942 | |
| 943 | Point = (0, 0) |
| 944 | |
| 945 | T = Canvas.AddScaledText("Top Left", |
| 946 | Point, |
| 947 | Size = 5, |
| 948 | Color = "Yellow", |
| 949 | BackgroundColor = "Blue", |
| 950 | Position = "tl") |
| 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) |
| 955 | |
| 956 | |
| 957 | Point = (0, 20) |
| 958 | |
| 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) |
| 962 | |
| 963 | Point = (0, -20) |
| 964 | |
| 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) |
| 968 | |
| 969 | x = -200 |
| 970 | |
| 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) |
| 978 | |
| 979 | |
| 980 | # NOTE: this font exists on my Linux box..who knows were else you'll find it! |
| 981 | Point = (-100, 50) |
| 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') |
| 984 | |
| 985 | Point = (-50, -50) |
| 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) |
| 988 | |
| 989 | self.Canvas.ZoomToBB() |
| 990 | |
| 991 | def TestScaledTextBox(self, event= None): |
| 992 | wx.GetApp().Yield() |
| 993 | |
| 994 | self.UnBindAllMouseEvents() |
| 995 | Canvas = self.Canvas |
| 996 | Canvas.ClearAll() |
| 997 | Canvas.SetProjectionFun(None) |
| 998 | |
| 999 | Point = (45,40) |
| 1000 | Box = Canvas.AddScaledTextBox("A Two Line\nString", |
| 1001 | Point, |
| 1002 | 2, |
| 1003 | Color = "Black", |
| 1004 | BackgroundColor = None, |
| 1005 | LineColor = "Red", |
| 1006 | LineStyle = "Solid", |
| 1007 | LineWidth = 1, |
| 1008 | Width = None, |
| 1009 | PadSize = 5, |
| 1010 | Family = wx.ROMAN, |
| 1011 | Style = wx.NORMAL, |
| 1012 | Weight = wx.NORMAL, |
| 1013 | Underline = False, |
| 1014 | Position = 'br', |
| 1015 | Alignment = "left", |
| 1016 | InForeground = False) |
| 1017 | |
| 1018 | # All defaults |
| 1019 | Box = Canvas.AddScaledTextBox("A Two Line\nString", |
| 1020 | Point, |
| 1021 | 2) |
| 1022 | |
| 1023 | Box = Canvas.AddScaledTextBox("A Two Line\nString", |
| 1024 | Point, |
| 1025 | 2, |
| 1026 | BackgroundColor = "Yellow", |
| 1027 | LineColor = "Red", |
| 1028 | LineStyle = "Solid", |
| 1029 | PadSize = 5, |
| 1030 | Family = wx.TELETYPE, |
| 1031 | Position = 'bl') |
| 1032 | |
| 1033 | Box = Canvas.AddScaledTextBox("A String\nThis box is clickable", |
| 1034 | Point, |
| 1035 | 2, |
| 1036 | BackgroundColor = "Yellow", |
| 1037 | LineColor = "Red", |
| 1038 | LineStyle = "Solid", |
| 1039 | PadSize = 5, |
| 1040 | Family = wx.TELETYPE, |
| 1041 | Position = 'tr') |
| 1042 | |
| 1043 | Box.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.binding2) |
| 1044 | |
| 1045 | Canvas.AddPoint(Point, Diameter = 4) |
| 1046 | |
| 1047 | Point = (45,15) |
| 1048 | Box = Canvas.AddScaledTextBox("A Two Line\nString", |
| 1049 | Point, |
| 1050 | 2, |
| 1051 | Color = "Black", |
| 1052 | BackgroundColor = 'Red', |
| 1053 | LineColor = "Blue", |
| 1054 | LineStyle = "LongDash", |
| 1055 | LineWidth = 2, |
| 1056 | Width = None, |
| 1057 | PadSize = 5, |
| 1058 | Family = wx.TELETYPE, |
| 1059 | Style = wx.NORMAL, |
| 1060 | Weight = wx.NORMAL, |
| 1061 | Underline = False, |
| 1062 | Position = 'cr', |
| 1063 | Alignment = "left", |
| 1064 | InForeground = False) |
| 1065 | |
| 1066 | Box = Canvas.AddScaledTextBox("A Two Line\nString", |
| 1067 | Point, |
| 1068 | 1.5, |
| 1069 | Color = "Black", |
| 1070 | BackgroundColor = 'Red', |
| 1071 | LineColor = "Blue", |
| 1072 | LineStyle = "LongDash", |
| 1073 | LineWidth = 2, |
| 1074 | Width = None, |
| 1075 | PadSize = 5, |
| 1076 | Family = wx.TELETYPE, |
| 1077 | Style = wx.NORMAL, |
| 1078 | Weight = wx.NORMAL, |
| 1079 | Underline = False, |
| 1080 | Position = 'cl', |
| 1081 | Alignment = "left", |
| 1082 | InForeground = False) |
| 1083 | |
| 1084 | Canvas.AddPoint(Point, Diameter = 4) |
| 1085 | |
| 1086 | Point = (45,-10) |
| 1087 | Box = Canvas.AddScaledTextBox("A Two Line\nString", |
| 1088 | Point, |
| 1089 | 2, |
| 1090 | Color = "Black", |
| 1091 | BackgroundColor = 'Red', |
| 1092 | LineColor = "Blue", |
| 1093 | LineStyle = "LongDash", |
| 1094 | LineWidth = 2, |
| 1095 | Width = None, |
| 1096 | PadSize = 3, |
| 1097 | Family = wx.TELETYPE, |
| 1098 | Style = wx.NORMAL, |
| 1099 | Weight = wx.NORMAL, |
| 1100 | Underline = False, |
| 1101 | Position = 'tc', |
| 1102 | Alignment = "left", |
| 1103 | InForeground = False) |
| 1104 | |
| 1105 | Box = Canvas.AddScaledTextBox("A three\nLine\nString", |
| 1106 | Point, |
| 1107 | 1.5, |
| 1108 | Color = "Black", |
| 1109 | BackgroundColor = 'Red', |
| 1110 | LineColor = "Blue", |
| 1111 | LineStyle = "LongDash", |
| 1112 | LineWidth = 2, |
| 1113 | Width = None, |
| 1114 | PadSize = 0.5, |
| 1115 | Family = wx.TELETYPE, |
| 1116 | Style = wx.NORMAL, |
| 1117 | Weight = wx.NORMAL, |
| 1118 | Underline = False, |
| 1119 | Position = 'bc', |
| 1120 | Alignment = "left", |
| 1121 | InForeground = False) |
| 1122 | |
| 1123 | |
| 1124 | Canvas.AddPoint(Point, Diameter = 4) |
| 1125 | |
| 1126 | Box = Canvas.AddScaledTextBox("Some Auto Wrapped Text. There is enough to do.", |
| 1127 | (80,40), |
| 1128 | 2, |
| 1129 | BackgroundColor = 'White', |
| 1130 | LineWidth = 2, |
| 1131 | Width = 20, |
| 1132 | PadSize = 0.5, |
| 1133 | Family = wx.TELETYPE, |
| 1134 | ) |
| 1135 | |
| 1136 | Box = Canvas.AddScaledTextBox("Some more auto wrapped text. Wrapped to a different width.\n\nThis is another paragraph.", |
| 1137 | (80,20), |
| 1138 | 2, |
| 1139 | BackgroundColor = 'White', |
| 1140 | LineWidth = 2, |
| 1141 | Width = 40, |
| 1142 | PadSize = 0.5, |
| 1143 | Family = wx.ROMAN, |
| 1144 | Alignment = "right" |
| 1145 | ) |
| 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.", |
| 1148 | Point, |
| 1149 | Size = 3, |
| 1150 | BackgroundColor = 'White', |
| 1151 | LineWidth = 1, |
| 1152 | Width = 40, |
| 1153 | PadSize = 0.0, |
| 1154 | Family = wx.ROMAN, |
| 1155 | Position = "cc", |
| 1156 | LineSpacing = 0.8 |
| 1157 | ) |
| 1158 | Canvas.AddPoint(Point, "Red", 2) |
| 1159 | |
| 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, |
| 1165 | Point, |
| 1166 | Size = 4, |
| 1167 | Color = "Red", |
| 1168 | BackgroundColor = None,#'LightBlue', |
| 1169 | LineWidth = 1, |
| 1170 | LineColor = "White", |
| 1171 | Width = None, |
| 1172 | PadSize = 2, |
| 1173 | Family = wx.ROMAN, |
| 1174 | Position = Position, |
| 1175 | LineSpacing = 0.8 |
| 1176 | ) |
| 1177 | Canvas.AddPoint(Point, "Red", 4) |
| 1178 | |
| 1179 | Point = Numeric.array((-20, 60), Numeric.Float) |
| 1180 | Box = Canvas.AddScaledTextBox("Here is some\ncentered\ntext", |
| 1181 | Point, |
| 1182 | Size = 4, |
| 1183 | Color = "Red", |
| 1184 | BackgroundColor = 'LightBlue', |
| 1185 | LineWidth = 1, |
| 1186 | LineColor = "White", |
| 1187 | Width = None, |
| 1188 | PadSize = 2, |
| 1189 | Family = wx.ROMAN, |
| 1190 | Position = "tl", |
| 1191 | Alignment = "center", |
| 1192 | LineSpacing = 0.8 |
| 1193 | ) |
| 1194 | |
| 1195 | Point = Numeric.array((-20, 20), Numeric.Float) |
| 1196 | Box = Canvas.AddScaledTextBox("Here is some\nright aligned\ntext", |
| 1197 | Point, |
| 1198 | Size = 4, |
| 1199 | Color = "Red", |
| 1200 | BackgroundColor = 'LightBlue', |
| 1201 | LineColor = None, |
| 1202 | Width = None, |
| 1203 | PadSize = 2, |
| 1204 | Family = wx.ROMAN, |
| 1205 | Position = "tl", |
| 1206 | Alignment = "right", |
| 1207 | LineSpacing = 0.8 |
| 1208 | ) |
| 1209 | |
| 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.", |
| 1212 | Point, |
| 1213 | Size = 3, |
| 1214 | BackgroundColor = 'White', |
| 1215 | LineWidth = 1, |
| 1216 | Width = 40, |
| 1217 | PadSize = 2.0, |
| 1218 | Family = wx.ROMAN, |
| 1219 | Position = "cc", |
| 1220 | LineSpacing = 0.8, |
| 1221 | Alignment = 'center', |
| 1222 | ) |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | self.Canvas.ZoomToBB() |
| 1228 | |
| 1229 | def binding2(self, event): |
| 1230 | self.Log("I'm the TextBox") |
| 1231 | |
| 1232 | def TestBitmap(self, event= None): |
| 1233 | wx.GetApp().Yield() |
| 1234 | |
| 1235 | self.UnBindAllMouseEvents() |
| 1236 | Canvas = self.Canvas |
| 1237 | Canvas.ClearAll() |
| 1238 | Canvas.SetProjectionFun(None) |
| 1239 | |
| 1240 | Canvas.AddRectangle((10, 20), |
| 1241 | (400, 100), |
| 1242 | LineWidth = 3, |
| 1243 | LineColor = "Blue", |
| 1244 | FillColor = "Red") |
| 1245 | |
| 1246 | bmp = Resources.getMagPlusBitmap() |
| 1247 | |
| 1248 | Canvas.AddText("These are Unscaled Bitmaps:", (140, 90)) |
| 1249 | |
| 1250 | Point = (150, 50) |
| 1251 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "cc" ) |
| 1252 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1253 | |
| 1254 | Point = (200, 50) |
| 1255 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "br" ) |
| 1256 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1257 | |
| 1258 | Point = (200, 50) |
| 1259 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "bl" ) |
| 1260 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1261 | |
| 1262 | Point = (200, 50) |
| 1263 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "tr" ) |
| 1264 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1265 | |
| 1266 | Point = (200, 50) |
| 1267 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "tl" ) |
| 1268 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1269 | |
| 1270 | Point = (250, 50) |
| 1271 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "cr" ) |
| 1272 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1273 | |
| 1274 | Point = (250, 50) |
| 1275 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "cl" ) |
| 1276 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1277 | |
| 1278 | Point = (300, 50) |
| 1279 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "tc" ) |
| 1280 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1281 | |
| 1282 | Point = (300, 50) |
| 1283 | BitMap = Canvas.AddBitmap(bmp, Point, Position = "bc" ) |
| 1284 | Canvas.AddPoint(Point, Diameter=4, Color="Green") |
| 1285 | |
| 1286 | Canvas.AddScaledText("These are Scaled Bitmaps:", (220, -60), Size = 10, Position = "tr") |
| 1287 | Point = (250, -100) |
| 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") |
| 1291 | |
| 1292 | Point = (300, -100) |
| 1293 | BitMap = Canvas.AddScaledBitmap(Resources.getMondrianImage(), Point, Height = 50) |
| 1294 | |
| 1295 | self.Canvas.ZoomToBB() |
| 1296 | |
| 1297 | def DrawMap(self,event = None): |
| 1298 | wx.GetApp().Yield() |
| 1299 | import os, time |
| 1300 | self.BindAllMouseEvents() |
| 1301 | |
| 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) ) |
| 1317 | |
| 1318 | |
| 1319 | def LineTest(self,event = None): |
| 1320 | wx.GetApp().Yield() |
| 1321 | import os, time |
| 1322 | # import random |
| 1323 | colors = self.colors |
| 1324 | Range = (-10,10) |
| 1325 | ## Test of drawing lots of lines |
| 1326 | Canvas = self.Canvas |
| 1327 | Canvas.ClearAll() |
| 1328 | Canvas.SetProjectionFun(None) |
| 1329 | #start = time.clock() |
| 1330 | linepoints = [] |
| 1331 | linecolors = [] |
| 1332 | linewidths = [] |
| 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() |
| 1345 | Canvas.ZoomToBB() |
| 1346 | #print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) ) |
| 1347 | |
| 1348 | def SpeedTest(self,event=None): |
| 1349 | wx.GetApp().Yield() |
| 1350 | BigRange = (-1000,1000) |
| 1351 | colors = self.colors |
| 1352 | |
| 1353 | self.UnBindAllMouseEvents() |
| 1354 | Canvas = self.Canvas |
| 1355 | |
| 1356 | Canvas.ClearAll() |
| 1357 | Canvas.SetProjectionFun(None) |
| 1358 | |
| 1359 | # Pointset |
| 1360 | coords = [] |
| 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) |
| 1369 | Canvas.ZoomToBB() |
| 1370 | |
| 1371 | def PropertiesChangeTest(self,event=None): |
| 1372 | wx.GetApp().Yield() |
| 1373 | |
| 1374 | Range = (-10,10) |
| 1375 | colors = self.colors |
| 1376 | |
| 1377 | self.UnBindAllMouseEvents() |
| 1378 | Canvas = self.Canvas |
| 1379 | |
| 1380 | Canvas.ClearAll() |
| 1381 | Canvas.SetProjectionFun(None) |
| 1382 | |
| 1383 | self.ColorObjectsAll = [] |
| 1384 | self.ColorObjectsLine = [] |
| 1385 | self.ColorObjectsColor = [] |
| 1386 | self.ColorObjectsText = [] |
| 1387 | ##One of each object: |
| 1388 | # Rectangle |
| 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) |
| 1395 | |
| 1396 | # Ellipse |
| 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) |
| 1403 | |
| 1404 | # Point |
| 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)) |
| 1411 | |
| 1412 | # Circle |
| 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) |
| 1420 | |
| 1421 | # Line |
| 1422 | points = [] |
| 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])) |
| 1430 | |
| 1431 | # Polygon |
| 1432 | ## points = [] |
| 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, |
| 1441 | LineWidth = lw, |
| 1442 | LineColor = colors[cl], |
| 1443 | FillColor = colors[cf], |
| 1444 | FillStyle = 'Solid')) |
| 1445 | |
| 1446 | ## Pointset |
| 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) |
| 1452 | |
| 1453 | ## Point |
| 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) |
| 1459 | |
| 1460 | # Text |
| 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")) |
| 1466 | |
| 1467 | # Scaled Text |
| 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")) |
| 1473 | |
| 1474 | # A "Button" |
| 1475 | Button = Canvas.AddRectangle((-10, -12), (20, 3), LineStyle = None, FillColor = "Red") |
| 1476 | Canvas.AddScaledText("Click Here To Change Properties", |
| 1477 | (0, -10.5), |
| 1478 | Size = 0.7, |
| 1479 | Color = "Black", |
| 1480 | Position = "cc") |
| 1481 | |
| 1482 | Button.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.ChangeProperties) |
| 1483 | |
| 1484 | Canvas.ZoomToBB() |
| 1485 | |
| 1486 | def ChangeProperties(self, Object = None): |
| 1487 | colors = self.colors |
| 1488 | Range = (-10,10) |
| 1489 | |
| 1490 | for Object in self.ColorObjectsAll: |
| 1491 | pass |
| 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) |
| 1513 | |
| 1514 | def ArrowTest(self,event=None): |
| 1515 | wx.GetApp().Yield() |
| 1516 | self.UnBindAllMouseEvents() |
| 1517 | Canvas = self.Canvas |
| 1518 | |
| 1519 | Canvas.ClearAll() |
| 1520 | Canvas.SetProjectionFun(None) |
| 1521 | |
| 1522 | # put in a rectangle to get a bounding box |
| 1523 | Canvas.AddRectangle((0,0), (20,20), LineColor = None) |
| 1524 | |
| 1525 | # Draw some Arrows |
| 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 ) |
| 1534 | |
| 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) |
| 1538 | |
| 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) |
| 1542 | |
| 1543 | Canvas.ZoomToBB() |
| 1544 | |
| 1545 | def ArrowClicked(self,event): |
| 1546 | print "The Arrow was Clicked" |
| 1547 | |
| 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) ) |
| 1556 | |
| 1557 | self.Canvas.Draw(Force = True) |
| 1558 | |
| 1559 | def HideTest(self, event=None): |
| 1560 | wx.GetApp().Yield() |
| 1561 | |
| 1562 | self.UnBindAllMouseEvents() |
| 1563 | Canvas = self.Canvas |
| 1564 | Canvas.ClearAll() |
| 1565 | Canvas.SetProjectionFun(None) |
| 1566 | |
| 1567 | Range = (-10,10) |
| 1568 | |
| 1569 | # Create a couple random Polygons |
| 1570 | points = [] |
| 1571 | for j in range(6): |
| 1572 | point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) |
| 1573 | points.append(point) |
| 1574 | Poly = Canvas.AddPolygon(points, |
| 1575 | LineWidth = 2, |
| 1576 | LineColor = "Black", |
| 1577 | FillColor = "LightBlue", |
| 1578 | FillStyle = 'Solid') |
| 1579 | |
| 1580 | points = [] |
| 1581 | for j in range(6): |
| 1582 | point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) |
| 1583 | points.append(point) |
| 1584 | Poly2 = Canvas.AddPolygon(points, |
| 1585 | LineWidth = 2, |
| 1586 | LineColor = "Black", |
| 1587 | FillColor = "Purple", |
| 1588 | FillStyle = 'Solid', |
| 1589 | InForeground = True) |
| 1590 | |
| 1591 | HideButton = Canvas.AddScaledTextBox("Click To Hide\nBackground Polygon", |
| 1592 | (-10, 0), |
| 1593 | .5, |
| 1594 | BackgroundColor="Red", |
| 1595 | PadSize = 0.5, |
| 1596 | Position = 'tr', |
| 1597 | Alignment="center", |
| 1598 | ) |
| 1599 | HideButton.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.HidePoly) |
| 1600 | HideButton.HidePoly = Poly |
| 1601 | |
| 1602 | HideButton2 = Canvas.AddScaledTextBox("Click To Hide\nForeground Polygon", |
| 1603 | (-10, 5), |
| 1604 | .5, |
| 1605 | BackgroundColor="Red", |
| 1606 | PadSize = 0.5, |
| 1607 | Position = 'tr', |
| 1608 | Alignment="center", |
| 1609 | ) |
| 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 |
| 1613 | |
| 1614 | |
| 1615 | Canvas.ZoomToBB() |
| 1616 | |
| 1617 | def HidePoly(self, Button): |
| 1618 | Poly = Button.HidePoly |
| 1619 | if Poly.Visible: |
| 1620 | Poly.Hide() |
| 1621 | Button.SetText(Button.String.replace("Hide","Show")) |
| 1622 | else: |
| 1623 | Poly.Show() |
| 1624 | Button.SetText(Button.String.replace("Show", "Hide")) |
| 1625 | self.Canvas.Draw(True) |
| 1626 | |
| 1627 | def TempTest(self, event= None): |
| 1628 | wx.GetApp().Yield() |
| 1629 | |
| 1630 | self.UnBindAllMouseEvents() |
| 1631 | Canvas = self.Canvas |
| 1632 | Canvas.ClearAll() |
| 1633 | Canvas.SetProjectionFun(None) |
| 1634 | |
| 1635 | Range = (-10,10) |
| 1636 | |
| 1637 | # Create a random Polygon |
| 1638 | points = [] |
| 1639 | for j in range(6): |
| 1640 | point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1])) |
| 1641 | points.append(point) |
| 1642 | Poly = Canvas.AddPolygon(points, |
| 1643 | LineWidth = 2, |
| 1644 | LineColor = "Black", |
| 1645 | FillColor = "LightBlue", |
| 1646 | FillStyle = 'Solid') |
| 1647 | |
| 1648 | Poly.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.SelectPoly) |
| 1649 | |
| 1650 | self.SelectedPoly = None |
| 1651 | self.SelectPoints = [] |
| 1652 | self.SelectedPoint = None |
| 1653 | |
| 1654 | Canvas.ZoomToBB() |
| 1655 | |
| 1656 | def SelectPoly(self, Object): |
| 1657 | print "In SelectPoly" |
| 1658 | Canvas = self.Canvas |
| 1659 | if Object is self.SelectedPoly: |
| 1660 | pass |
| 1661 | else: |
| 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") |
| 1669 | P.VerticeNum = i |
| 1670 | P.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.SelectPointHit) |
| 1671 | self.SelectPoints.append(P) |
| 1672 | #Canvas.ZoomToBB() |
| 1673 | Canvas.Draw() |
| 1674 | |
| 1675 | def SelectPointHit(self, Point): |
| 1676 | print "Point Num: %i Hit"%Point.VerticeNum |
| 1677 | self.SelectedPoint = Point |
| 1678 | |
| 1679 | def Read_MapGen(self, filename, stats = 0,AllLines=0): |
| 1680 | """ |
| 1681 | This function reads a MapGen Format file, and |
| 1682 | returns a list of NumPy arrays with the line segments in them. |
| 1683 | |
| 1684 | Each NumPy array in the list is an NX2 array of Python Floats. |
| 1685 | |
| 1686 | The demo should have come with a file, "world.dat" that is the |
| 1687 | shorelines of the whole world, in MapGen format. |
| 1688 | |
| 1689 | """ |
| 1690 | import string |
| 1691 | file = open(filename,'rt') |
| 1692 | data = file.readlines() |
| 1693 | data = map(string.strip,data) |
| 1694 | |
| 1695 | Shorelines = [] |
| 1696 | segment = [] |
| 1697 | for line in data: |
| 1698 | if line: |
| 1699 | if line == "# -b": #New segment beginning |
| 1700 | if segment: Shorelines.append(Numeric.array(segment)) |
| 1701 | segment = [] |
| 1702 | else: |
| 1703 | segment.append(map(float,string.split(line))) |
| 1704 | if segment: Shorelines.append(Numeric.array(segment)) |
| 1705 | |
| 1706 | if stats: |
| 1707 | NumSegments = len(Shorelines) |
| 1708 | NumPoints = 0 |
| 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 |
| 1714 | if AllLines: |
| 1715 | Lines = [] |
| 1716 | for segment in Shorelines: |
| 1717 | Lines.append(segment[0]) |
| 1718 | for point in segment[1:-1]: |
| 1719 | Lines.append(point) |
| 1720 | Lines.append(point) |
| 1721 | Lines.append(segment[-1]) |
| 1722 | return Lines |
| 1723 | else: |
| 1724 | return Shorelines |
| 1725 | return DrawFrame |
| 1726 | |
| 1727 | #--------------------------------------------------------------------------- |
| 1728 | |
| 1729 | if __name__ == "__main__": |
| 1730 | |
| 1731 | import wx |
| 1732 | |
| 1733 | |
| 1734 | # check options: |
| 1735 | import sys, getopt |
| 1736 | optlist, args = getopt.getopt(sys.argv[1:],'l',["local", |
| 1737 | "all", |
| 1738 | "text", |
| 1739 | "map", |
| 1740 | "stext", |
| 1741 | "stextbox", |
| 1742 | "bitmap", |
| 1743 | "hit", |
| 1744 | "hitf", |
| 1745 | "animate", |
| 1746 | "speed", |
| 1747 | "temp", |
| 1748 | "props", |
| 1749 | "arrow", |
| 1750 | "hide"]) |
| 1751 | |
| 1752 | if not haveNumeric: |
| 1753 | raise ImportError(errorText) |
| 1754 | StartUpDemo = "all" # the default |
| 1755 | for opt in optlist: |
| 1756 | if opt[0] == "--all": |
| 1757 | StartUpDemo = "all" |
| 1758 | elif opt[0] == "--text": |
| 1759 | StartUpDemo = "text" |
| 1760 | elif opt[0] == "--map": |
| 1761 | StartUpDemo = "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": |
| 1769 | StartUpDemo = "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" |
| 1784 | |
| 1785 | class DemoApp(wx.App): |
| 1786 | """ |
| 1787 | How the demo works: |
| 1788 | |
| 1789 | Under the Draw menu, there are three options: |
| 1790 | |
| 1791 | *Draw Test: will put up a picture of a bunch of randomly generated |
| 1792 | objects, of each kind supported. |
| 1793 | |
| 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. |
| 1798 | |
| 1799 | *Clear: Clears the Canvas. |
| 1800 | |
| 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 |
| 1803 | selected. |
| 1804 | |
| 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. |
| 1809 | |
| 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) |
| 1815 | |
| 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. |
| 1820 | |
| 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 |
| 1824 | use. |
| 1825 | |
| 1826 | |
| 1827 | Any bugs, comments, feedback, questions, and especially code are welcome: |
| 1828 | |
| 1829 | -Chris Barker |
| 1830 | |
| 1831 | Chris.Barker@noaa.gov |
| 1832 | |
| 1833 | """ |
| 1834 | |
| 1835 | def __init__(self, *args, **kwargs): |
| 1836 | wx.App.__init__(self, *args, **kwargs) |
| 1837 | |
| 1838 | def OnInit(self): |
| 1839 | wx.InitAllImageHandlers() |
| 1840 | DrawFrame = BuildDrawFrame() |
| 1841 | frame = DrawFrame(None, -1, "FloatCanvas Demo App",wx.DefaultPosition,(700,700)) |
| 1842 | |
| 1843 | self.SetTopWindow(frame) |
| 1844 | frame.Show() |
| 1845 | |
| 1846 | ## check to see if the demo is set to start in a particular mode. |
| 1847 | if StartUpDemo == "text": |
| 1848 | frame.TestText() |
| 1849 | elif StartUpDemo == "stext": |
| 1850 | frame.TestScaledText() |
| 1851 | elif StartUpDemo == "stextbox": |
| 1852 | frame.TestScaledTextBox() |
| 1853 | elif StartUpDemo == "bitmap": |
| 1854 | frame.TestBitmap() |
| 1855 | elif StartUpDemo == "all": |
| 1856 | frame.DrawTest() |
| 1857 | elif StartUpDemo == "map": |
| 1858 | frame.DrawMap() |
| 1859 | elif StartUpDemo == "hit": |
| 1860 | frame.TestHitTest() |
| 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" |
| 1869 | frame.SpeedTest() |
| 1870 | elif StartUpDemo == "temp": |
| 1871 | "starting temp Test" |
| 1872 | frame.TempTest() |
| 1873 | elif StartUpDemo == "props": |
| 1874 | "starting PropertiesChange Test" |
| 1875 | frame.PropertiesChangeTest() |
| 1876 | elif StartUpDemo == "arrow": |
| 1877 | "starting arrow Test" |
| 1878 | frame.ArrowTest() |
| 1879 | elif StartUpDemo == "hide": |
| 1880 | "starting Hide Test" |
| 1881 | frame.HideTest() |
| 1882 | |
| 1883 | return True |
| 1884 | |
| 1885 | app = DemoApp(False)# put in True if you want output to go to it's own window. |
| 1886 | app.MainLoop() |
| 1887 | |
| 1888 | else: |
| 1889 | # It's not running stand-alone, set up for wxPython demo. |
| 1890 | # don't neeed wxversion here. |
| 1891 | import wx |
| 1892 | if not haveNumeric: |
| 1893 | ## TestPanel and runTest used for integration into wxPython Demo |
| 1894 | class TestPanel(wx.Panel): |
| 1895 | def __init__(self, parent, log): |
| 1896 | self.log = log |
| 1897 | wx.Panel.__init__(self, parent, -1) |
| 1898 | |
| 1899 | import images |
| 1900 | |
| 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) |
| 1904 | S.Add((10, 10), 1) |
| 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) |
| 1908 | S.Add((10, 10), 1) |
| 1909 | self.SetSizer(S) |
| 1910 | self.Layout() |
| 1911 | |
| 1912 | else: |
| 1913 | ## TestPanel and runTest used for integration into wxPython Demo |
| 1914 | class TestPanel(wx.Panel): |
| 1915 | def __init__(self, parent, log): |
| 1916 | self.log = 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) |
| 1922 | |
| 1923 | S = wx.BoxSizer(wx.VERTICAL) |
| 1924 | S.Add((10, 10), 1) |
| 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) |
| 1928 | S.Add((10, 10), 1) |
| 1929 | self.SetSizer(S) |
| 1930 | self.Layout() |
| 1931 | |
| 1932 | def OnButton(self, evt): |
| 1933 | DrawFrame = BuildDrawFrame() |
| 1934 | frame = DrawFrame(None, -1, "FloatCanvas Drawing Window",wx.DefaultPosition,(500,500)) |
| 1935 | |
| 1936 | #win = wx.lib.plot.TestFrame(self, -1, "PlotCanvas Demo") |
| 1937 | frame.Show() |
| 1938 | frame.DrawTest() |
| 1939 | |
| 1940 | def runTest(frame, nb, log): |
| 1941 | win = TestPanel(nb, log) |
| 1942 | return win |
| 1943 | |
| 1944 | # import to get the doc |
| 1945 | from wx.lib import floatcanvas |
| 1946 | overview = floatcanvas.__doc__ |
| 1947 | |
| 1948 | |
| 1949 | |
| 1950 | |
| 1951 | |
| 1952 | |
| 1953 | |
| 1954 | |