phoenix_title wx.lib.floatcanvas.FloatCanvas.FloatCanvas

The main class of the floatcanvas package FloatCanvas.


class_hierarchy Class Hierarchy

Inheritance diagram for class FloatCanvas:

super_classes Known Superclasses

wx.Panel


method_summary Methods Summary

__init__

Default class constructor.

AddObject

Add an object to the canvas

AddObjects

Add objects to the canvas

addshape

Creates Circle and adds its reference to the canvas.

ClearAll

ClearAll(ResetBB=True)

Draw

Canvas.Draw(Force=False)

FlatEarthProjection

Compute the scaling array for the flat-earth projection

GetHitTestColor

Get the hit test colour

HitTest

Check if any objects in the dict for this event.

InitAll

Sets everything in the Canvas to default state.

InitializePanel

Initialize the panel.

KeyDownEvent

Key down event.

KeyUpEvent

Key up event.

LeftDoubleClickEvent

Left double click event.

LeftDownEvent

Left down event.

LeftUpEvent

Left up event.

MakeHitDict

Initialize the Hit dictionary.

MakeNewBuffers

Make a new buffer.

MakeNewForegroundHTBitmap

Off screen Bitmap used for Hit tests on foreground objects

MakeNewHTBitmap

Off screen Bitmap used for Hit tests on background objects

MiddleDoubleClickEvent

Middle double click event.

MiddleDownEvent

Middle down event.

MiddleUpEvent

Middle up event.

MotionEvent

Motion event.

MouseOverTest

Check if mouse is over an object.

MoveImage

Move the image in the window.

OnPaint

On paint handler.

OnSize

On size handler.

OnSizeTimer

On size timer handler.

PixelToWorld

Converts coordinates from Pixel coordinates to world coordinates.

RemoveObject

RemoveObjects

RightDoubleCLickEvent

Right double click event.

RightDownEvent

Right down event.

RightUpEvent

Right up event.

SaveAsImage

Saves the current image as an image file.

ScalePixelToWorld

This function computes a pair of x.y lengths,

ScaleWorldToPixel

This function will get passed to the drawing functions of the objects,

SetMode

Set the GUImode to any of the available mode.

SetProjectionFun

Set a custom projection function

SetToNewScale

Set to the new scale

UnBindAll

Removes all bindings to Objects.

WheelEvent

Wheel event.

WorldToPixel

This function will get passed to the drawing functions of the objects,

Zoom

Zoom(factor, center) changes the amount of zoom of the image by factor.

ZoomToBB

Zooms the image to the bounding box given, or to the bounding


api Class API

class FloatCanvas(wx.Panel)

The main class of the floatcanvas package FloatCanvas.


Methods

__init__(self, parent, id = -1, size = wx.DefaultSize, ProjectionFun = None, BackgroundColor = "WHITE", Debug = False, **kwargs)

Default class constructor.

Parameters:
  • parent (wx.Window) – parent window. Must not be None;

  • id (integer) – window identifier. A value of -1 indicates a default value;

  • size – a tuple or wx.Size

  • ProjectionFun

    This allows you to change the transform from world to pixel coordinates. We can point to 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()

    (Note: this really should get re-factored to allow more generic projections…)

  • BackgroundColor (string) – any value accepted by wx.Brush

  • Debug – activate debug, currently it prints some debugging information, could be improved.



AddObject(self, obj)

Add an object to the canvas

Parameters:

obj (DrawObject) – the object to add

Returns:

DrawObject



AddObjects(self, Objects)

Add objects to the canvas

Parameters:

Objects (list) – a list of DrawObject



addshape(self, *args, **kwargs)

Creates Circle and adds its reference to the canvas. Argument protocol same as Circle class, whose docstring is: Draws a circle



ClearAll(self, ResetBB=True)

ClearAll(ResetBB=True)

Removes all DrawObjects from the Canvas

If ResetBB is set to False, the original bounding box will remain



Draw(self, Force=False)

Canvas.Draw(Force=False)

Re-draws the canvas.

Note that the buffer will not be re-drawn unless something has changed. If you change a DrawObject directly, then the canvas will not know anything has changed. In this case, you can force a re-draw by passing int True for the Force flag:

Canvas.Draw(Force=True)

There is a main buffer set up to double buffer the screen, so you can get quick re-draws when the window gets uncovered.

If there are any objects in self._ForeDrawList, then the background gets drawn to a new buffer, and the foreground objects get drawn on top of it. The final result if blitted to the screen, and stored for future Paint events. This is done so that you can have a complicated background, but have something changing on the foreground, without having to wait for the background to get re-drawn. This can be used to support simple animation, for instance.



FlatEarthProjection(self, CenterPoint)

Compute the scaling array for the flat-earth projection

