From 546d770ddbb63c65a55854f9cf488a7af418164c Mon Sep 17 00:00:00 2001 From: Metallicow Date: Wed, 12 Oct 2016 22:38:31 -0500 Subject: [PATCH] Trim Whitespace floatcanvas directory --- wx/lib/floatcanvas/FCEvents.py | 2 +- wx/lib/floatcanvas/FCObjects.py | 338 ++++++++++++------------- wx/lib/floatcanvas/FloatCanvas.py | 92 +++---- wx/lib/floatcanvas/GUIMode.py | 18 +- wx/lib/floatcanvas/NavCanvas.py | 22 +- wx/lib/floatcanvas/Utilities/BBox.py | 70 ++--- wx/lib/floatcanvas/Utilities/Colors.py | 24 +- wx/lib/floatcanvas/Utilities/GUI.py | 8 +- wx/lib/floatcanvas/__init__.py | 6 +- 9 files changed, 290 insertions(+), 290 deletions(-) diff --git a/wx/lib/floatcanvas/FCEvents.py b/wx/lib/floatcanvas/FCEvents.py index 8ff835d3..c51fbfd7 100644 --- a/wx/lib/floatcanvas/FCEvents.py +++ b/wx/lib/floatcanvas/FCEvents.py @@ -1,6 +1,6 @@ #---------------------------------------------------------------------------- # Name: FCEvents.py -# Purpose: A convenient place to put all event types and binders for +# Purpose: A convenient place to put all event types and binders for # FloatCanvas, and to help avoid circular imports. # # Author: diff --git a/wx/lib/floatcanvas/FCObjects.py b/wx/lib/floatcanvas/FCObjects.py index 1e051f95..ec382e0a 100644 --- a/wx/lib/floatcanvas/FCObjects.py +++ b/wx/lib/floatcanvas/FCObjects.py @@ -35,7 +35,7 @@ global FontScale def ComputeFontScale(): """ Compute the font scale. - + A global variable to hold the scaling from pixel size to point size. """ global FontScale @@ -46,7 +46,7 @@ def ComputeFontScale(): del dc # why do we do this here, causes a Sphinx build crash -#ComputeFontScale() +#ComputeFontScale() ## fixme: This should probably be re-factored into a class _testBitmap = None @@ -78,7 +78,7 @@ def _cycleidxs(indexcount, maxvalue, step): else: outcolor = dc.GetPixel(0,0) return outcolor == color - + if indexcount == 0: yield () else: @@ -118,11 +118,11 @@ class DrawObject: def __init__(self, InForeground = False, IsVisible = True): """ Default class constructor. - + :param boolean `InForeground`: Define if object should be in foreground or not :param boolean `IsVisible`: Define if object should be visible - + """ self.InForeground = InForeground @@ -197,7 +197,7 @@ class DrawObject: def Bind(self, Event, CallBackFun): """ Bind an event to the DrawObject - + :param `Event`: see below for supported event types - EVT_FC_LEFT_DOWN @@ -214,7 +214,7 @@ class DrawObject: :param `CallBackFun`: the call back function for the event - + """ ##fixme: Way too much Canvas Manipulation here! self.CallBackFuncs[Event] = CallBackFun @@ -246,9 +246,9 @@ class DrawObject: def UnBindAll(self): """ Unbind all events - + .. note:: Currently only removes one from each list - + """ ## fixme: this only removes one from each list, there could be more. ## + patch by Tim Ansel @@ -264,7 +264,7 @@ class DrawObject: def SetBrush(self, FillColor, FillStyle): """ Set the brush for this DrawObject - + :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid entries :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle` @@ -283,12 +283,12 @@ class DrawObject: def SetPen(self, LineColor, LineStyle, LineWidth): """ Set the Pen for this DrawObject - + :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid entries :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle` for valid entries - :param integer `LineWidth`: the width in pixels + :param integer `LineWidth`: the width in pixels """ if (LineColor is None) or (LineStyle is None): self.Pen = wx.TRANSPARENT_PEN @@ -301,9 +301,9 @@ class DrawObject: def SetHitBrush(self, HitColor): """ Set the brush used for hit test, do not call directly. - + :param `HitColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` - + """ if not self.HitFill: self.HitBrush = wx.TRANSPARENT_BRUSH @@ -315,10 +315,10 @@ class DrawObject: def SetHitPen(self, HitColor, LineWidth): """ Set the pen used for hit test, do not call directly. - + :param `HitColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param integer `LineWidth`: the line width in pixels - + """ if not self.HitLine: self.HitPen = wx.TRANSPARENT_PEN @@ -330,10 +330,10 @@ class DrawObject: def SetColor(self, Color): """ Set the Color - this method is overridden in the subclasses - + :param `Color`: use one of the following values any valid entry from :class:`wx.ColourDatabase` - + - ``Green`` - ``White`` - ``Black`` @@ -346,27 +346,27 @@ class DrawObject: """ pass - + def SetLineColor(self, LineColor): """ Set the LineColor - this method is overridden in the subclasses - + :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid values - + """ pass - + def SetLineStyle(self, LineStyle): """ Set the LineStyle - this method is overridden in the subclasses - + :param `LineStyle`: Use one of the following values or ``None`` : - + ===================== ============================= Style Description ===================== ============================= - ``Solid`` Solid line + ``Solid`` Solid line ``Transparent`` A transparent line ``Dot`` Dotted line ``LongDash`` Dashed line (long) @@ -376,32 +376,32 @@ class DrawObject: """ pass - + def SetLineWidth(self, LineWidth): """ Set the LineWidth - + :param integer `LineWidth`: sets the line width in pixel - + """ pass def SetFillColor(self, FillColor): """ Set the FillColor - this method is overridden in the subclasses - + :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid values - + """ pass def SetFillStyle(self, FillStyle): """ Set the FillStyle - this method is overridden in the subclasses - + :param string `FillStyle`: following is a list of valid values: - + ===================== ========================================= Style Description ===================== ========================================= @@ -453,10 +453,10 @@ class ColorOnlyMixin: def SetColor(self, Color): """ Set the Color - + :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid values - + """ self.SetPen(Color,"Solid",1) self.SetBrush(Color,"Solid") @@ -474,22 +474,22 @@ class LineOnlyMixin: def SetLineColor(self, LineColor): """ Set the LineColor - + :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid values - + """ self.LineColor = LineColor self.SetPen(LineColor,self.LineStyle,self.LineWidth) SetColor = SetLineColor# so that it will do something reasonable - + def SetLineStyle(self, LineStyle): """ Set the LineStyle - + :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle` for valid values - + """ self.LineStyle = LineStyle self.SetPen(self.LineColor,LineStyle,self.LineWidth) @@ -497,9 +497,9 @@ class LineOnlyMixin: def SetLineWidth(self, LineWidth): """ Set the LineWidth - + :param integer `LineWidth`: line width in pixels - + """ self.LineWidth = LineWidth self.SetPen(self.LineColor,self.LineStyle,LineWidth) @@ -514,10 +514,10 @@ class LineAndFillMixin(LineOnlyMixin): def SetFillColor(self, FillColor): """ Set the FillColor - + :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid values - + """ self.FillColor = FillColor self.SetBrush(FillColor, self.FillStyle) @@ -525,10 +525,10 @@ class LineAndFillMixin(LineOnlyMixin): def SetFillStyle(self, FillStyle): """ Set the FillStyle - + :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle` for valid values - + """ self.FillStyle = FillStyle self.SetBrush(self.FillColor,FillStyle) @@ -536,12 +536,12 @@ class LineAndFillMixin(LineOnlyMixin): def SetUpDraw(self, dc, WorldToPixel, ScaleWorldToPixel, HTdc): """ Setup for draw - + :param `dc`: the dc to draw ??? :param `WorldToPixel`: ??? :param `ScaleWorldToPixel`: ??? :param `HTdc`: ??? - + """ dc.SetPen(self.Pen) dc.SetBrush(self.Brush) @@ -561,8 +561,8 @@ class XYObjectMixin: def Move(self, Delta): """ Moves the object by delta, where delta is a (dx, dy) pair. - - :param `Delta`: is a (dx, dy) pair ideally a `NumPy `_ + + :param `Delta`: is a (dx, dy) pair ideally a `NumPy `_ array of shape (2, ) """ @@ -598,8 +598,8 @@ class PointsObjectMixin: def Move(self, Delta): """ Moves the object by delta, where delta is a (dx, dy) pair. - - :param `Delta`: is a (dx, dy) pair ideally a `NumPy `_ + + :param `Delta`: is a (dx, dy) pair ideally a `NumPy `_ array of shape (2, ) """ @@ -665,7 +665,7 @@ class Polygon(PointsObjectMixin, LineAndFillMixin, DrawObject): InForeground = False): """ Default class constructor. - + :param `Points`: start point, takes a 2-tuple, or a (2,) `NumPy `_ array of point coordinates :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` @@ -674,7 +674,7 @@ class Polygon(PointsObjectMixin, LineAndFillMixin, DrawObject): :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle` :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self, InForeground) self.Points = N.array(Points ,N.float) # this DOES need to make a copy @@ -716,14 +716,14 @@ class Line(PointsObjectMixin, LineOnlyMixin, DrawObject): InForeground = False): """ Default class constructor. - + :param `Points`: takes a 2-tuple, or a (2,) `NumPy `_ array of point coordinates :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle` :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth` :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self, InForeground) @@ -753,9 +753,9 @@ class Spline(Line): def __init__(self, *args, **kwargs): """ Default class constructor. - + see :class:`~lib.floatcanvas.FloatCanvas.Line` - + """ Line.__init__(self, *args, **kwargs) @@ -800,7 +800,7 @@ class Arrow(XYObjectMixin, LineOnlyMixin, DrawObject): :param `ArrowHeadSize`: size of arrow head in pixels :param `ArrowHeadAngle`: angle of arrow head in degrees :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self, InForeground) @@ -827,7 +827,7 @@ class Arrow(XYObjectMixin, LineOnlyMixin, DrawObject): def SetDirection(self, Direction): """ Set the direction - + :param integer `Direction`: angle of arrow in degrees, zero is straight up `+` angle is to the right @@ -838,9 +838,9 @@ class Arrow(XYObjectMixin, LineOnlyMixin, DrawObject): def SetLength(self, Length): """ Set the length - + :param integer `Length`: length of arrow in pixels - + """ self.Length = Length self.CalcArrowPoints() @@ -848,7 +848,7 @@ class Arrow(XYObjectMixin, LineOnlyMixin, DrawObject): def SetLengthDirection(self, Length, Direction): """ Set the lenght and direction - + :param integer `Length`: length of arrow in pixels :param integer `Direction`: angle of arrow in degrees, zero is straight up `+` angle is to the right @@ -929,7 +929,7 @@ class ArrowLine(PointsObjectMixin, LineOnlyMixin, DrawObject): :param `ArrowHeadSize`: size of arrow head in pixels :param `ArrowHeadAngle`: angle of arrow head in degrees :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self, InForeground) @@ -1006,13 +1006,13 @@ class PointSet(PointsObjectMixin, ColorOnlyMixin, DrawObject): def __init__(self, Points, Color="Black", Diameter=1, InForeground=False): """ Default class constructor. - + :param `Points`: takes a 2-tuple, or a (2,) `NumPy `_ array of point coordinates :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param integer `Diameter`: the points diameter :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self, InForeground) @@ -1027,9 +1027,9 @@ class PointSet(PointsObjectMixin, ColorOnlyMixin, DrawObject): def SetDiameter(self, Diameter): """ Sets the diameter - + :param integer `Diameter`: the points diameter - + """ self.Diameter = Diameter @@ -1042,7 +1042,7 @@ class PointSet(PointsObjectMixin, ColorOnlyMixin, DrawObject): This can be used to figure out which point got hit in a mouse binding callback, for instance. It's a lot faster that using a lot of separate points. - + :param `XY`: the (x,y) coordinates of the point to look for, it takes a 2-tuple or (2,) numpy array in World coordinates @@ -1097,7 +1097,7 @@ class Point(XYObjectMixin, ColorOnlyMixin, DrawObject): A point DrawObject .. note:: - + The Bounding box is just the point, and doesn't include the Diameter. The HitLineWidth is used as diameter for the Hit Test. @@ -1106,15 +1106,15 @@ class Point(XYObjectMixin, ColorOnlyMixin, DrawObject): def __init__(self, XY, Color="Black", Diameter=1, InForeground=False): """ Default class constructor. - + :param `XY`: the (x, y) coordinate of the center of the point, or a 2-tuple, or a (2,) `NumPy `_ array :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param integer `Diameter`: in screen points :param `InForeground`: define if object is in foreground - + """ - + DrawObject.__init__(self, InForeground) self.XY = N.array(XY, N.float) @@ -1128,9 +1128,9 @@ class Point(XYObjectMixin, ColorOnlyMixin, DrawObject): def SetDiameter(self, Diameter): """ Set the diameter of the object. - + :param integer `Diameter`: in screen points - + """ self.Diameter = Diameter @@ -1164,13 +1164,13 @@ class SquarePoint(XYObjectMixin, ColorOnlyMixin, DrawObject): def __init__(self, Point, Color="Black", Size=4, InForeground=False): """ Default class constructor. - + :param `Point`: takes a 2-tuple, or a (2,) `NumPy `_ array of point coordinates :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param integer `Size`: the size of the square point :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self, InForeground) @@ -1185,9 +1185,9 @@ class SquarePoint(XYObjectMixin, ColorOnlyMixin, DrawObject): def SetSize(self, Size): """ Sets the size - + :param integer `Size`: the size of the square point - + """ self.Size = Size @@ -1222,7 +1222,7 @@ class RectEllipse(XYObjectMixin, LineAndFillMixin, DrawObject): InForeground = False): """ Default class constructor. - + :param `XY`: the (x, y) coordinate of the corner of RectEllipse, or a 2-tuple, or a (2,) `NumPy `_ array :param `WH`: a tuple with the Width and Height for the object @@ -1232,7 +1232,7 @@ class RectEllipse(XYObjectMixin, LineAndFillMixin, DrawObject): :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle` :param `InForeground`: put object in foreground - + """ DrawObject.__init__(self,InForeground) @@ -1256,11 +1256,11 @@ class RectEllipse(XYObjectMixin, LineAndFillMixin, DrawObject): def SetShape(self, XY, WH): """ Set the shape of the object. - + :param `XY`: takes a 2-tuple, or a (2,) `NumPy `_ array of point coordinates :param `WH`: a tuple with the Width and Height for the object - + """ self.XY = N.array( XY, N.float) self.XY.shape = (2,) @@ -1306,7 +1306,7 @@ class Ellipse(RectEllipse): class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): """Draws a circle""" - def __init__(self, XY, Diameter, + def __init__(self, XY, Diameter, LineColor = "Black", LineStyle = "Solid", LineWidth = 1, @@ -1315,7 +1315,7 @@ class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): InForeground = False): """ Default class constructor. - + :param `XY`: the (x, y) coordinate of the center of the circle, or a 2-tuple, or a (2,) `NumPy `_ array :param integer `Diameter`: the diameter for the object @@ -1325,7 +1325,7 @@ class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle` :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self, InForeground) @@ -1351,9 +1351,9 @@ class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): def SetDiameter(self, Diameter): """ Set the diameter of the object - + :param integer `Diameter`: the diameter for the object - + """ self.WH = N.array((Diameter/2, Diameter/2), N.float) # just to keep it compatible with others @@ -1369,7 +1369,7 @@ class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): WorldToPixel, ScaleWorldToPixel, HTdc) - + WH[N.abs(WH) < self.MinSize] = self.MinSize if not( self.DisappearWhenSmall and N.abs(WH).min() <= self.MinSize) : # don't try to draw it too tiny dc.DrawCircle(XY, WH[0]) @@ -1400,7 +1400,7 @@ class TextObjectMixin(XYObjectMixin): Underlined, FaceName), #wx.FontFromPixelSize((0.45*Size,Size), # this seemed to give a decent height/width ratio on Windows - wx.Font(Size, + wx.Font(Size, Family, Style, Weight, @@ -1453,7 +1453,7 @@ class TextObjectMixin(XYObjectMixin): class Text(TextObjectMixin, DrawObject): """ Draws a text object - + The size is fixed, and does not scale with the drawing. The hit-test is done on the entire text extent @@ -1473,7 +1473,7 @@ class Text(TextObjectMixin, DrawObject): Font = None): """ Default class constructor. - + :param string `string`: the text to draw :param `XY`: the (x, y) coordinate of the corner of the text, or a 2-tuple, or a (2,) `NumPy `_ array @@ -1489,7 +1489,7 @@ class Text(TextObjectMixin, DrawObject): :param boolean `InForeground`: should object be in foreground :param wx.Font `Font`: alternatively you can define :ref:`wx.Font` and the above will be ignored. - + ============== ========================== 1st character Meaning ============== ========================== @@ -1508,7 +1508,7 @@ class Text(TextObjectMixin, DrawObject): :param wx.Font `Font`: a valid :class:`wx.Font` :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self,InForeground) @@ -1560,7 +1560,7 @@ class Text(TextObjectMixin, DrawObject): class ScaledText(TextObjectMixin, DrawObject): """ ##fixme: this can be depricated and jsut use ScaledTextBox with different defaults. - + This class creates a text object that is scaled when zoomed. It is placed at the coordinates, x,y. the "Position" argument is a two charactor string, indicating where in relation to the coordinates @@ -1575,16 +1575,16 @@ class ScaledText(TextObjectMixin, DrawObject): * Family: Font family, a generic way of referring to fonts without specifying actual facename. One of: - + * wx.FONTFAMILY_DEFAULT: Chooses a default font. * wx.FONTFAMILY_DECORATIVE: A decorative font. * wx.FONTFAMILY_ROMAN: A formal, serif font. * wx.FONTFAMILY_SCRIPT: A handwriting font. * wx.FONTFAMILY_SWISS: A sans-serif font. * wx.FONTFAMILY_MODERN: A fixed pitch font. - + .. note:: these are only as good as the wxWindows defaults, which aren't so good. - + * Style: One of wx.FONTSTYLE_NORMAL, wx.FONTSTYLE_SLANT and wx.FONTSTYLE_ITALIC. * Weight: One of wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_LIGHT and wx.FONTWEIGHT_BOLD. * Underlined: The value can be True or False. At present this may have an an @@ -1724,7 +1724,7 @@ class ScaledText(TextObjectMixin, DrawObject): class ScaledTextBox(TextObjectMixin, DrawObject): """ Draws a text object - + The object is scaled when zoomed. The hit-test is done on the entire text extent @@ -1766,7 +1766,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): InForeground = False): """ Default class constructor. - + :param `Point`: takes a 2-tuple, or a (2,) `NumPy `_ array of point coordinates :param integer `Size`: size in World units @@ -1774,7 +1774,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): :param `BackgroundColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth` - :param `Width`: width in pixels or ``None``, text will be wrapped to + :param `Width`: width in pixels or ``None``, text will be wrapped to the given width. :param `PadSize`: padding in world units or ``None``, if specified it will creating a space (margin) around the text @@ -1784,7 +1784,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): :param boolean `Underlined`: underline the text :param string `Position`: a two character string indicating where in relation to the coordinates the box should be oriented - + ============== ========================== 1st character Meaning ============== ========================== @@ -1806,7 +1806,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): in which case the above will be ignored :param float `LineSpacing`: the line space to be used :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self,InForeground) @@ -1998,7 +1998,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): ## If so, limit it. Would it be better just to not draw it? ## note that this limit is dependent on how much memory you have, etc. Size = min(Size, self.MaxFontSize) - + Size = max(Size, self.MinFontSize) # smallest size you want - default to 1 # Draw The Box @@ -2034,13 +2034,13 @@ class Bitmap(TextObjectMixin, DrawObject): InForeground=False): """ Default class constructor. - + :param wx.Bitmap `Bitmap`: the bitmap to be drawn :param `XY`: the (x, y) coordinate of the corner of the bitmap, or a 2-tuple, or a (2,) `NumPy `_ array :param string `Position`: a two character string indicating where in relation to the coordinates the bitmap should be oriented - + ============== ========================== 1st character Meaning ============== ========================== @@ -2056,9 +2056,9 @@ class Bitmap(TextObjectMixin, DrawObject): ``c`` center ``r`` right ============== ========================== - + :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self,InForeground) @@ -2101,14 +2101,14 @@ class ScaledBitmap(TextObjectMixin, DrawObject): InForeground = False): """ Default class constructor. - + :param wx.Bitmap `Bitmap`: the bitmap to be drawn :param `XY`: the (x, y) coordinate of the corner of the scaled bitmap, or a 2-tuple, or a (2,) `NumPy `_ array :param `Height`: height to be used, width is calculated from the aspect ratio of the bitmap :param string `Position`: a two character string indicating where in relation to the coordinates the bitmap should be oriented - + ============== ========================== 1st character Meaning ============== ========================== @@ -2124,9 +2124,9 @@ class ScaledBitmap(TextObjectMixin, DrawObject): ``c`` center ``r`` right ============== ========================== - + :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self,InForeground) @@ -2187,7 +2187,7 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): InForeground = False): """ Default class constructor. - + :param wx.Bitmap `Bitmap`: the bitmap to be drawn :param `XY`: the (x, y) coordinate of the corner of the scaled bitmap, or a 2-tuple, or a (2,) `NumPy `_ array @@ -2195,7 +2195,7 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): :param `Width`: width to be used, if ``None`` width is calculated from the aspect ratio of the bitmap :param string `Position`: a two character string indicating where in relation to the coordinates the bitmap should be oriented - + ============== ========================== 1st character Meaning ============== ========================== @@ -2211,9 +2211,9 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): ``c`` center ``r`` right ============== ========================== - + :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self,InForeground) @@ -2373,16 +2373,16 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): class DotGrid: """ - An example of a Grid Object -- it is set on the FloatCanvas with one of:: - + An example of a Grid Object -- it is set on the FloatCanvas with one of:: + FloatCanvas.GridUnder = Grid FloatCanvas.GridOver = Grid - + It will be drawn every time, regardless of the viewport. - + In its _Draw method, it computes what to draw, given the ViewPortBB of the Canvas it's being drawn on. - + """ def __init__(self, Spacing, Size = 2, Color = "Black", Cross=False, CrossThickness = 1): @@ -2467,10 +2467,10 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): LineWidth = 1, FillColor = None, FillStyle = "Solid", - InForeground = False): + InForeground = False): """ Default class constructor. - + :param `StartXY`: start point, takes a 2-tuple, or a (2,) `NumPy `_ array of point coordinates :param `EndXY`: end point, takes a 2-tuple, or a (2,) @@ -2483,11 +2483,11 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle` :param boolean `InForeground`: should object be in foreground - + """ DrawObject.__init__(self, InForeground) - + # There is probably a more elegant way to do this next section # The bounding box just gets set to the WH of a circle, with center at CenterXY # This is suitable for a pie chart as it will be a circle anyway @@ -2495,7 +2495,7 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): minX = CenterXY[0]-radius minY = CenterXY[1]-radius maxX = CenterXY[0]+radius - maxY = CenterXY[1]+radius + maxY = CenterXY[1]+radius XY = [minX,minY] WH = [maxX-minX,maxY-minY] @@ -2508,8 +2508,8 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): #self.BoundingBox = array((self.XY, (self.XY + self.WH)), Float) self.CalcBoundingBox() - - #Finish the setup; allocate color,style etc. + + #Finish the setup; allocate color,style etc. self.LineColor = LineColor self.LineStyle = LineStyle self.LineWidth = LineWidth @@ -2524,7 +2524,7 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): def Move(self, Delta): """ Move the object by delta - + :param `Delta`: delta is a (dx, dy) pair. Ideally a `NumPy `_ array of shape (2,) @@ -2539,13 +2539,13 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): if self._Canvas: self._Canvas.BoundingBoxDirty = True - + def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None): self.SetUpDraw(dc , WorldToPixel, ScaleWorldToPixel, HTdc) StartXY = WorldToPixel(self.StartXY) EndXY = WorldToPixel(self.EndXY) CenterXY = WorldToPixel(self.CenterXY) - + dc.DrawArc(StartXY, EndXY, CenterXY) if HTdc and self.HitAble: HTdc.DrawArc(StartXY, EndXY, CenterXY) @@ -2561,12 +2561,12 @@ class Arc(XYObjectMixin, LineAndFillMixin, 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. """ - + ##fixme: this should be a longer and better designed set. ## Maybe one from: http://geography.uoregon.edu/datagraphics/color_scales.htm DefaultColorList = Colors.CategoricalColor1 @@ -2582,10 +2582,10 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): LineStyle = "Solid", LineWidth = 1, Scaled = True, - InForeground = False): + InForeground = False): """ Default class constructor. - + :param `XY`: The (x,y) coords of the center of the chart :param `Diameter`: The diamter of the chart in worls coords, unless you set "Scaled" to False, in which case it's in pixel coords. @@ -2598,7 +2598,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): :param `LineWidth`: With of lines separating the slices :param `Scaled`: Do you want the pie to scale when zooming? or stay the same size in pixels? - :param `InForeground`: Should it be on the foreground? + :param `InForeground`: Should it be on the foreground? """ DrawObject.__init__(self, InForeground) @@ -2616,7 +2616,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): self.Scaled = Scaled self.InForeground = InForeground - + self.SetPen(LineColor, LineStyle, LineWidth) self.SetBrushes() self.CalculatePoints() @@ -2624,7 +2624,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): def SetFillColors(self, FillColors): """ Set the FillColors and update the Brushes. - + :param `FillColors`: sequence of colors """ self.FillColors = FillColors @@ -2633,7 +2633,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): def SetFillStyles(self, FillStyles): """ Set te FillStyles and update the Brushes. - + :param `FillStyles`: Fill style you want ("Solid", "Hash", etc) """ self.FillStyles = FillStyles @@ -2642,7 +2642,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): def SetValues(self, Values): """ Set the values and calculate the points. - + :param `Values`: sequence of values you want to use for the chart """ Values = N.asarray(Values, dtype=N.float).reshape((-1,1)) @@ -2655,7 +2655,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): Values = N.vstack( ( (0,), self.Values) ) self.Angles = 360. * Values.cumsum()/Values.sum() self.CalcBoundingBox() - + def SetBrushes(self): """Set the Brushes.""" self.Brushes = [] @@ -2698,24 +2698,24 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): HTdc.DrawCircle(CenterXY, radius) -class Group(DrawObject): +class Group(DrawObject): """ A group of other FloatCanvas Objects - + Not all DrawObject methods may apply here. - + Note that if an object is in more than one group, it will get drawn more than once. - + """ def __init__(self, ObjectList=[], InForeground=False, IsVisible=True): """ Default class constructor. - + :param list `ObjectList`: a list of :class:`DrawObject` to be grouped :param boolean `InForeground`: keep in foreground :param boolean `IsVisible`: keep it visible - + """ self.ObjectList = [] DrawObject.__init__(self, InForeground, IsVisible) @@ -2748,9 +2748,9 @@ class Group(DrawObject): def AddObject(self, obj): """ Add an object to the group. - + :param DrawObject `obj`: object to add - + """ self.ObjectList.append(obj) self.BoundingBox.Merge(obj.BoundingBox) @@ -2758,13 +2758,13 @@ class Group(DrawObject): def AddObjects(self, Objects): """ Add objects to the group. - + :param list `Objects`: a list of :class:`DrawObject` to be grouped - + """ for o in Objects: self.AddObject(o) - + def CalcBoundingBox(self): """Calculate the bounding box.""" if self.ObjectList: @@ -2778,10 +2778,10 @@ class Group(DrawObject): def SetColor(self, Color): """ Set the Color - + :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid values - + """ for o in self.ObjectList: o.SetColor(Color) @@ -2789,10 +2789,10 @@ class Group(DrawObject): def SetLineColor(self, Color): """ Set the LineColor - + :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid values - + """ for o in self.ObjectList: o.SetLineColor(Color) @@ -2800,10 +2800,10 @@ class Group(DrawObject): def SetLineStyle(self, LineStyle): """ Set the LineStyle - + :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle` for valid values - + """ for o in self.ObjectList: o.SetLineStyle(LineStyle) @@ -2811,9 +2811,9 @@ class Group(DrawObject): def SetLineWidth(self, LineWidth): """ Set the LineWidth - + :param integer `LineWidth`: line width in pixels - + """ for o in self.ObjectList: o.SetLineWidth(LineWidth) @@ -2821,10 +2821,10 @@ class Group(DrawObject): def SetFillColor(self, Color): """ Set the FillColor - + :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor` for valid values - + """ for o in self.ObjectList: o.SetFillColor(Color) @@ -2832,10 +2832,10 @@ class Group(DrawObject): def SetFillStyle(self, FillStyle): """ Set the FillStyle - + :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle` for valid values - + """ for o in self.ObjectList: o.SetFillStyle(FillStyle) @@ -2843,8 +2843,8 @@ class Group(DrawObject): def Move(self, Delta): """ Moves the object by delta, where delta is a (dx, dy) pair. - - :param `Delta`: is a (dx, dy) pair ideally a `NumPy `_ + + :param `Delta`: is a (dx, dy) pair ideally a `NumPy `_ array of shape (2, ) """ @@ -2855,7 +2855,7 @@ class Group(DrawObject): def Bind(self, Event, CallBackFun): """ Bind an event to the Group object - + :param `Event`: see below for supported event types - EVT_FC_LEFT_DOWN @@ -2872,7 +2872,7 @@ class Group(DrawObject): :param `CallBackFun`: the call back function for the event - + """ ## slight variation on DrawObject Bind Method: ## fixme: There is a lot of repeated code from the DrawObject method, but @@ -2887,7 +2887,7 @@ class Group(DrawObject): if not self.HitColor: if not self._Canvas.HitColorGenerator: self._Canvas.HitColorGenerator = _colorGenerator() - # first call to prevent the background color from being used. + # first call to prevent the background color from being used. if six.PY2: self._Canvas.HitColorGenerator.next() else: @@ -2908,7 +2908,7 @@ class Group(DrawObject): obj.SetHitPen(self.HitColor, self.HitLineWidth) obj.SetHitBrush(self.HitColor) obj.HitAble = True - + if isinstance(obj, Group): self._ChangeChildrenHitColor(obj.ObjectList) diff --git a/wx/lib/floatcanvas/FloatCanvas.py b/wx/lib/floatcanvas/FloatCanvas.py index c627d690..60b4aa1a 100644 --- a/wx/lib/floatcanvas/FloatCanvas.py +++ b/wx/lib/floatcanvas/FloatCanvas.py @@ -25,16 +25,16 @@ container type control:: Debug=0, BackgroundColor="White", ) - + # add a circle cir = FloatCanvas.Circle((10, 10), 100) self.Canvas.AddObject(cir) - + # add a rectangle rect = FloatCanvas.Rectangle((110, 10), (100, 100), FillColor='Red') self.Canvas.AddObject(rect) - + self.Canvas.Draw() @@ -46,7 +46,7 @@ from __future__ import division import sys mac = sys.platform.startswith("darwin") - + import numpy as N from time import clock import wx @@ -107,7 +107,7 @@ class _MouseEvent(wx.PyCommandEvent): class FloatCanvas(wx.Panel): """ The main class of the floatcanvas package :class:`~lib.floatcanvas.FloatCanvas`. - + """ def __init__(self, parent, id = -1, @@ -124,7 +124,7 @@ class FloatCanvas(wx.Panel): :param integer `id`: window identifier. A value of -1 indicates a default value; :param `size`: a tuple or :class:`wx.Size` :param `ProjectionFun`: This allows you to change the transform from - world to pixel coordinates. We can point to :meth:`~lib.floatcanvas.FloatCanvas.FloatCanvas.FlatEarthProjection` + world to pixel coordinates. We can point to :meth:`~lib.floatcanvas.FloatCanvas.FloatCanvas.FlatEarthProjection` for an example -- though that should really be a class method, or even better, simply a function in the module. There is a tiny bit on info in the error message in FloatCanvas.SetProjectionFun() @@ -132,7 +132,7 @@ class FloatCanvas(wx.Panel): (Note: this really should get re-factored to allow more generic projections...) :param string `BackgroundColor`: any value accepted by :class:`wx.Brush` - :param `Debug`: activate debug, currently it prints some debugging + :param `Debug`: activate debug, currently it prints some debugging information, could be improved. """ @@ -167,9 +167,9 @@ class FloatCanvas(wx.Panel): ## CHB: I'm leaving these out for now. #self.Bind(wx.EVT_ENTER_WINDOW, self. ) #self.Bind(wx.EVT_LEAVE_WINDOW, self. ) - + self.SetProjectionFun(ProjectionFun) - + self.GUIMode = None # making sure the arrribute exists self.SetMode(GUIMode.GUIMouse()) # make the default Mouse Mode. @@ -181,7 +181,7 @@ class FloatCanvas(wx.Panel): # self.CreateCursors() - + def InitAll(self): """ Sets everything in the Canvas to default state. @@ -225,11 +225,11 @@ class FloatCanvas(wx.Panel): def SetProjectionFun(self, ProjectionFun): """ Set a custom projection function - + :param `ProjectionFun`: valid entries are ``FlatEarth``, ``None`` or a callable object that takes the ``ViewPortCenter`` and returns ``MapProjectionVector`` - + """ if ProjectionFun == 'FlatEarth': self.ProjectionFun = self.FlatEarthProjection @@ -247,7 +247,7 @@ class FloatCanvas(wx.Panel): """ Compute the scaling array for the flat-earth projection - :param `CenterPoint`: center point of viewport (lon, lat) -- the + :param `CenterPoint`: center point of viewport (lon, lat) -- the longitude is scaled to the latitude of this point. a 2-tuple, or a (2,) `NumPy `_ array of point coordinates @@ -264,7 +264,7 @@ class FloatCanvas(wx.Panel): def SetMode(self, Mode): """ Set the GUImode to any of the available mode. - + :param `Mode`: a valid GUI Mode, out of the box valid modes are subclassed from :class:`~lib.floatcanvas.GUIMode.GUIBase` or a mode can also be user defined. @@ -306,7 +306,7 @@ class FloatCanvas(wx.Panel): def GetHitTestColor(self, xy): """ Get the hit test colour - + :param `xy`: the position to get the hit test colour for """ if self._ForegroundHTBitmap: @@ -324,7 +324,7 @@ class FloatCanvas(wx.Panel): def GetHitTestColor(self, xy ): """ Get the hit test colour - + :param `xy`: the position to get the hit test colour for """ dc = wx.MemoryDC() @@ -338,7 +338,7 @@ class FloatCanvas(wx.Panel): def UnBindAll(self): """Removes all bindings to Objects.""" self.HitDict = None - + def _CallHitCallback(self, Object, xy, HitEvent): """ A little book keeping to be done when a callback is called. @@ -483,7 +483,7 @@ class FloatCanvas(wx.Panel): if self.GUIMode: self.GUIMode.OnRightUp(event) event.Skip() - + def KeyDownEvent(self, event): """Key down event.""" if self.GUIMode: @@ -521,7 +521,7 @@ class FloatCanvas(wx.Panel): def MakeNewHTBitmap(self): """ Off screen Bitmap used for Hit tests on background objects - + """ self._HTBitmap = wx.Bitmap(self.PanelSize[0], self.PanelSize[1], @@ -533,7 +533,7 @@ class FloatCanvas(wx.Panel): ## added after the backgound is drawn """ Off screen Bitmap used for Hit tests on foreground objects - + """ self._ForegroundHTBitmap = wx.Bitmap(self.PanelSize[0], self.PanelSize[1], @@ -569,7 +569,7 @@ class FloatCanvas(wx.Panel): # self.GUIMode.DrawOnTop(dc) #except AttributeError: # pass - + def Draw(self, Force=False): """ @@ -662,14 +662,14 @@ class FloatCanvas(wx.Panel): print("Drawing took %f seconds of CPU time"%(clock()-start)) if self._HTBitmap is not None: self._HTBitmap.SaveFile('junk.png', wx.BITMAP_TYPE_PNG) - + ## Clear the font cache. If you don't do this, the X font server ## starts to take up Massive amounts of memory This is mostly a ## problem with very large fonts, that you get with scaled text ## when zoomed in. DrawObject.FontList = {} - def _ShouldRedraw(DrawList, ViewPortBB): + def _ShouldRedraw(DrawList, ViewPortBB): # lrk: Returns the objects that should be redrawn ## fixme: should this check be moved into the object? BB2 = ViewPortBB @@ -684,15 +684,15 @@ class FloatCanvas(wx.Panel): """ Move the image in the window. - :param tuple `shift`: is an (x, y) tuple defining amount to shift in + :param tuple `shift`: is an (x, y) tuple defining amount to shift in each direction :param string `CoordType`: defines what coordinates to use, valid entries are: - + ============== ====================================================== Coordtype Description ============== ====================================================== - `Panel` shift the image by some fraction of the size of the + `Panel` shift the image by some fraction of the size of the displayed image `Pixel` shift the image by some number of pixels `World` shift the image by an amount of floating point world @@ -728,35 +728,35 @@ class FloatCanvas(wx.Panel): :param center: a tuple of (x,y) coordinates of the center of the viewport, after zooming. If center is not given, the center will stay the same. - :param centerCoords: flag indicating whether the center given is in pixel or world + :param centerCoords: flag indicating whether the center given is in pixel or world coords. Options are: "world" or "pixel" :param keepPointInPlace: boolean flag. If False, the center point is what's given. If True, the image is shifted so that the given center point - is kept in the same pixel space. This facilitates keeping the + is kept in the same pixel space. This facilitates keeping the same point under the mouse when zooming with the scroll wheel. """ if center is None: center = self.ViewPortCenter centerCoords = 'World' #override input if they don't give a center point. - + if centerCoords == "Pixel": oldpoint = self.PixelToWorld( center ) else: oldpoint = N.array(center, N.float) - + self.Scale = self.Scale*factor if keepPointInPlace: self.SetToNewScale(False) - + if centerCoords == "Pixel": newpoint = self.PixelToWorld( center ) else: newpoint = N.array(center, N.float) delta = (newpoint - oldpoint) - self.MoveImage(-delta, 'World') + self.MoveImage(-delta, 'World') else: self.ViewPortCenter = oldpoint - self.SetToNewScale() + self.SetToNewScale() def ZoomToBB(self, NewBB=None, DrawFlag=True): @@ -801,9 +801,9 @@ class FloatCanvas(wx.Panel): def SetToNewScale(self, DrawFlag=True): """ Set to the new scale - + :param boolean `DrawFlag`: draw the canvas - + """ Scale = self.Scale if self.MinScale is not None: @@ -820,9 +820,9 @@ class FloatCanvas(wx.Panel): def RemoveObjects(self, Objects): """" Remove objects from canvas - + :param list `Objects`: a list of :class:`DrawObjects` to remove - + """ for Object in Objects: self.RemoveObject(Object, ResetBB=False) @@ -831,10 +831,10 @@ class FloatCanvas(wx.Panel): def RemoveObject(self, Object, ResetBB=True): """" Remove object from canvas - + :param DrawObject `Object`: a :class:`DrawObjects` to remove :param boolean `ResetBB`: reset the bounding box - + """ ##fixme: Using the list.remove method is kind of slow if Object.InForeground: @@ -937,11 +937,11 @@ class FloatCanvas(wx.Panel): def AddObject(self, obj): """ Add an object to the canvas - + :param DrawObject `obj`: the object to add - + :return: DrawObject - + """ # put in a reference to the Canvas, so remove and other stuff can work obj._Canvas = self @@ -957,9 +957,9 @@ class FloatCanvas(wx.Panel): def AddObjects(self, Objects): """ Add objects to the canvas - + :param list `Objects`: a list of :class:`DrawObject` - + """ for Object in Objects: self.AddObject(Object) @@ -967,7 +967,7 @@ class FloatCanvas(wx.Panel): def _DrawObjects(self, dc, DrawList, ScreenDC, ViewPortBB, HTdc=None): """ This is a convenience function; - + This function takes the list of objects and draws them to specified device context. """ @@ -987,7 +987,7 @@ class FloatCanvas(wx.Panel): def SaveAsImage(self, filename, ImageType=wx.BITMAP_TYPE_PNG): """ Saves the current image as an image file. - + :param string `filename`: the name of the image file :param `ImageType`: format to use, see :ref:`wx.BitmapType` and the note in :meth:`wx.Bitmap.SaveFile` diff --git a/wx/lib/floatcanvas/GUIMode.py b/wx/lib/floatcanvas/GUIMode.py index 2e666e2b..aabfe7de 100644 --- a/wx/lib/floatcanvas/GUIMode.py +++ b/wx/lib/floatcanvas/GUIMode.py @@ -31,18 +31,18 @@ from .Utilities import BBox class Cursors(object): """ Class to hold the standard Cursors - + """ def __init__(self): if "wxMac" in wx.PlatformInfo: # use 16X16 cursors for wxMac self.HandCursor = wx.Cursor(Resources.getHand16Image()) self.GrabHandCursor = wx.Cursor(Resources.getGrabHand16Image()) - + img = Resources.getMagPlus16Image() img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 6) img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 6) self.MagPlusCursor = wx.Cursor(img) - + img = Resources.getMagMinus16Image() img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 6) img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 6) @@ -50,12 +50,12 @@ class Cursors(object): else: # use 24X24 cursors for GTK and Windows self.HandCursor = wx.Cursor(Resources.getHandImage()) self.GrabHandCursor = wx.Cursor(Resources.getGrabHandImage()) - + img = Resources.getMagPlusImage() img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 9) img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 9) self.MagPlusCursor = wx.Cursor(img) - + img = Resources.getMagMinusImage() img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 9) img.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 9) @@ -74,7 +74,7 @@ class GUIBase(object): Default class constructor. :param `Canvas`: the canvas the GUI mode is attached too - + """ self.Canvas = Canvas # set the FloatCanvas for the mode # it gets set when the Mode is set on the Canvas. @@ -215,7 +215,7 @@ class GUIMove(ZoomWithMouseWheel, GUIBase): self.StartMove = None self.MidMove = None self.PrevMoveXY = None - + ## timer to give a delay when moving so that buffers aren't re-built too many times. self.MoveTimer = wx.PyTimer(self.OnMoveTimer) @@ -359,7 +359,7 @@ class GUIZoomIn(ZoomWithMouseWheel, GUIBase): dc.DrawRectangle(*self.PrevRBBox) self.PrevRBBox = ( xy_c - wh/2, wh ) dc.DrawRectangle( *self.PrevRBBox ) - + def UpdateScreen(self): """ Update gets called if the screen has been repainted in the middle of a zoom in @@ -384,7 +384,7 @@ class GUIZoomOut(ZoomWithMouseWheel, GUIBase): def __init__(self, Canvas=None): GUIBase.__init__(self, Canvas) self.Cursor = self.Cursors.MagMinusCursor - + def OnLeftDown(self, event): self.Canvas.Zoom(1/1.5, event.GetPosition(), centerCoords="pixel") diff --git a/wx/lib/floatcanvas/NavCanvas.py b/wx/lib/floatcanvas/NavCanvas.py index 2751d7e4..fdd06427 100644 --- a/wx/lib/floatcanvas/NavCanvas.py +++ b/wx/lib/floatcanvas/NavCanvas.py @@ -31,16 +31,16 @@ container type control:: # add a circle cir = FloatCanvas.Circle((10, 10), 100) self.Canvas.AddObject(cir) - + # add a rectangle rect = FloatCanvas.Rectangle((110, 10), (100, 100), FillColor='Red') self.Canvas.AddObject(rect) - + self.Canvas.Draw() - + Many samples are available in the `wxPhoenix/samples/floatcanvas` folder. - + """ @@ -52,7 +52,7 @@ class NavCanvas(wx.Panel): :class:`~lib.floatcanvas.NavCanvas.NavCanvas` encloses a :class:`~lib.floatcanvas.FloatCanvas.FloatCanvas` in a :class:`Panel` and adds a Navigation toolbar. - + """ def __init__(self, @@ -75,7 +75,7 @@ class NavCanvas(wx.Panel): ("Zoom Out", GUIMode.GUIZoomOut(), Resources.getMagMinusBitmap()), ("Pan", GUIMode.GUIMove(), Resources.getHandBitmap()), ] - + self.BuildToolbar() ## Create the vertical sizer for the toolbar and Panel box = wx.BoxSizer(wx.VERTICAL) @@ -105,16 +105,16 @@ class NavCanvas(wx.Panel): tb.Realize() ## fixme: remove this when the bug is fixed! #wx.CallAfter(self.HideShowHack) # this required on wxPython 2.8.3 on OS-X - + def AddToolbarModeButtons(self, tb, Modes): """ Add the mode buttons to the tool bar. - + :param ToolBar `tb`: the toolbar instance :param list `Modes`: a list of modes to add, out of the box valid modes are subclassed from :class:`~lib.floatcanvas.GUIMode.GUIBase` or modes can also be user defined. - + """ self.ModesDict = {} for Mode in Modes: @@ -129,9 +129,9 @@ class NavCanvas(wx.Panel): def AddToolbarZoomButton(self, tb): """ Add the zoom button to the tool bar. - + :param ToolBar `tb`: the toolbar instance - + """ tb.AddSeparator() diff --git a/wx/lib/floatcanvas/Utilities/BBox.py b/wx/lib/floatcanvas/Utilities/BBox.py index 89f774ab..a20f94ce 100755 --- a/wx/lib/floatcanvas/Utilities/BBox.py +++ b/wx/lib/floatcanvas/Utilities/BBox.py @@ -20,8 +20,8 @@ import numpy as N class BBox(N.ndarray): """ A Bounding Box object: - - Takes Data as an array. Data is any python sequence that can be turned into a + + Takes Data as an array. Data is any python sequence that can be turned into a 2x2 numpy array of floats:: [ @@ -29,17 +29,17 @@ class BBox(N.ndarray): [MaxX, MaxY ] ] - It is a subclass of numpy.ndarray, so for the most part it can be used as + It is a subclass of numpy.ndarray, so for the most part it can be used as an array, and arrays that fit the above description can be used in its place. - + Usually created by the factory functions: - + asBBox - - and - + + and + fromPoints - + """ def __new__(subtype, data): """ @@ -53,11 +53,11 @@ class BBox(N.ndarray): You don't usually call this directly. BBox objects are created with the factory functions: - + asBBox - - and - + + and + fromPoints """ @@ -101,7 +101,7 @@ class BBox(N.ndarray): return True else: return False - + def PointInside(self, Point): """ Inside(BB): @@ -112,7 +112,7 @@ class BBox(N.ndarray): border. Returns False otherwise - + Point is any length-2 sequence (tuple, list, array) or two numbers """ if Point[0] >= self[0,0] and \ @@ -122,12 +122,12 @@ class BBox(N.ndarray): return True else: return False - + def Merge(self, BB): """ Joins this bounding box with the one passed in, maybe making this one bigger - """ + """ if self.IsNull(): self[:] = BB elif N.isnan(BB).all(): ## BB may be a regular array, so I can't use IsNull @@ -137,9 +137,9 @@ class BBox(N.ndarray): if BB[0,1] < self[0,1]: self[0,1] = BB[0,1] if BB[1,0] > self[1,0]: self[1,0] = BB[1,0] if BB[1,1] > self[1,1]: self[1,1] = BB[1,1] - + return None - + def IsNull(self): return N.isnan(self).all() @@ -164,7 +164,7 @@ class BBox(N.ndarray): def _getHeight(self): return self[1,1] - self[0,1] Height = property(_getHeight) - + def _getCenter(self): return self.sum(0) / 2.0 Center = property(_getCenter) @@ -191,8 +191,8 @@ class BBox(N.ndarray): return True else: return self.Array__eq__(BB).all() - - + + def asBBox(data): """ returns a BBox object. @@ -207,7 +207,7 @@ def asBBox(data): [MinX, MinY ], [MaxX, MaxY ] ] - + """ if isinstance(data, BBox): @@ -223,7 +223,7 @@ def fromPoints(Points): be any python object that can be turned into a numpy NX2 array of Floats. If a single point is passed in, a zero-size Bounding Box is returned. - + """ Points = N.asarray(Points, N.float).reshape(-1,2) @@ -232,30 +232,30 @@ def fromPoints(Points): def fromBBArray(BBarray): """ - Builds a BBox object from an array of Bounding Boxes. + Builds a BBox object from an array of Bounding Boxes. The resulting Bounding Box encompases all the included BBs. - + The BBarray is in the shape: (Nx2x2) where BBarray[n] is a 2x2 array that represents a BBox """ - + #upperleft = N.minimum.reduce(BBarray[:,0]) #lowerright = N.maximum.reduce(BBarray[:,1]) - + # BBarray = N.asarray(BBarray, N.float).reshape(-1,2) # arr = N.vstack( (BBarray.min(0), BBarray.max(0)) ) BBarray = N.asarray(BBarray, N.float).reshape(-1,2,2) arr = N.vstack( (BBarray[:,0,:].min(0), BBarray[:,1,:].max(0)) ) return asBBox(arr) #return asBBox( (upperleft, lowerright) ) * 2 - + def NullBBox(): """ Returns a BBox object with all NaN entries. - + This represents a Null BB box; - + BB merged with it will return BB. - + Nothing is inside it. """ @@ -275,11 +275,11 @@ def InfBBox(): class RectBBox(BBox): """ subclass of a BBox that can be used for a rotated Rectangle - + contributed by MArco Oster (marco.oster@bioquant.uni-heidelberg.de) """ - + def __new__(self, data, edges=None): return BBox.__new__(self, data) @@ -310,4 +310,4 @@ class RectBBox(BBox): continue else: return False - return True + return True diff --git a/wx/lib/floatcanvas/Utilities/Colors.py b/wx/lib/floatcanvas/Utilities/Colors.py index de1f328e..0f866db7 100755 --- a/wx/lib/floatcanvas/Utilities/Colors.py +++ b/wx/lib/floatcanvas/Utilities/Colors.py @@ -22,12 +22,12 @@ http://geography.uoregon.edu/datagraphics/color_scales.htm They may have been modified some CategoricalColor1: A list of colors that are distict. -BlueToRed11: 11 colors from blue to red +BlueToRed11: 11 colors from blue to red """ -## Categorical 12-step scheme, after ColorBrewer 11-step Paired Scheme +## Categorical 12-step scheme, after ColorBrewer 11-step Paired Scheme ## From: http://geography.uoregon.edu/datagraphics/color_scales.htm # CategoricalColor1 = [ (255, 191, 127), # (255, 127, 0), @@ -58,16 +58,16 @@ CategoricalColor1 = [ (229, 25, 50), ] RedToBlue11 = [ (165, 0, 33), - (216, 38, 50), - (247, 109, 94), - (255, 173, 114), - (255, 224, 153), - (255, 255, 191), - (224, 255, 255), - (170, 247, 255), - (114, 216, 255), - ( 63, 160, 255), - ( 38, 76, 255), + (216, 38, 50), + (247, 109, 94), + (255, 173, 114), + (255, 224, 153), + (255, 255, 191), + (224, 255, 255), + (170, 247, 255), + (114, 216, 255), + ( 63, 160, 255), + ( 38, 76, 255), ] BlueToDarkRed12 = [( 41, 10, 216), diff --git a/wx/lib/floatcanvas/Utilities/GUI.py b/wx/lib/floatcanvas/Utilities/GUI.py index c266c357..68998a63 100644 --- a/wx/lib/floatcanvas/Utilities/GUI.py +++ b/wx/lib/floatcanvas/Utilities/GUI.py @@ -22,7 +22,7 @@ So far, they are: RubberBandBox: used to draw a RubberBand Box on the screen """ - + import numpy as np import wx @@ -50,7 +50,7 @@ class RubberBandBox(GUIMode.GUIBase): self.Canvas = None # this will be set when the mode is set on a Canvas self.CallBack = CallBack self.Tol = Tol - + self.Drawing = False self.RBRect = None self.StartPointWorld = None @@ -73,12 +73,12 @@ class RubberBandBox(GUIMode.GUIBase): self.RBRect = ((x, y), (w, h) ) dc.DrawRectangle(*self.RBRect) self.Canvas._RaiseMouseEvent(event,FloatCanvas.EVT_FC_MOTION) - + def OnLeftDown(self, event): # Start drawing self.Drawing = True self.StartPoint = event.GetPosition() - + def OnLeftUp(self, event): # Stop Drawing if self.Drawing: diff --git a/wx/lib/floatcanvas/__init__.py b/wx/lib/floatcanvas/__init__.py index 6a73d7c6..f439fc2f 100644 --- a/wx/lib/floatcanvas/__init__.py +++ b/wx/lib/floatcanvas/__init__.py @@ -1,6 +1,6 @@ #---------------------------------------------------------------------------- # Name: __init__.py -# Purpose: The FloatCanvas package +# Purpose: The FloatCanvas package # # Author: # @@ -11,7 +11,7 @@ # Tags: phoenix-port, unittest, documented, py3-port #---------------------------------------------------------------------------- """ -This is the floatcanvas package, the main classes are +This is the floatcanvas package, the main classes are :class:`~lib.floatcanvas.FloatCanvas` and :class:`~lib.floatcanvas.NavCanvas`, in each class documentation there is at least one sample on how to use them and many more samples are provided @@ -46,7 +46,7 @@ It is double buffered, so re-draws after the window is uncovered by something else are very quick. It relies on `NumPy `_, which is needed for speed -(maybe, I haven't profiled properly) and convenience. +(maybe, I haven't profiled properly) and convenience. Bugs and Limitations: Lots: patches, fixes welcome