.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc

.. currentmodule:: wx.lib.floatcanvas.FloatCanvas

.. highlight:: python



.. _wx.lib.floatcanvas.FloatCanvas.FloatCanvas:

==========================================================================================================================================
|phoenix_title|  **wx.lib.floatcanvas.FloatCanvas.FloatCanvas**
==========================================================================================================================================

The main class of the floatcanvas package :class:`~lib.floatcanvas.FloatCanvas`.



|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>FloatCanvas</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.lib.floatcanvas.FloatCanvas.FloatCanvas_inheritance.png" alt="Inheritance diagram of FloatCanvas" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.lib.floatcanvas.FloatCanvas.FloatCanvas.html" title="wx.lib.floatcanvas.FloatCanvas.FloatCanvas" alt="" coords="5,392,313,421"/> <area shape="rect" id="node2" href="wx.Panel.html" title="wx.Panel" alt="" coords="119,315,199,344"/> <area shape="rect" id="node3" href="wx.Window.html" title="wx.Window" alt="" coords="111,237,208,267"/> <area shape="rect" id="node4" href="wx.WindowBase.html" title="wx.WindowBase" alt="" coords="95,160,224,189"/> <area shape="rect" id="node5" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="101,83,218,112"/> <area shape="rect" id="node6" href="wx.Object.html" title="wx.Object" alt="" coords="56,5,143,35"/> <area shape="rect" id="node7" href="wx.Trackable.html" title="wx.Trackable" alt="" coords="167,5,274,35"/> </map> 
   </p>
   </div>

|


|super_classes| Known Superclasses
==================================

