+ for Point in coords:
+ Canvas.AddPoint(Point, Diameter = 4)
+ print "It took %s seconds to add the points"%(time.clock() - start)
+ Canvas.ZoomToBB()
+
+ def PropertiesChangeTest(self,event=None):
+ wx.GetApp().Yield()
+
+ Range = (-10,10)
+ colors = self.colors
+
+ self.UnBindAllMouseEvents()
+ Canvas = self.Canvas
+
+ Canvas.ClearAll()
+ Canvas.SetProjectionFun(None)
+
+ self.ColorObjectsAll = []
+ self.ColorObjectsLine = []
+ self.ColorObjectsColor = []
+ self.ColorObjectsText = []
+ ##One of each object:
+ # Rectangle
+ Point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ lw = random.randint(1,5)
+ cf = random.randint(0,len(colors)-1)
+ wh = ( random.randint(1,5), random.randint(1,5) )
+ self.Rectangle = Canvas.AddRectangle(Point, wh, LineWidth = lw, FillColor = colors[cf])
+ self.ColorObjectsAll.append(self.Rectangle)
+
+ # Ellipse
+ Point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ lw = random.randint(1,5)
+ cf = random.randint(0,len(colors)-1)
+ wh = ( random.randint(1,5), random.randint(1,5) )
+ self.Ellipse = Canvas.AddEllipse(Point, wh, LineWidth = lw, FillColor = colors[cf])
+ self.ColorObjectsAll.append(self.Ellipse)
+
+ # Point
+ xy = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ D = random.randint(1,50)
+ lw = random.randint(1,5)
+ cf = random.randint(0,len(colors)-1)
+ cl = random.randint(0,len(colors)-1)
+ self.ColorObjectsColor.append(Canvas.AddPoint(xy, colors[cf], D))
+
+ # Circle
+ Point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ D = random.randint(1,5)
+ lw = random.randint(1,5)
+ cf = random.randint(0,len(colors)-1)
+ cl = random.randint(0,len(colors)-1)
+ self.Circle = Canvas.AddCircle(Point, D, LineWidth = lw, LineColor = colors[cl], FillColor = colors[cf])
+ self.ColorObjectsAll.append(self.Circle)
+
+ # Line
+ points = []
+ for j in range(random.randint(2,10)):
+ point = (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
+ points.append(point)
+ lw = random.randint(1,10)
+ cf = random.randint(0,len(colors)-1)
+ cl = random.randint(0,len(colors)-1)
+ self.ColorObjectsLine.append(Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl]))
+
+ # Polygon
+## points = []
+## for j in range(random.randint(2,6)):
+## point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+## points.append(point)
+ points = RandomArray.uniform(Range[0],Range[1],(6,2))
+ lw = random.randint(1,6)
+ cf = random.randint(0,len(colors)-1)
+ cl = random.randint(0,len(colors)-1)
+ self.ColorObjectsAll.append(Canvas.AddPolygon(points,
+ LineWidth = lw,
+ LineColor = colors[cl],
+ FillColor = colors[cf],
+ FillStyle = 'Solid'))
+
+ ## Pointset
+ points = RandomArray.uniform(Range[0],Range[1],(100,2))
+ cf = random.randint(0,len(colors)-1)
+ D = random.randint(1,4)
+ self.PointSet = Canvas.AddPointSet(points, Color = colors[cf], Diameter = D)
+ self.ColorObjectsColor.append(self.PointSet)
+
+ ## Point
+ point = RandomArray.uniform(Range[0],Range[1],(2,))
+ cf = random.randint(0,len(colors)-1)
+ D = random.randint(1,4)
+ self.Point = Canvas.AddPoint(point, Color = colors[cf], Diameter = D)
+ self.ColorObjectsColor.append(self.Point)
+
+ # Text
+ String = "Unscaled text"
+ ts = random.randint(10,40)
+ cf = random.randint(0,len(colors)-1)
+ Point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ self.ColorObjectsText.append(Canvas.AddText(String, Point, Size = ts, Color = colors[cf], Position = "cc"))
+
+ # Scaled Text
+ String = "Scaled text"
+ ts = random.random()*3 + 0.2
+ cf = random.randint(0,len(colors)-1)
+ Point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ self.ColorObjectsText.append(Canvas.AddScaledText(String, Point, Size = ts, Color = colors[cf], Position = "cc"))
+
+ # A "Button"
+ Button = Canvas.AddRectangle((-10, -12), (20, 3), LineStyle = None, FillColor = "Red")
+ Canvas.AddScaledText("Click Here To Change Properties",
+ (0, -10.5),
+ Size = 0.7,
+ Color = "Black",
+ Position = "cc")
+
+ Button.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.ChangeProperties)
+
+ Canvas.ZoomToBB()
+
+ def ChangeProperties(self, Object = None):
+ colors = self.colors
+ Range = (-10,10)
+
+ for Object in self.ColorObjectsAll:
+ pass
+ Object.SetFillColor(colors[random.randint(0,len(colors)-1)])
+ Object.SetLineColor(colors[random.randint(0,len(colors)-1)])
+ Object.SetLineWidth(random.randint(1,7))
+ Object.SetLineStyle(FloatCanvas.DrawObject.LineStyleList.keys()[random.randint(0,5)])
+ for Object in self.ColorObjectsLine:
+ Object.SetLineColor(colors[random.randint(0,len(colors)-1)])
+ Object.SetLineWidth(random.randint(1,7))
+ Object.SetLineStyle(FloatCanvas.DrawObject.LineStyleList.keys()[random.randint(0,5)])
+ for Object in self.ColorObjectsColor:
+ Object.SetColor(colors[random.randint(0,len(colors)-1)])
+ for Object in self.ColorObjectsText:
+ Object.SetColor(colors[random.randint(0,len(colors)-1)])
+ Object.SetBackgroundColor(colors[random.randint(0,len(colors)-1)])
+ self.Circle.SetDiameter(random.randint(1,10))
+ self.PointSet.SetDiameter(random.randint(1,8))
+ self.Point.SetDiameter(random.randint(1,8))
+ for Object in (self.Rectangle, self.Ellipse):
+ Point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ wh = ( random.randint(1,5), random.randint(1,5) )
+ Object.SetShape(Point, wh)
+ self.Canvas.Draw(Force = True)
+
+ def ArrowTest(self,event=None):
+ wx.GetApp().Yield()
+ self.UnBindAllMouseEvents()
+ Canvas = self.Canvas
+
+ Canvas.ClearAll()
+ Canvas.SetProjectionFun(None)
+
+ # put in a rectangle to get a bounding box
+ Canvas.AddRectangle((0,0), (20,20), LineColor = None)
+
+ # Draw some Arrows
+ Canvas.AddArrow((10,10),Length = 40, Direction = 0)
+ Canvas.AddArrow((10,10),Length = 50, Direction = 45 ,LineWidth = 2, LineColor = "Black", ArrowHeadAngle = 20)
+ Canvas.AddArrow((10,10),Length = 60, Direction = 90 ,LineWidth = 3, LineColor = "Red", ArrowHeadAngle = 30)
+ Canvas.AddArrow((10,10),Length = 70, Direction = 135,LineWidth = 4, LineColor = "Red", ArrowHeadAngle = 40)
+ Canvas.AddArrow((10,10),Length = 80, Direction = 180,LineWidth = 5, LineColor = "Blue", ArrowHeadAngle = 50)
+ Canvas.AddArrow((10,10),Length = 90, Direction = 225,LineWidth = 4, LineColor = "Blue", ArrowHeadAngle = 60)
+ Canvas.AddArrow((10,10),Length = 100,Direction = 270,LineWidth = 3, LineColor = "Green", ArrowHeadAngle = 70)
+ Canvas.AddArrow((10,10),Length = 110,Direction = 315,LineWidth = 2, LineColor = "Green", ArrowHeadAngle = 90 )
+
+ Canvas.AddText("Clickable Arrow", (4,18), Position = "bc")
+ Arrow = Canvas.AddArrow((4,18), 80, Direction = 90 ,LineWidth = 3, LineColor = "Red", ArrowHeadAngle = 30)
+ Arrow.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.ArrowClicked)
+
+ Canvas.AddText("Changable Arrow", (16,4), Position = "cc")
+ self.RotArrow = Canvas.AddArrow((16,4), 80, Direction = 0 ,LineWidth = 3, LineColor = "Green", ArrowHeadAngle = 30)
+ self.RotArrow.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.RotateArrow)
+
+ Canvas.ZoomToBB()
+
+ def ArrowClicked(self,event):
+ print "The Arrow was Clicked"
+
+ def RotateArrow(self,event):
+ ##print "The Changeable Arrow was Clicked"
+ ## You can do them either one at a time, or both at once
+ ## Doing them both at once prevents the arrow points from being calculated twice
+ #self.RotArrow.SetDirection(self.RotArrow.Direction + random.uniform(-90,90))
+ #self.RotArrow.SetLength(self.RotArrow.Length + random.randint(-20,20))
+ self.RotArrow.SetLengthDirection(self.RotArrow.Length + random.randint(-20,20),
+ self.RotArrow.Direction + random.uniform(-90,90) )
+
+ self.Canvas.Draw(Force = True)
+
+ def HideTest(self, event=None):
+ wx.GetApp().Yield()
+
+ self.UnBindAllMouseEvents()
+ Canvas = self.Canvas
+ Canvas.ClearAll()
+ Canvas.SetProjectionFun(None)
+
+ Range = (-10,10)
+
+ # Create a couple random Polygons
+ points = []
+ for j in range(6):
+ point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ points.append(point)
+ Poly = Canvas.AddPolygon(points,
+ LineWidth = 2,
+ LineColor = "Black",
+ FillColor = "LightBlue",
+ FillStyle = 'Solid')
+
+ points = []
+ for j in range(6):
+ point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
+ points.append(point)
+ Poly2 = Canvas.AddPolygon(points,
+ LineWidth = 2,
+ LineColor = "Black",
+ FillColor = "Purple",
+ FillStyle = 'Solid',
+ InForeground = True)
+
+ HideButton = Canvas.AddScaledTextBox("Click To Hide\nBackground Polygon",
+ (-10, 0),
+ .5,
+ BackgroundColor="Red",
+ PadSize = 0.5,
+ Position = 'tr',
+ Alignment="center",
+ )
+ HideButton.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.HidePoly)
+ HideButton.HidePoly = Poly