2222"""
2323import displayio
2424
25+ try :
26+ from typing import Optional , Type
27+ from types import TracebackType
28+ except ImportError :
29+ pass
30+
2531__version__ = "0.0.0-auto.0"
2632__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git"
2733
@@ -31,9 +37,10 @@ class Cursor:
3137
3238 :param ~displayio.Display display: CircuitPython display object.
3339 :param ~displayio.Group display_group: CircuitPython group object to append the cursor to.
40+ :param ~displayio.Bitmap bmp: CircuitPython bitmap object to use as the cursor
41+ :param bool is_hidden: Cursor is hidden on init.
3442 :param int cursor_speed: Speed of the cursor, in pixels.
3543 :param int scale: Scale amount for the cursor in both directions.
36- :param bool is_hidden: Cursor is hidden on init.
3744
3845 Example for creating a cursor layer
3946
@@ -53,12 +60,12 @@ class Cursor:
5360 # pylint: disable=too-many-arguments,line-too-long
5461 def __init__ (
5562 self ,
56- display = None ,
57- display_group = None ,
58- bmp = None ,
59- is_hidden = False ,
60- cursor_speed = 5 ,
61- scale = 1 ,
63+ display : Optional [ displayio . Display ] = None ,
64+ display_group : Optional [ displayio . Group ] = None ,
65+ bmp : Optional [ displayio . Bitmap ] = None ,
66+ is_hidden : bool = False ,
67+ cursor_speed : int = 5 ,
68+ scale : int = 1 ,
6269 ):
6370 self ._display = display
6471 self ._scale = scale
@@ -75,19 +82,24 @@ def __init__(
7582
7683 # pylint: enable=too-many-arguments,line-too-long
7784
78- def __enter__ (self ):
85+ def __enter__ (self ) -> "Cursor" :
7986 return self
8087
81- def __exit__ (self , exception_type , exception_value , traceback ):
88+ def __exit__ (
89+ self ,
90+ exception_type : Optional [Type [type ]],
91+ exception_value : Optional [BaseException ],
92+ traceback : Optional [TracebackType ],
93+ ) -> None :
8294 self .deinit ()
8395
84- def deinit (self ):
96+ def deinit (self ) -> None :
8597 """deinitializes the cursor object."""
8698 self ._is_deinited ()
8799 self ._scale = None
88100 self ._display_grp .remove (self ._cursor_grp )
89101
90- def _is_deinited (self ):
102+ def _is_deinited (self ) -> None :
91103 """checks cursor deinitialization"""
92104 if self ._scale is None :
93105 raise ValueError (
@@ -96,12 +108,12 @@ def _is_deinited(self):
96108 )
97109
98110 @property
99- def scale (self ):
111+ def scale (self ) -> int :
100112 """Returns the cursor's scale amount as an integer."""
101113 return self ._scale
102114
103115 @scale .setter
104- def scale (self , scale_value ) :
116+ def scale (self , scale_value : int ) -> None :
105117 """Scales the cursor by scale_value in both directions.
106118 :param int scale_value: Amount to scale the cursor by.
107119 """
@@ -111,12 +123,12 @@ def scale(self, scale_value):
111123 self ._cursor_grp .scale = scale_value
112124
113125 @property
114- def speed (self ):
126+ def speed (self ) -> int :
115127 """Returns the cursor's speed, in pixels."""
116128 return self ._speed
117129
118130 @speed .setter
119- def speed (self , speed ) :
131+ def speed (self , speed : int ) -> None :
120132 """Sets the speed of the cursor.
121133 :param int speed: Cursor movement speed, in pixels.
122134 """
@@ -125,12 +137,12 @@ def speed(self, speed):
125137 self ._speed = speed
126138
127139 @property
128- def x (self ):
140+ def x (self ) -> int :
129141 """Returns the cursor's x-coordinate."""
130142 return self ._cursor_grp .x
131143
132144 @x .setter
133- def x (self , x_val ) :
145+ def x (self , x_val : int ) -> None :
134146 """Sets the x-value of the cursor.
135147 :param int x_val: cursor x-position, in pixels.
136148 """
@@ -143,12 +155,12 @@ def x(self, x_val):
143155 self ._cursor_grp .x = x_val
144156
145157 @property
146- def y (self ):
158+ def y (self ) -> int :
147159 """Returns the cursor's y-coordinate."""
148160 return self ._cursor_grp .y
149161
150162 @y .setter
151- def y (self , y_val ) :
163+ def y (self , y_val : int ) -> None :
152164 """Sets the y-value of the cursor.
153165 :param int y_val: cursor y-position, in pixels.
154166 """
@@ -161,12 +173,12 @@ def y(self, y_val):
161173 self ._cursor_grp .y = y_val
162174
163175 @property
164- def hidden (self ):
176+ def hidden (self ) -> bool :
165177 """Returns True if the cursor is hidden or visible on the display."""
166178 return self ._is_hidden
167179
168180 @hidden .setter
169- def hidden (self , is_hidden ) :
181+ def hidden (self , is_hidden : bool ) -> None :
170182 self ._is_deinited ()
171183 if is_hidden :
172184 self ._is_hidden = True
@@ -175,16 +187,16 @@ def hidden(self, is_hidden):
175187 self ._is_hidden = False
176188 self ._display_grp .append (self ._cursor_grp )
177189
178- def hide (self ):
190+ def hide (self ) -> None :
179191 """Hide the cursor."""
180192 self .hidden = True
181193
182- def show (self ):
194+ def show (self ) -> None :
183195 """Show the cursor."""
184196 self .hidden = False
185197
186198 # pylint:disable=no-self-use
187- def _default_cursor_bitmap (self ):
199+ def _default_cursor_bitmap (self ) -> displayio . Bitmap :
188200 bmp = displayio .Bitmap (20 , 20 , 3 )
189201 # left edge, outline
190202 for i in range (0 , bmp .height ):
@@ -209,23 +221,26 @@ def _default_cursor_bitmap(self):
209221 # pylint:enable=no-self-use
210222
211223 @property
212- def cursor_bitmap (self ):
224+ def cursor_bitmap (self ) -> displayio . Bitmap :
213225 """Return the cursor bitmap."""
214226 return self ._cursor_bitmap
215227
216228 @cursor_bitmap .setter
217- def cursor_bitmap (self , bmp ) :
229+ def cursor_bitmap (self , bmp : displayio . Bitmap ) -> None :
218230 """Set a new cursor bitmap.
219231
220- :param bmp: A Bitmap to use for the cursor
232+ :param ~displayio.Bitmap bmp: A Bitmap to use for the cursor
221233 """
222234 self ._cursor_bitmap = bmp
223235 self ._cursor_grp .remove (self ._cur_sprite )
224236 self ._cur_sprite = displayio .TileGrid (bmp , pixel_shader = self ._cur_palette )
225237 self ._cursor_grp .append (self ._cur_sprite )
226238
227- def generate_cursor (self , bmp ):
228- """Generates a cursor icon"""
239+ def generate_cursor (self , bmp : displayio .Bitmap ) -> None :
240+ """Generates a cursor icon
241+
242+ :param ~displayio.Bitmap bmp: A Bitmap to use for the cursor
243+ """
229244 self ._is_deinited ()
230245 self ._cursor_grp = displayio .Group (scale = self ._scale )
231246 self ._cur_palette = displayio .Palette (3 )
0 commit comments