mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-15 17:20:07 +01:00
- refactor of FloatCanvas package, unittest and demo run on Py27 and Py33
This commit is contained in:
@@ -5,7 +5,7 @@ import wx
|
||||
|
||||
## import the installed version
|
||||
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
|
||||
from wx.lib.floatcanvas.SpecialObjects import PieChart
|
||||
from wx.lib.floatcanvas.FCObjects import PieChart
|
||||
|
||||
## import a local version
|
||||
#import sys
|
||||
|
||||
58
wx/lib/floatcanvas/Utilities/BBoxTest.py → unittests/test_lib_floatcanvas_bbox.py
Executable file → Normal file
58
wx/lib/floatcanvas/Utilities/BBoxTest.py → unittests/test_lib_floatcanvas_bbox.py
Executable file → Normal file
@@ -1,27 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: BBoxTest.py
|
||||
# Purpose: Test code for the BBox Object
|
||||
#
|
||||
# Author:
|
||||
#
|
||||
# Created:
|
||||
# Version:
|
||||
# Date:
|
||||
# Licence:
|
||||
# Tags: phoenix-port
|
||||
#----------------------------------------------------------------------------
|
||||
import imp_unittest, unittest
|
||||
import wtc
|
||||
import wx
|
||||
|
||||
"""
|
||||
Test code for the BBox Object
|
||||
from wx.lib.floatcanvas.Utilities.BBox import *
|
||||
|
||||
"""
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
import unittest
|
||||
|
||||
from BBox import *
|
||||
|
||||
class testCreator(unittest.TestCase):
|
||||
class testCreator(wtc.WidgetTestCase):
|
||||
def testCreates(self):
|
||||
B = BBox(((0,0),(5,5)))
|
||||
self.failUnless(isinstance(B, BBox))
|
||||
@@ -74,7 +59,7 @@ class testCreator(unittest.TestCase):
|
||||
# Should catch tiny difference
|
||||
self.failUnlessRaises(ValueError, BBox, ((0,0), (-1e-20,5)) )
|
||||
|
||||
class testAsBBox(unittest.TestCase):
|
||||
class testAsBBox(wtc.WidgetTestCase):
|
||||
|
||||
def testPassThrough(self):
|
||||
B = BBox(((0,0),(5,5)))
|
||||
@@ -99,7 +84,7 @@ class testAsBBox(unittest.TestCase):
|
||||
A[0,0] = -10
|
||||
self.failUnless(C[0,0] == A[0,0])
|
||||
|
||||
class testIntersect(unittest.TestCase):
|
||||
class testIntersect(wtc.WidgetTestCase):
|
||||
|
||||
def testSame(self):
|
||||
B = BBox(((-23.5, 456),(56, 532.0)))
|
||||
@@ -188,7 +173,7 @@ class testIntersect(unittest.TestCase):
|
||||
|
||||
|
||||
|
||||
class testEquality(unittest.TestCase):
|
||||
class testEquality(wtc.WidgetTestCase):
|
||||
def testSame(self):
|
||||
B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
C = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
@@ -218,7 +203,7 @@ class testEquality(unittest.TestCase):
|
||||
C = N.array( ( (1.01, 2.0), (5.0, 10.0) ) )
|
||||
self.failIf(C == B)
|
||||
|
||||
class testInside(unittest.TestCase):
|
||||
class testInside(wtc.WidgetTestCase):
|
||||
def testSame(self):
|
||||
B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
C = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
@@ -274,7 +259,7 @@ class testInside(unittest.TestCase):
|
||||
C = BBox( ( (17.1, 8),(17.95, 32) ) )
|
||||
self.failIf(B.Inside(C) )
|
||||
|
||||
class testPointInside(unittest.TestCase):
|
||||
class testPointInside(wtc.WidgetTestCase):
|
||||
def testPointIn(self):
|
||||
B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
P = (3.0, 4.0)
|
||||
@@ -350,7 +335,7 @@ class testPointInside(unittest.TestCase):
|
||||
P = (-1, -10.0)
|
||||
self.failUnless(B.PointInside(P))
|
||||
|
||||
class testFromPoints(unittest.TestCase):
|
||||
class testFromPoints(wtc.WidgetTestCase):
|
||||
|
||||
def testCreate(self):
|
||||
Pts = N.array( ((5,2),
|
||||
@@ -398,7 +383,7 @@ class testFromPoints(unittest.TestCase):
|
||||
B[1,0] == 65.0 and
|
||||
B[1,1] == 43.2
|
||||
)
|
||||
class testMerge(unittest.TestCase):
|
||||
class testMerge(wtc.WidgetTestCase):
|
||||
A = BBox( ((-23.5, 456), (56, 532.0)) )
|
||||
B = BBox( ((-20.3, 460), (54, 465 )) )# B should be completely inside A
|
||||
C = BBox( ((-23.5, 456), (58, 540.0)) )# up and to the right or A
|
||||
@@ -424,7 +409,7 @@ class testMerge(unittest.TestCase):
|
||||
A.Merge(self.D)
|
||||
self.failUnless(A[0] == self.D[0] and A[1] == self.A[1])
|
||||
|
||||
class testWidthHeight(unittest.TestCase):
|
||||
class testWidthHeight(wtc.WidgetTestCase):
|
||||
B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
def testWidth(self):
|
||||
self.failUnless(self.B.Width == 4.0)
|
||||
@@ -444,7 +429,7 @@ class testWidthHeight(unittest.TestCase):
|
||||
def testSetH(self):
|
||||
self.failUnlessRaises(AttributeError, self.attemptSetHeight)
|
||||
|
||||
class testCenter(unittest.TestCase):
|
||||
class testCenter(wtc.WidgetTestCase):
|
||||
B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
def testCenter(self):
|
||||
self.failUnless( (self.B.Center == (3.0, 6.0)).all() )
|
||||
@@ -456,7 +441,7 @@ class testCenter(unittest.TestCase):
|
||||
self.failUnlessRaises(AttributeError, self.attemptSetCenter)
|
||||
|
||||
|
||||
class testBBarray(unittest.TestCase):
|
||||
class testBBarray(wtc.WidgetTestCase):
|
||||
BBarray = N.array( ( ((-23.5, 456), (56, 532.0)),
|
||||
((-20.3, 460), (54, 465 )),
|
||||
((-23.5, 456), (58, 540.0)),
|
||||
@@ -469,7 +454,7 @@ class testBBarray(unittest.TestCase):
|
||||
BB = fromBBArray(self.BBarray)
|
||||
self.failUnless(BB == self.BB, "Wrong BB was created. It was:\n%s \nit should have been:\n%s"%(BB, self.BB))
|
||||
|
||||
class testNullBBox(unittest.TestCase):
|
||||
class testNullBBox(wtc.WidgetTestCase):
|
||||
B1 = NullBBox()
|
||||
B2 = NullBBox()
|
||||
B3 = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
@@ -504,7 +489,7 @@ class testNullBBox(unittest.TestCase):
|
||||
self.failUnless( self.B3.Overlaps(self.B1) == False)
|
||||
|
||||
|
||||
class testInfBBox(unittest.TestCase):
|
||||
class testInfBBox(wtc.WidgetTestCase):
|
||||
B1 = InfBBox()
|
||||
B2 = InfBBox()
|
||||
B3 = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
@@ -556,7 +541,7 @@ class testInfBBox(unittest.TestCase):
|
||||
self.failUnless( self.NB.Overlaps(self.B1) == True)
|
||||
|
||||
|
||||
class testSides(unittest.TestCase):
|
||||
class testSides(wtc.WidgetTestCase):
|
||||
B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
|
||||
|
||||
def testLeft(self):
|
||||
@@ -568,7 +553,8 @@ class testSides(unittest.TestCase):
|
||||
def testTop(self):
|
||||
self.failUnless( self.B.Top == 10.0 )
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
2657
wx/lib/floatcanvas/FCObjects.py
Normal file
2657
wx/lib/floatcanvas/FCObjects.py
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,138 +0,0 @@
|
||||
import wx
|
||||
|
||||
## import a local version of FloatCanvas
|
||||
|
||||
|
||||
from wx.lib.floatcanvas import FloatCanvas
|
||||
from wx.lib.floatcanvas.Utilities import BBox
|
||||
from wx.lib.floatcanvas.Utilities import Colors
|
||||
|
||||
import numpy as N
|
||||
|
||||
XYObjectMixin = FloatCanvas.XYObjectMixin
|
||||
LineOnlyMixin = FloatCanvas.LineOnlyMixin
|
||||
DrawObject = FloatCanvas.DrawObject
|
||||
|
||||
class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject):
|
||||
"""
|
||||
This is DrawObject for a pie chart
|
||||
|
||||
You can pass in a bunch of values, and it will draw a pie chart for
|
||||
you, and it will make the chart, scaling the size of each "slice" to
|
||||
match your values.
|
||||
|
||||
The parameters are:
|
||||
|
||||
XY : The (x,y) coords of the center of the chart
|
||||
Diameter : The diamter of the chart in worls coords, unless you set
|
||||
"Scaled" to False, in which case it's in pixel coords.
|
||||
Values : sequence of values you want to make the chart of.
|
||||
FillColors=None : sequence of colors you want the slices. If
|
||||
None, it will choose (no guarantee youll like them!)
|
||||
FillStyles=None : Fill style you want ("Solid", "Hash", etc)
|
||||
LineColor = None : Color of lines separating the slices
|
||||
LineStyle = "Solid" : style of lines separating the slices
|
||||
LineWidth = 1 : With of lines separating the slices
|
||||
Scaled = True : Do you want the pie to scale when zooming? or stay the same size in pixels?
|
||||
InForeground = False: Should it be on the foreground?
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
##fixme: this should be a longer and better designed set.
|
||||
## Maybe one from: http://geography.uoregon.edu/datagraphics/color_scales.htm
|
||||
DefaultColorList = Colors.CategoricalColor1
|
||||
#["Red", "Green", "Blue", "Purple", "Yellow", "Cyan"]
|
||||
|
||||
def __init__(self,
|
||||
XY,
|
||||
Diameter,
|
||||
Values,
|
||||
FillColors=None,
|
||||
FillStyles=None,
|
||||
LineColor = None,
|
||||
LineStyle = "Solid",
|
||||
LineWidth = 1,
|
||||
Scaled = True,
|
||||
InForeground = False):
|
||||
DrawObject.__init__(self, InForeground)
|
||||
|
||||
self.XY = N.asarray(XY, N.float).reshape( (2,) )
|
||||
self.Diameter = Diameter
|
||||
self.Values = N.asarray(Values, dtype=N.float).reshape((-1,1))
|
||||
if FillColors is None:
|
||||
FillColors = self.DefaultColorList[:len(Values)]
|
||||
if FillStyles is None:
|
||||
FillStyles = ['Solid'] * len(FillColors)
|
||||
self.FillColors = FillColors
|
||||
self.FillStyles = FillStyles
|
||||
self.LineColor = LineColor
|
||||
self.LineStyle = LineStyle
|
||||
|
||||
self.Scaled = Scaled
|
||||
self.InForeground = InForeground
|
||||
|
||||
self.SetPen(LineColor, LineStyle, LineWidth)
|
||||
self.SetBrushes()
|
||||
self.CalculatePoints()
|
||||
|
||||
def SetFillColors(self, FillColors):
|
||||
self.FillColors = FillColors
|
||||
self.SetBrushes()
|
||||
|
||||
def SetFillStyles(self, FillStyles):
|
||||
self.FillStyles = FillStyles
|
||||
self.SetBrushed()
|
||||
|
||||
def SetValues(self, Values):
|
||||
Values = N.asarray(Values, dtype=N.float).reshape((-1,1))
|
||||
self.Values = Values
|
||||
self.CalculatePoints()
|
||||
|
||||
def CalculatePoints(self):
|
||||
# add the zero point to start
|
||||
Values = N.vstack( ( (0,), self.Values) )
|
||||
self.Angles = 360. * Values.cumsum()/Values.sum()
|
||||
self.CalcBoundingBox()
|
||||
|
||||
def SetBrushes(self):
|
||||
self.Brushes = []
|
||||
for FillColor, FillStyle in zip(self.FillColors, self.FillStyles):
|
||||
if FillColor is None or FillStyle is None:
|
||||
self.Brush = wx.TRANSPARENT_BRUSH
|
||||
else:
|
||||
self.Brushes.append(self.BrushList.setdefault( (FillColor, FillStyle),
|
||||
wx.Brush( FillColor, self.FillStyleList[FillStyle] )
|
||||
)
|
||||
)
|
||||
def CalcBoundingBox(self):
|
||||
if self.Scaled:
|
||||
self.BoundingBox = BBox.asBBox( ((self.XY-self.Diameter),(self.XY+self.Diameter)) )
|
||||
else:
|
||||
self.BoundingBox = BBox.asBBox((self.XY, self.XY))
|
||||
if self._Canvas:
|
||||
self._Canvas.BoundingBoxDirty = True
|
||||
|
||||
def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
|
||||
CenterXY = WorldToPixel(self.XY)
|
||||
if self.Scaled:
|
||||
Diameter = ScaleWorldToPixel( (self.Diameter,self.Diameter) )[0]
|
||||
else:
|
||||
Diameter = self.Diameter
|
||||
WH = N.array((Diameter,Diameter), dtype = N.float)
|
||||
Corner = CenterXY - (WH / 2)
|
||||
dc.SetPen(self.Pen)
|
||||
for i, brush in enumerate(self.Brushes):
|
||||
dc.SetBrush( brush )
|
||||
dc.DrawEllipticArc(Corner[0], Corner[1], WH[0], WH[1], self.Angles[i], self.Angles[i+1])
|
||||
if HTdc and self.HitAble:
|
||||
if self.Scaled:
|
||||
radius = (ScaleWorldToPixel(self.Diameter)/2)[0]# just the x-coord
|
||||
else:
|
||||
radius = self.Diameter/2
|
||||
HTdc.SetPen(self.HitPen)
|
||||
HTdc.SetBrush(self.HitBrush)
|
||||
HTdc.DrawCircle(CenterXY, radius)
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
"""
|
||||
SpecialObjects Package
|
||||
|
||||
Various special objects -- to specific for inclusion in the main FloatCanvas
|
||||
|
||||
"""
|
||||
from PieChart import PieChart
|
||||
@@ -1,4 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: Colors.py
|
||||
# Purpose: Contains color lists used in FloatCanvas
|
||||
#
|
||||
# Author:
|
||||
#
|
||||
# Created:
|
||||
# Version:
|
||||
# Date:
|
||||
# Licence:
|
||||
# Tags: phoenix-port, unittest, documented, py3-port
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
"""
|
||||
Colors.py
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: GUI.py
|
||||
# Purpose: Contains GUI related utilities for FloatCanvas
|
||||
#
|
||||
# Author:
|
||||
#
|
||||
# Created:
|
||||
# Version:
|
||||
# Date:
|
||||
# Licence:
|
||||
# Tags: phoenix-port, unittest, documented, py3-port
|
||||
#----------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
Part of the floatcanvas.Utilities package.
|
||||
|
||||
Reference in New Issue
Block a user