mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-07-21 12:41:10 +02:00
Trim Whitespace floatcanvas directory
This commit is contained in:
@@ -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:
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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 <http://www.numpy.org/>`_ 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`
|
||||
|
@@ -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")
|
||||
|
||||
|
@@ -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()
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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),
|
||||
|
@@ -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:
|
||||
|
@@ -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 <http://www.numpy.org/>`_, 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
|
||||
|
||||
|
Reference in New Issue
Block a user