File: wx.Cursor.txt

package info (click to toggle)
wxpython4.0 4.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 211,112 kB
  • sloc: cpp: 888,355; python: 223,130; makefile: 52,087; ansic: 45,780; sh: 3,012; xml: 1,534; perl: 264
file content (371 lines) | stat: -rw-r--r-- 12,281 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
.. wxPython Phoenix documentation

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

   Copyright: (c) 2011-2018 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>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.GDIObject.html" title="wx.GDIObject" alt="" coords="5,83,112,112"/> <area shape="rect" id="node3" href="wx.Cursor.html" title="wx.Cursor" alt="" coords="17,160,100,189"/> <area shape="rect" id="node2" href="wx.Object.html" title="wx.Object" alt="" coords="17,5,99,35"/> </map> 
   </p>

|


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


|


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

      **~~~**

      
      **__init__** `(self)`
      
      Default constructor.                   
      
      
      
      
      **~~~**

      
      **__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 OS X 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
      
      
      
      
      
      
      
      
      
      
                        
      
      
      
      
      **~~~**

      
      **__init__** `(self, cursorId)`
      
      Constructs a cursor using a cursor identifier.                  
      
      
      
      
      :param `cursorId`: A stock cursor identifier. See :ref:`wx.StockCursor`.   
      :type `cursorId`: wx.StockCursor
      
      
      
      
                        
      
      
      
      
      **~~~**

      
      **__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
      
      
      
      
      
      
      **~~~**

      
      **__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
      
      
      
      
                        
      
      
      
      
      **~~~**






   .. method:: GetHandle(self)

      Get the handle for the Cursor.  Windows only. 

      :rtype: `long`








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