+ def TestHitTest(self,event=None):
+
+ self.UnBindAllMouseEvents()
+ Canvas = self.Canvas
+
+ Canvas.ClearAll()
+ Canvas.SetProjectionFun(None)
+
+ #Add a HitAble rectangle
+ w, h = 60, 20
+
+ dx = 80
+ dy = 40
+ x,y = 20, 20
+
+ #Add one that is not HitAble
+ Canvas.AddRectangle(x, y, w, h, LineWidth = 2)
+ Canvas.AddText("Not Hit-able", x, y, Position = "bl")
+
+
+ x += dx
+ R = Canvas.AddRectangle(x, y, w, h,LineWidth = 2)
+ R.Name = "Line Rectangle"
+ R.HitFill = False
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectGotHit)
+ Canvas.AddText("Left Click Line", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+
+ x += dx
+ color = "Red"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color + "Rectangle"
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectGotHit)
+ Canvas.AddText("Left Click Fill", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x = 20
+ y += dy
+ color = "LightBlue"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color + " Rectangle"
+ R.Bind(FloatCanvas.EVT_FC_RIGHT_DOWN, self.RectGotHit)
+ Canvas.AddText("Right Click Fill", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "Grey"
+ R = Canvas.AddEllipse(x, y, w, h,LineWidth = 2,FillColor = color)
+ R.Name = color +" Ellipse"
+ R.Bind(FloatCanvas.EVT_FC_RIGHT_DOWN, self.RectGotHit)
+ Canvas.AddText("Right Click Fill", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "Brown"
+ R = Canvas.AddCircle(x+dx/2, y+dy/2, dx/4, LineWidth = 2, FillColor = color)
+ R.Name = color + " Circle"
+ R.HitFill = True
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DCLICK, self.RectGotHit)
+ Canvas.AddText("Left D-Click Fill", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x = 20
+ y += dy
+ color = "Pink"
+ R = Canvas.AddCircle(x+dx/2, y+dy/2, dx/4, LineWidth = 2,FillColor = color)
+ R.Name = color + " Circle"
+ R.Bind(FloatCanvas.EVT_FC_LEFT_UP, self.RectGotHit)
+ Canvas.AddText("Left Up Fill", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "White"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color + " Rectangle"
+ R.Bind(FloatCanvas.EVT_FC_MIDDLE_DOWN, self.RectGotHit)
+ Canvas.AddText("Middle Down", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "AQUAMARINE"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color + " Rectangle"
+ R.Bind(FloatCanvas.EVT_FC_MIDDLE_UP, self.RectGotHit)
+ Canvas.AddText("Middle Up", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x = 20
+ y += dy
+ color = "CORAL"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color + " Rectangle"
+ R.Bind(FloatCanvas.EVT_FC_MIDDLE_DCLICK, self.RectGotHit)
+ Canvas.AddText("Middle DoubleClick", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "CYAN"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color + " Rectangle"
+ R.Bind(FloatCanvas.EVT_FC_RIGHT_UP, self.RectGotHit)
+ Canvas.AddText("Right Up", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "LIME GREEN"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color + " Rectangle"
+ R.Bind(FloatCanvas.EVT_FC_RIGHT_DCLICK, self.RectGotHit)
+ Canvas.AddText("Right Double Click", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x = 20
+ y += dy
+ color = "MEDIUM GOLDENROD"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color
+ R.Bind(FloatCanvas.EVT_FC_RIGHT_DOWN, self.RectGotHitRight)
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectGotHitLeft)
+ Canvas.AddText("L and R Click", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "SALMON"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color + " Rectangle"
+ R.Bind(FloatCanvas.EVT_FC_ENTER_OBJECT, self.RectMouseOver)
+ Canvas.AddText("Mouse Enter", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "MEDIUM VIOLET RED"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color
+ R.Bind(FloatCanvas.EVT_FC_LEAVE_OBJECT, self.RectMouseLeave)
+ Canvas.AddText("Mouse Leave", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x = 20
+ y += dy
+ color = "SKY BLUE"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color)
+ R.Name = color
+ R.Bind(FloatCanvas.EVT_FC_ENTER_OBJECT, self.RectMouseOver)
+ R.Bind(FloatCanvas.EVT_FC_LEAVE_OBJECT, self.RectMouseLeave)
+ Canvas.AddText("Enter and Leave", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "WHEAT"
+ R = Canvas.AddRectangle(x, y, w+12, h, LineColor = None, FillColor = color)
+ R.Name = color
+ R.Bind(FloatCanvas.EVT_FC_ENTER_OBJECT, self.RectMouseOver)
+ R.Bind(FloatCanvas.EVT_FC_LEAVE_OBJECT, self.RectMouseLeave)
+ Canvas.AddText("Mouse Enter&Leave", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "KHAKI"
+ R = Canvas.AddRectangle(x-12, y, w+12, h, LineColor = None, FillColor = color)
+ R.Name = color
+ R.Bind(FloatCanvas.EVT_FC_ENTER_OBJECT, self.RectMouseOver)
+ R.Bind(FloatCanvas.EVT_FC_LEAVE_OBJECT, self.RectMouseLeave)
+ Canvas.AddText("Mouse ENter&Leave", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x = 20
+ y += dy
+ L = Canvas.AddLine(( (x, y), (x+10, y+10), (x+w, y+h) ), LineWidth = 2, LineColor = "Red")
+ L.Name = "A Line"
+ L.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectGotHitLeft)
+ Canvas.AddText("Left Down", x, y, Position = "bl")
+ Canvas.AddText(L.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "SEA GREEN"
+ 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)
+ R = Canvas.AddPolygon(Points, LineWidth = 2, FillColor = color)
+ R.Name = color + " Polygon"
+ R.Bind(FloatCanvas.EVT_FC_RIGHT_DOWN, self.RectGotHitRight)
+ Canvas.AddText("RIGHT_DOWN", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x += dx
+ color = "Red"
+ 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)
+ R = Canvas.AddPointSet(Points, Diameter = 4, Color = color)
+ R.Name = "PointSet"
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.PointSetGotHit)
+ Canvas.AddText("LEFT_DOWN", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ x = 20
+ y += dy
+ T = Canvas.AddText("Hit-able Text", x, y, Size = 15, Color = "Red", Position = 'tl')
+ T.Name = "Hit-able Text"
+ T.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectGotHitLeft)
+ Canvas.AddText("Left Down", x, y, Position = "bl")
+
+ x += dx
+ T = Canvas.AddScaledText("Scaled Text", x, y, Size = 1./2*h, Color = "Pink", Position = 'bl')
+ Canvas.AddPointSet( (x, y), Diameter = 3)
+ T.Name = "Scaled Text"
+ T.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectGotHitLeft)
+ Canvas.AddText("Left Down", x, y, Position = "tl")
+
+ self.Canvas.ZoomToBB()
+
+ def TestHitTestForeground(self,event=None):
+ print "Running: TestHitTestForeground"
+
+ self.UnBindAllMouseEvents()
+ Canvas = self.Canvas
+
+ Canvas.ClearAll()
+ Canvas.SetProjectionFun(None)
+
+ #Add a Hitable rectangle
+ w, h = 60, 20
+
+ dx = 80
+ dy = 40
+ x,y = 20, 20
+
+ color = "Red"
+ R = Canvas.AddRectangle(x, y, w, h, LineWidth = 2, FillColor = color, InForeground = False)
+ R.Name = color + "Rectangle"
+ R.HitFill = True
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectGotHit)
+ Canvas.AddText("Left Click Fill", x, y, Position = "bl")
+ Canvas.AddText(R.Name, x, y+h, Position = "tl")
+
+ ## A set of Rectangles that move together
+
+ ## NOTE: In a real app, it might be better to create a new
+ ## custom FloatCanvas DrawObject
+
+ self.MovingRects = []
+ x += dx
+ color = "LightBlue"
+ R = Canvas.AddRectangle(x, y, w/2, h/2, LineWidth = 2, FillColor = color, InForeground = True)
+ R.HitFill = True
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectMoveLeft)
+ L = Canvas.AddText("Left", x + w/4, y + h/4, Position = "cc", InForeground = True)
+ self.MovingRects.extend( (R,L) )
+
+ x += w/2
+ R = Canvas.AddRectangle(x, y, w/2, h/2, LineWidth = 2, FillColor = color, InForeground = True)
+ R.HitFill = True
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectMoveRight)
+ L = Canvas.AddText("Right", x + w/4, y + h/4, Position = "cc", InForeground = True)
+ self.MovingRects.extend( (R,L) )
+
+ x -= w/2
+ y += h/2
+ R = Canvas.AddRectangle(x, y, w/2, h/2, LineWidth = 2, FillColor = color, InForeground = True)
+ R.HitFill = True
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectMoveUp)
+ L = Canvas.AddText("Up", x + w/4, y + h/4, Position = "cc", InForeground = True)
+ self.MovingRects.extend( (R,L) )
+
+
+ x += w/2
+ R = Canvas.AddRectangle(x, y, w/2, h/2, LineWidth = 2, FillColor = color, InForeground = True)
+ R.HitFill = True
+ R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RectMoveDown)
+ L = Canvas.AddText("Down", x + w/4, y + h/4, Position = "cc", InForeground = True)
+ self.MovingRects.extend( (R,L) )
+
+ self.Canvas.ZoomToBB()
+
+ def RectMoveLeft(self,Object):
+ self.MoveRects("left")
+
+ def RectMoveRight(self,Object):
+ self.MoveRects("right")
+
+ def RectMoveUp(self,Object):
+ self.MoveRects("up")
+
+ def RectMoveDown(self,Object):
+ self.MoveRects("down")
+
+ def MoveRects(self, Dir):
+ for Object in self.MovingRects:
+ X,Y = Object.XY
+ if Dir == "left": X -= 10
+ elif Dir == "right": X += 10
+ elif Dir == "up": Y += 10
+ elif Dir == "down": Y -= 10
+ Object.SetXY(X,Y)
+ self.Canvas.Draw()
+
+
+ def PointSetGotHit(self, Object):
+ print Object.Name, "Got Hit\n"
+
+ def RectGotHit(self, Object):
+ print Object.Name, "Got Hit\n"
+
+ def RectGotHitRight(self, Object):
+ print Object.Name, "Got Hit With Right\n"
+
+ def RectGotHitLeft(self, Object):
+ print Object.Name, "Got Hit with Left\n"
+
+ def RectMouseOver(self, Object):
+ print "Mouse entered:", Object.Name
+
+ def RectMouseLeave(self, Object):
+ print "Mouse left ", Object.Name
+
+
+ def TestText(self, event= None):
+
+ self.BindAllMouseEvents()
+ Canvas = self.Canvas
+ Canvas.ClearAll()
+ Canvas.SetProjectionFun(None)
+
+ x,y = (0, 0)
+
+ ## Add a non-visible rectangle, just to get a Bounding Box
+ ## Text objects have a zero-size bounding box, because it changes with zoom
+ Canvas.AddRectangle(-10,-10,20,20,LineWidth = 1, LineColor = None)
+
+ # Text
+ String = "Some text"
+## for i in range(10):
+## ts = random.randint(10,40)
+## cf = random.randint(0,len(colors)-1)
+## x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ self.Canvas.AddText("Top Left",x,y,Size = 14,Color = "Yellow",BackgroundColor = "Blue", Position = "tl")
+ self.Canvas.AddText("Bottom Left",x,y,Size = 14,Color = "Cyan",BackgroundColor = "Black",Position = "bl")
+ self.Canvas.AddText("Top Right",x,y,Size = 14,Color = "Black",BackgroundColor = "Cyan",Position = "tr")
+ self.Canvas.AddText("Bottom Right",x,y,Size = 14,Color = "Blue",BackgroundColor = "Yellow",Position = "br")
+ Canvas.AddPointSet((x,y), Color = "White", Diameter = 2)
+
+ x,y = (0, 2)
+
+ Canvas.AddPointSet((x,y), Color = "White", Diameter = 2)
+ self.Canvas.AddText("Top Center",x,y,Size = 14,Color = "Black",Position = "tc")
+ self.Canvas.AddText("Bottom Center",x,y,Size = 14,Color = "White",Position = "bc")
+
+ x,y = (0, 4)
+
+ Canvas.AddPointSet((x,y), Color = "White", Diameter = 2)
+ self.Canvas.AddText("Center Right",x,y,Size = 14,Color = "Black",Position = "cr")
+ self.Canvas.AddText("Center Left",x,y,Size = 14,Color = "Black",Position = "cl")
+
+ x,y = (0, -2)
+
+ Canvas.AddPointSet((x,y), Color = "White", Diameter = 2)
+ self.Canvas.AddText("Center Center",x,y,Size = 14,Color = "Black",Position = "cc")
+
+ self.Canvas.AddText("40 Pixels",-10,8,Size = 40)
+ self.Canvas.AddText("20 Pixels",-10,5,Size = 20)
+ self.Canvas.AddText("10 Pixels",-10,3,Size = 10)
+
+ self.Canvas.AddText("MODERN Font", -10, 0, Family = wx.MODERN)
+ self.Canvas.AddText("DECORATIVE Font", -10, -1, Family = wx.DECORATIVE)
+ self.Canvas.AddText("ROMAN Font", -10, -2, Family = wx.ROMAN)
+ self.Canvas.AddText("SCRIPT Font", -10, -3, Family = wx.SCRIPT)
+ self.Canvas.AddText("ROMAN BOLD Font", -10, -4, Family = wx.ROMAN, Weight=wx.BOLD)
+ self.Canvas.AddText("ROMAN ITALIC BOLD Font", -10, -5, Family = wx.ROMAN, Weight=wx.BOLD, Style=wx.ITALIC)
+
+ # NOTE: this font exists on my Linux box..who knows were else you'll find it!
+ Font = wx.Font(20, wx.DEFAULT, wx.ITALIC, wx.NORMAL, False, "zapf chancery")
+ self.Canvas.AddText("zapf chancery Font", -10, -6, Font = Font)
+
+ self.Canvas.ZoomToBB()
+
+ def TestScaledText(self, event= None):
+
+ self.BindAllMouseEvents()
+ Canvas = self.Canvas
+ Canvas.ClearAll()
+ Canvas.SetProjectionFun(None)
+
+ x,y = (0, 0)
+
+ T = Canvas.AddScaledText("Top Left",x,y,Size = 5,Color = "Yellow",BackgroundColor = "Blue", Position = "tl")
+ T = Canvas.AddScaledText("Bottom Left",x,y,Size = 5,Color = "Cyan",BackgroundColor = "Black",Position = "bl")
+ T = Canvas.AddScaledText("Top Right",x,y,Size = 5,Color = "Black",BackgroundColor = "Cyan",Position = "tr")
+ T = Canvas.AddScaledText("Bottom Right",x,y,Size = 5,Color = "Blue",BackgroundColor = "Yellow",Position = "br")
+ Canvas.AddPointSet((x,y), Color = "Red", Diameter = 4)
+
+
+ x,y = (0, 20)
+
+ Canvas.AddScaledText("Top Center",x,y,Size = 7,Color = "Black",Position = "tc")
+ Canvas.AddScaledText("Bottom Center",x,y,Size = 7,Color = "White",Position = "bc")
+ Canvas.AddPointSet((x,y), Color = "White", Diameter = 4)
+
+ x,y = (0, -20)
+
+ Canvas.AddScaledText("Center Right",x,y,Size = 9,Color = "Black",Position = "cr")
+ Canvas.AddScaledText("Center Left",x,y,Size = 9,Color = "Black",Position = "cl")
+ Canvas.AddPointSet((x,y), Color = "White", Diameter = 4)
+
+ x = -200
+
+ self.Canvas.AddScaledText("MODERN Font", x, 0, Size = 7, Family = wx.MODERN, Color = (0,0,0))
+ self.Canvas.AddScaledText("DECORATIVE Font", x, -10, Size = 7, Family = wx.DECORATIVE, Color = (0,0,1))
+ self.Canvas.AddScaledText("ROMAN Font", x, -20, Size = 7, Family = wx.ROMAN)
+ self.Canvas.AddScaledText("SCRIPT Font", x, -30, Size = 7, Family = wx.SCRIPT)
+ self.Canvas.AddScaledText("ROMAN BOLD Font", x, -40, Size = 7, Family = wx.ROMAN, Weight=wx.BOLD)
+ self.Canvas.AddScaledText("ROMAN ITALIC BOLD Font", x, -50, Size = 7, Family = wx.ROMAN, Weight=wx.BOLD, Style=wx.ITALIC)
+ Canvas.AddPointSet((x,0), Color = "White", Diameter = 4)
+
+
+ # NOTE: this font exists on my Linux box..who knows were else you'll find it!
+ x,y = (-100, 50)
+ Font = wx.Font(12, wx.DEFAULT, wx.ITALIC, wx.NORMAL, False, "zapf chancery")
+ T = self.Canvas.AddScaledText("zapf chancery Font", x, y, Size = 20, Font = Font, Position = 'bc')
+
+ x,y = (-50, -50)
+ Font = wx.Font(12, wx.DEFAULT, wx.ITALIC, wx.NORMAL, False, "bookman")
+ T = self.Canvas.AddScaledText("Bookman Font", x, y, Size = 8, Font = Font)
+