:class:`wx.Panel`

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.__init__`                     Default class constructor.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.AddObject`                    Add an object to the canvas
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.AddObjects`                   Add objects to the canvas
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.addshape`                     Creates Circle and adds its reference to the canvas.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.ClearAll`                     ClearAll(ResetBB=True)
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.Draw`                         Canvas.Draw(Force=False)
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.FlatEarthProjection`          Compute the scaling array for the flat-earth projection
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.GetHitTestColor`              Get the hit test colour
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.HitTest`                      Check if any objects in the dict for this event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.InitAll`                      Sets everything in the Canvas to default state.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.InitializePanel`              Intialize the panel.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.KeyDownEvent`                 Key down event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.KeyUpEvent`                   Key up event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.LeftDoubleClickEvent`         Left double click event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.LeftDownEvent`                Left down event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.LeftUpEvent`                  Left up event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MakeHitDict`                  Initialize the Hit dictonary.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MakeNewBuffers`               Make a new buffer.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MakeNewForegroundHTBitmap`    Off screen Bitmap used for Hit tests on foreground objects
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MakeNewHTBitmap`              Off screen Bitmap used for Hit tests on background objects
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MiddleDoubleClickEvent`       Middle double click event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MiddleDownEvent`              Middle down event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MiddleUpEvent`                Middle up event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MotionEvent`                  Motion event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MouseOverTest`                Check if mouse is over an object.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.MoveImage`                    Move the image in the window.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.OnPaint`                      On paint handler.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.OnSize`                       On size handler.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.OnSizeTimer`                  On size timer handler.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.PixelToWorld`                 Converts coordinates from Pixel coordinates to world coordinates.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.RemoveObject`                 "
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.RemoveObjects`                "
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.RightDoubleCLickEvent`        Right double click event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.RightDownEvent`               Right down event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.RightUpEvent`                 Right up event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.SaveAsImage`                  Saves the current image as an image file.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.ScalePixelToWorld`            This function computes a pair of x.y lengths,
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.ScaleWorldToPixel`            This function will get passed to the drawing functions of the objects,
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.SetMode`                      Set the GUImode to any of the available mode.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.SetProjectionFun`             Set a custom projection function
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.SetToNewScale`                Set to the new scale
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.UnBindAll`                    Removes all bindings to Objects.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.WheelEvent`                   Wheel event.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.WorldToPixel`                 This function will get passed to the drawing functions of the objects,
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.Zoom`                         Zoom(factor, center) changes the amount of zoom of the image by factor.
:meth:`~wx.lib.floatcanvas.FloatCanvas.FloatCanvas.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 :class:`~lib.floatcanvas.FloatCanvas`.

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

      Default class constructor.
      
      :param wx.Window `parent`: parent window. Must not be ``None``;
      :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`
       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...)
      :param string `BackgroundColor`: any value accepted by :class:`wx.Brush`
      :param `Debug`: activate debug, currently it prints some debugging
       information, could be improved.


   .. method:: AddObject(self, obj)

      Add an object to the canvas
      
      :param DrawObject `obj`: the object to add
      
      :return: DrawObject


   .. method:: AddObjects(self, Objects)

      Add objects to the canvas
      
      :param list `Objects`: a list of :class:`DrawObject`


   .. method:: 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


   .. method:: 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


   .. method:: 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.


   .. method:: FlatEarthProjection(self, CenterPoint)

      Compute the scaling array for the flat-earth projection
      
      :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
      
       :returns : a (2,) numpy array that scales world coordinates. This
        scaling is applied when converting to-from world to pixel coordinates.


   .. method:: GetHitTestColor(self, xy)

      Get the hit test colour
      
      :param `xy`: the position to get the hit test colour for


   .. method:: HitTest(self, event, HitEvent)

      Check if any objects in the dict for this event.


   .. method:: InitAll(self)

      Sets everything in the Canvas to default state.
      
      It can be used to reset the Canvas


   .. method:: InitializePanel(self)

      Intialize the panel.


   .. method:: KeyDownEvent(self, event)

      Key down event.


   .. method:: KeyUpEvent(self, event)

      Key up event.


   .. method:: LeftDoubleClickEvent(self, event)

      Left double click event.


   .. method:: LeftDownEvent(self, event)

      Left down event.


   .. method:: LeftUpEvent(self, event)

      Left up event.


   .. method:: MakeHitDict(self)

      Initialize the Hit dictonary.


   .. method:: MakeNewBuffers(self)

      Make a new buffer.


   .. method:: MakeNewForegroundHTBitmap(self)

      Off screen Bitmap used for Hit tests on foreground objects


   .. method:: MakeNewHTBitmap(self)

      Off screen Bitmap used for Hit tests on background objects


   .. method:: MiddleDoubleClickEvent(self, event)

      Middle double click event.


   .. method:: MiddleDownEvent(self, event)

      Middle down event.


   .. method:: MiddleUpEvent(self, event)

      Middle up event.


   .. method:: MotionEvent(self, event)

      Motion event.


   .. method:: MouseOverTest(self, event)

      Check if mouse is over an object.


   .. method:: MoveImage(self, shift, CoordType, ReDraw=True)

      Move the image in the window.
      
      :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
                      displayed image
       `Pixel`        shift the image by some number of pixels
       `World`        shift the image by an amount of floating point world
                      coordinates
       ============== ======================================================


   .. method:: OnPaint(self, event)

      On paint handler.


   .. method:: OnSize(self, event=None)

      On size handler.


   .. method:: OnSizeTimer(self, event=None)

      On size timer handler.


   .. method:: 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.


   .. method:: RemoveObject(self, Object, ResetBB=True)

      "
      Remove object from canvas
      
      :param DrawObject `Object`: a :class:`DrawObjects` to remove
      :param boolean `ResetBB`: reset the bounding box


   .. method:: RemoveObjects(self, Objects)

      "
      Remove objects from canvas
      
      :param list `Objects`: a list of :class:`DrawObjects` to remove


   .. method:: RightDoubleCLickEvent(self, event)

      Right double click event.


   .. method:: RightDownEvent(self, event)

      Right down event.


   .. method:: RightUpEvent(self, event)

      Right up event.


   .. method:: 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`


   .. method:: 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.


   .. method:: 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.


   .. method:: 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.


   .. method:: 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``


   .. method:: SetToNewScale(self, DrawFlag=True)

      Set to the new scale
      
      :param boolean `DrawFlag`: draw the canvas


   .. method:: UnBindAll(self)

      Removes all bindings to Objects.


   .. method:: WheelEvent(self, event)

      Wheel event.


   .. method:: 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.


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


   .. method:: 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.