Parameters:

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

:returnsa (2,) numpy array that scales world coordinates. This

scaling is applied when converting to-from world to pixel coordinates.



GetHitTestColor(self, xy)

Get the hit test colour

Parameters:

xy – the position to get the hit test colour for



HitTest(self, event, HitEvent)

Check if any objects in the dict for this event.



InitAll(self)

Sets everything in the Canvas to default state.

It can be used to reset the Canvas



InitializePanel(self)

Initialize the panel.



KeyDownEvent(self, event)

Key down event.



KeyUpEvent(self, event)

Key up event.



LeftDoubleClickEvent(self, event)

Left double click event.



LeftDownEvent(self, event)

Left down event.



LeftUpEvent(self, event)

Left up event.



MakeHitDict(self)

Initialize the Hit dictionary.



MakeNewBuffers(self)

Make a new buffer.



MakeNewForegroundHTBitmap(self)

Off screen Bitmap used for Hit tests on foreground objects



MakeNewHTBitmap(self)

Off screen Bitmap used for Hit tests on background objects



MiddleDoubleClickEvent(self, event)

Middle double click event.



MiddleDownEvent(self, event)

Middle down event.



MiddleUpEvent(self, event)

Middle up event.



MotionEvent(self, event)

Motion event.



MouseOverTest(self, event)

Check if mouse is over an object.



MoveImage(self, shift, CoordType, ReDraw=True)

Move the image in the window.

Parameters:
  • shift (tuple) – is an (x, y) tuple defining amount to shift in each direction

  • CoordType (string) –

    defines what coordinates to use, valid entries are:

    Coordtype

    Description

    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 coordinates



OnPaint(self, event)

On paint handler.



OnSize(self, event=None)

On size handler.



OnSizeTimer(self, event=None)

On size timer handler.



PixelToWorld(self, Points)

Converts coordinates from Pixel coordinates to world coordinates.

Points is a tuple of (x,y) coordinates, or a list of such tuples, or a NX2 Numpy array of x,y coordinates.



RemoveObject(self, Object, ResetBB=True)

” Remove object from canvas

Parameters:
  • Object (DrawObject) – a DrawObjects to remove

  • ResetBB (boolean) – reset the bounding box



RemoveObjects(self, Objects)

” Remove objects from canvas

Parameters:

Objects (list) – a list of DrawObjects to remove



RightDoubleCLickEvent(self, event)

Right double click event.



RightDownEvent(self, event)

Right down event.



RightUpEvent(self, event)

Right up event.



SaveAsImage(self, filename, ImageType=wx.BITMAP_TYPE_PNG)

Saves the current image as an image file.

Parameters:


ScalePixelToWorld(self, Lengths)

This function computes a pair of x.y lengths, to change then from pixel to world coordinates.

Lengths should be a NX2 array of (x,y) coordinates, or a 2-tuple, or sequence of 2-tuples.



ScaleWorldToPixel(self, Lengths)

This function will get passed to the drawing functions of the objects, to Change a length from world to pixel coordinates.

Lengths should be a NX2 array of (x,y) coordinates, or a 2-tuple, or sequence of 2-tuples.



SetMode(self, Mode)

Set the GUImode to any of the available mode.

Parameters:

Mode – a valid GUI Mode, out of the box valid modes are subclassed from GUIBase or a mode can also be user defined.



SetProjectionFun(self, ProjectionFun)

Set a custom projection function

Parameters:

ProjectionFun – valid entries are FlatEarth, None or a callable object that takes the ViewPortCenter and returns MapProjectionVector



SetToNewScale(self, DrawFlag=True)

Set to the new scale

Parameters:

DrawFlag (boolean) – draw the canvas



UnBindAll(self)

Removes all bindings to Objects.



WheelEvent(self, event)

Wheel event.



WorldToPixel(self, Coordinates)

This function will get passed to the drawing functions of the objects, to transform from world to pixel coordinates. Coordinates should be a NX2 array of (x,y) coordinates, or a 2-tuple, or sequence of 2-tuples.



Zoom(self, factor, center = None, centerCoords="World", keepPointInPlace=False)

Zoom(factor, center) changes the amount of zoom of the image by factor. If factor is greater than one, the image gets larger. If factor is less than one, the image gets smaller. :param factor: amount to zoom in or out If factor is greater than one,

the image gets larger. If factor is less than one, the image gets smaller.

Parameters:
  • 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.

  • centerCoords – flag indicating whether the center given is in pixel or world coords. Options are: “World” or “Pixel”

  • 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 same point under the mouse when zooming with the scroll wheel.



ZoomToBB(self, NewBB=None, DrawFlag=True)

Zooms the image to the bounding box given, or to the bounding box of all the objects on the canvas, if none is given.