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



.. _wx.Cursor:

==========================================================================================================================================
|phoenix_title|  **wx.Cursor**
==========================================================================================================================================

A cursor is a small bitmap usually used for denoting where the mouse pointer is, with a picture that might indicate the interpretation of a mouse click.          

As with icons, cursors in X and MS Windows are created in a different manner. Therefore, separate cursors will be created for the different environments. Platform-specific methods for creating a :ref:`wx.Cursor`  object are catered for, and this is an occasion where conditional compilation will probably be required (see :ref:`wx.Icon`  for an example). 

A single cursor object may be used in many windows (any subwindow type). The wxWidgets convention is to set the cursor for a window, as in X, rather than to set it globally as in MS Windows, although a global :ref:`wx.SetCursor`  function is also available for MS Windows use. 



|phoenix_title| Creating a Custom Cursor
========================================

The following is an example of creating a cursor from 32x32 bitmap data (down_bits) and a mask (down_mask) where 1 is black and 0 is white for the bits, and 1 is opaque and 0 is transparent for the mask. It works on Windows and GTK+. ::

        down_bits = [255, 255, 255, 255, 31,
                     255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255,
                     31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255,
                     255, 31, 255, 255, 255, 31, 255, 255, 255, 25, 243,
                     255, 255, 19, 249, 255, 255, 7, 252, 255, 255, 15, 254,
                     255, 255, 31, 255, 255, 255, 191, 255, 255, 255, 255,
                     255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
                     255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
                     255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
                     255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
                     255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
                     255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
                     255]

        down_mask = [240, 1, 0, 0, 240, 1,
                     0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1,
                     0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 255, 31, 0, 0, 255,
                     31, 0, 0, 254, 15, 0, 0, 252, 7, 0, 0, 248, 3, 0, 0,
                     240, 1, 0, 0, 224, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     0, 0, 0, 0, 0]

        if wx.Platform == '__WXMSW__':

            down_bitmap = wx.BitmapFromBits(down_bits, 32, 32)
            down_mask_bitmap = wx.BitmapFromBits(down_mask, 32, 32)

            down_bitmap.SetMask(wx.Mask(down_mask_bitmap))
            down_image = down_bitmap.ConvertToImage()
            down_image.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 6)
            down_image.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 14)
            down_cursor = wx.Cursor(down_image)

        elif wx.Platform == '__WXGTK__':

            down_cursor = wx.Cursor(down_bits, 32, 32, 6, 14,
                                    down_mask, wx.WHITE, wx.BLACK)





.. seealso:: :ref:`wx.Bitmap`, :ref:`wx.Icon`, :meth:`wx.Window.SetCursor` , :ref:`wx.SetCursor`, :ref:`wx.StockCursor`    







|

|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>Cursor</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.Cursor_inheritance.png" alt="Inheritance diagram of Cursor" 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.Cursor.html" title="wx.Cursor" alt="" coords="17,160,104,189"/> <area shape="rect" id="node2" href="wx.GDIObject.html" title="wx.GDIObject" alt="" coords="5,83,116,112"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="17,5,104,35"/> </map> 
   </p>
   </div>

|


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

