1#!/usr/bin/env python 2 3""" 4This demonstrates how to use FloatCanvas with a coordinate system where 5X and Y have different scales. In the example, a user had: 6 7X data in the range: 50e-6 to 2000e-6 8Y data in the range: 0 to 50000 9 10-chb 11 12""" 13 14import wx 15 16## import the installed version 17from wx.lib.floatcanvas import NavCanvas, FloatCanvas 18 19## import a local version 20#import sys 21#sys.path.append("..") 22#from floatcanvas import NavCanvas, FloatCanvas 23 24 25import numpy as N 26 27def YScaleFun(center): 28 """ 29 function that returns a scaling vector to scale y data to same range as x data 30 31 """ 32 # center gets ignored in this case 33 return N.array((5e7, 1), N.float) 34 35class DrawFrame(wx.Frame): 36 37 """ 38 A frame used for the FloatCanvas Demo 39 40 """ 41 42 def __init__(self, *args, **kwargs): 43 wx.Frame.__init__(self, *args, **kwargs) 44 45 self.CreateStatusBar() 46 47 # Add the Canvas 48 Canvas = NavCanvas.NavCanvas(self,-1, 49 size = (500,500), 50 ProjectionFun = YScaleFun, 51 Debug = 0, 52 BackgroundColor = "DARK SLATE BLUE", 53 ).Canvas 54 55 self.Canvas = Canvas 56 57 Point = N.array((50e-6, 0)) 58 Size = N.array(( (2000e-6 - 5e-6), 50000)) 59 Box = Canvas.AddRectangle(Point, 60 Size, 61 FillColor = "blue" 62 ) 63 64 Canvas.AddText("%s"%(Point,), Point, Position="cr") 65 Canvas.AddPoint(Point, Diameter=3, Color = "red") 66 67 68 Point = Point + Size 69 Canvas.AddText("%s"%(Point,), Point, Position="cl") 70 Canvas.AddPoint(Point, Diameter=3, Color = "red") 71 72 self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove) 73 74 75 self.Show() 76 Canvas.ZoomToBB() 77 78 def OnMove(self, event): 79 """ 80 Updates the status bar with the world coordinates 81 """ 82 self.SetStatusText("%.2g, %.2g"%tuple(event.Coords)) 83 84 85app = wx.App(False) 86F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) ) 87app.MainLoop() 88 89 90 91 92 93 94 95 96 97 98 99 100 101