================================================================================ ================================================================================
:meth:`~wx.Cursor.__init__`                                                      Default constructor.
:meth:`~wx.Cursor.GetHandle`                                                     Get the handle for the Cursor.  Windows only.
:meth:`~wx.Cursor.GetHotSpot`                                                    Returns the coordinates of the cursor hot spot.
:meth:`~wx.Cursor.IsOk`                                                          Returns ``True`` if cursor data is present.
:meth:`~wx.Cursor.SetHandle`                                                     Set the handle to use for this Cursor.  Windows only.
:meth:`~wx.Cursor.__bool__`                                                      
:meth:`~wx.Cursor.__nonzero__`                                                   
:meth:`~wx.Cursor._copyFrom`                                                     For internal use only.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.Cursor.Handle`                                                        See :meth:`~wx.Cursor.GetHandle` and :meth:`~wx.Cursor.SetHandle`
:attr:`~wx.Cursor.HotSpot`                                                       See :meth:`~wx.Cursor.GetHotSpot`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.Cursor(GDIObject)

   **Possible constructors**::

       Cursor()
       
       Cursor(cursorName, type=BITMAP_TYPE_ANY, hotSpotX=0, hotSpotY=0)
       
       Cursor(cursorId)
       
       Cursor(image)
       
       Cursor(cursor)
       
   
   A cursor is a small bitmap usually used for denoting where the mouse
   pointer is, with a picture that might indicate the interpretation of a
   mouse click.



   .. method:: __init__(self, *args, **kw)



      |overload| Overloaded Implementations:

      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self)`
      
      Default constructor.                   
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, cursorName, type=BITMAP_TYPE_ANY, hotSpotX=0, hotSpotY=0)`
      
      Constructs a cursor by passing a string resource name or filename.                  
      
      The arguments `hotSpotX`  and `hotSpotY`  are only used when there's no hotspot info in the resource/image-file to load (e.g. when using  ``BITMAP_TYPE_ICO``   under wxMSW or   ``BITMAP_TYPE_XPM``   under wxGTK). 
      
      
      
      
      :param `cursorName`: The name of the resource or the image file to load.   
      :type `cursorName`: string
      :param `type`: Icon type to load. It defaults to  ``CURSOR_DEFAULT_TYPE`` , which is a #define associated to different values on different platforms:
      
       - under Windows, it defaults to  ``BITMAP_TYPE_CUR_RESOURCE`` . Other permitted types under Windows are   ``BITMAP_TYPE_CUR``   (to load a cursor from a .cur cursor file),   ``BITMAP_TYPE_ICO``   (to load a cursor from a .ico icon file) and   ``BITMAP_TYPE_ANI``   (to load a cursor from a .ani icon file). 
       - under MacOS, it defaults to  ``BITMAP_TYPE_MACCURSOR_RESOURCE`` ; when specifying a string resource name, first the color cursors 'crsr' and then the black/white cursors '``CURS``' in the resource chain are scanned through. Note that resource forks are deprecated on macOS so this is only available for legacy reasons and should not be used in new code. 
       - under GTK, it defaults to  ``BITMAP_TYPE_XPM`` . See the  :ref:`wx.Cursor`  constructor for more info. 
       - under X11, it defaults to  ``BITMAP_TYPE_XPM`` . 
       - under Motif, it defaults to  ``BITMAP_TYPE_XBM`` .   
      
       
      
      :type `type`: wx.BitmapType
      :param `hotSpotX`: Hotspot x coordinate (relative to the top left of the image).   
      :type `hotSpotX`: int
      :param `hotSpotY`: Hotspot y coordinate (relative to the top left of the image).   
      :type `hotSpotY`: int
      
      
      
      
      
      
      
      
      
      
                        
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, cursorId)`
      
      Constructs a cursor using a cursor identifier.                  
      
      
      
      
      :param `cursorId`: A stock cursor identifier. See :ref:`wx.StockCursor`.   
      :type `cursorId`: wx.StockCursor
      
      
      
      
                        
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, image)`
      
      Constructs a cursor from a :ref:`wx.Image`.                  
      
      If cursor are monochrome on the current platform, colors with the ``RGB`` elements all greater than 127 will be foreground, colors less than this background. The mask (if any) will be used to specify the transparent area. 
      
      In wxMSW the foreground will be white and the background black. If the cursor is larger than 32x32 it is resized. 
      
      In wxGTK, colour cursors and alpha channel are supported (starting from GTK+ 2.2). Otherwise the two most frequent colors will be used for foreground and background. In any case, the cursor will be displayed at the size of the image. 
      
      Under Mac (Cocoa), large cursors are supported. 
      
      Notice that the `image`  can define the cursor hot spot. To set it you need to use :meth:`wx.Image.SetOption`   with  ``IMAGE_OPTION_CUR_HOTSPOT_X``   or   ``IMAGE_OPTION_CUR_HOTSPOT_Y`` , e.g.  ::
      
                      image.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX)
                      image.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, hotSpotY)
      
                       
      
      
      :param `image`: 
      :type `image`: wx.Image
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, cursor)`
      
      Copy constructor, uses :ref:`reference counting <reference counting>`.                  
      
      
      
      
      :param `cursor`: Pointer or reference to a cursor to copy.   
      :type `cursor`: wx.Cursor
      
      
      
      
                        
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`






   .. method:: GetHandle(self)

      Get the handle for the Cursor.  Windows only. 

      :rtype: `long`








   .. method:: GetHotSpot(self)

      Returns the coordinates of the cursor hot spot.                  

      The hot spot is the point at which the mouse is actually considered to be when this cursor is used. 

      This method is currently only implemented in wxMSW and ``GTK2+`` and simply returns :ref:`wx.DefaultPosition`  in the other ports. 

                

      :rtype: :ref:`wx.Point`







      .. versionadded:: 4.1/wxWidgets-3.1.0  
     








   .. method:: IsOk(self)

      Returns ``True`` if cursor data is present.                  

      :rtype: `bool`








   .. method:: SetHandle(self, handle)

      Set the handle to use for this Cursor.  Windows only.  





   .. method:: __bool__(self)



      :rtype: `int`








   .. method:: __nonzero__(self)



      :rtype: `int`








   .. method:: _copyFrom(self, other)

      For internal use only.  





   .. attribute:: Handle

      See :meth:`~wx.Cursor.GetHandle` and :meth:`~wx.Cursor.SetHandle`


   .. attribute:: HotSpot

      See :meth:`~wx.Cursor.GetHotSpot`

