22
22
"""
23
23
import displayio
24
24
25
+ try :
26
+ from typing import Optional , Type
27
+ from types import TracebackType
28
+ except ImportError :
29
+ pass
30
+
25
31
__version__ = "0.0.0-auto.0"
26
32
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git"
27
33
@@ -54,12 +60,12 @@ class Cursor:
54
60
# pylint: disable=too-many-arguments,line-too-long
55
61
def __init__ (
56
62
self ,
57
- display = None ,
58
- display_group = None ,
59
- bmp = None ,
60
- is_hidden = False ,
61
- cursor_speed = 5 ,
62
- 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 ,
63
69
):
64
70
self ._display = display
65
71
self ._scale = scale
@@ -76,19 +82,19 @@ def __init__(
76
82
77
83
# pylint: enable=too-many-arguments,line-too-long
78
84
79
- def __enter__ (self ):
85
+ def __enter__ (self ) -> 'Cursor' :
80
86
return self
81
87
82
- def __exit__ (self , exception_type , exception_value , traceback ) :
88
+ def __exit__ (self , exception_type : Optional [ Type [ type ]] , exception_value : Optional [ BaseException ] , traceback : Optional [ TracebackType ]) -> None :
83
89
self .deinit ()
84
90
85
- def deinit (self ):
91
+ def deinit (self ) -> None :
86
92
"""deinitializes the cursor object."""
87
93
self ._is_deinited ()
88
94
self ._scale = None
89
95
self ._display_grp .remove (self ._cursor_grp )
90
96
91
- def _is_deinited (self ):
97
+ def _is_deinited (self ) -> None :
92
98
"""checks cursor deinitialization"""
93
99
if self ._scale is None :
94
100
raise ValueError (
@@ -97,12 +103,12 @@ def _is_deinited(self):
97
103
)
98
104
99
105
@property
100
- def scale (self ):
106
+ def scale (self ) -> int :
101
107
"""Returns the cursor's scale amount as an integer."""
102
108
return self ._scale
103
109
104
110
@scale .setter
105
- def scale (self , scale_value ) :
111
+ def scale (self , scale_value : int ) -> None :
106
112
"""Scales the cursor by scale_value in both directions.
107
113
:param int scale_value: Amount to scale the cursor by.
108
114
"""
@@ -112,12 +118,12 @@ def scale(self, scale_value):
112
118
self ._cursor_grp .scale = scale_value
113
119
114
120
@property
115
- def speed (self ):
121
+ def speed (self ) -> int :
116
122
"""Returns the cursor's speed, in pixels."""
117
123
return self ._speed
118
124
119
125
@speed .setter
120
- def speed (self , speed ) :
126
+ def speed (self , speed : int ) -> None :
121
127
"""Sets the speed of the cursor.
122
128
:param int speed: Cursor movement speed, in pixels.
123
129
"""
@@ -126,12 +132,12 @@ def speed(self, speed):
126
132
self ._speed = speed
127
133
128
134
@property
129
- def x (self ):
135
+ def x (self ) -> int :
130
136
"""Returns the cursor's x-coordinate."""
131
137
return self ._cursor_grp .x
132
138
133
139
@x .setter
134
- def x (self , x_val ) :
140
+ def x (self , x_val : int ) -> None :
135
141
"""Sets the x-value of the cursor.
136
142
:param int x_val: cursor x-position, in pixels.
137
143
"""
@@ -144,12 +150,12 @@ def x(self, x_val):
144
150
self ._cursor_grp .x = x_val
145
151
146
152
@property
147
- def y (self ):
153
+ def y (self ) -> int :
148
154
"""Returns the cursor's y-coordinate."""
149
155
return self ._cursor_grp .y
150
156
151
157
@y .setter
152
- def y (self , y_val ) :
158
+ def y (self , y_val : int ) -> None :
153
159
"""Sets the y-value of the cursor.
154
160
:param int y_val: cursor y-position, in pixels.
155
161
"""
@@ -162,12 +168,12 @@ def y(self, y_val):
162
168
self ._cursor_grp .y = y_val
163
169
164
170
@property
165
- def hidden (self ):
171
+ def hidden (self ) -> bool :
166
172
"""Returns True if the cursor is hidden or visible on the display."""
167
173
return self ._is_hidden
168
174
169
175
@hidden .setter
170
- def hidden (self , is_hidden ) :
176
+ def hidden (self , is_hidden : bool ) -> None :
171
177
self ._is_deinited ()
172
178
if is_hidden :
173
179
self ._is_hidden = True
@@ -176,16 +182,16 @@ def hidden(self, is_hidden):
176
182
self ._is_hidden = False
177
183
self ._display_grp .append (self ._cursor_grp )
178
184
179
- def hide (self ):
185
+ def hide (self ) -> None :
180
186
"""Hide the cursor."""
181
187
self .hidden = True
182
188
183
- def show (self ):
189
+ def show (self ) -> None :
184
190
"""Show the cursor."""
185
191
self .hidden = False
186
192
187
193
# pylint:disable=no-self-use
188
- def _default_cursor_bitmap (self ):
194
+ def _default_cursor_bitmap (self ) -> displayio . Bitmap :
189
195
bmp = displayio .Bitmap (20 , 20 , 3 )
190
196
# left edge, outline
191
197
for i in range (0 , bmp .height ):
@@ -210,12 +216,12 @@ def _default_cursor_bitmap(self):
210
216
# pylint:enable=no-self-use
211
217
212
218
@property
213
- def cursor_bitmap (self ):
219
+ def cursor_bitmap (self ) -> displayio . Bitmap :
214
220
"""Return the cursor bitmap."""
215
221
return self ._cursor_bitmap
216
222
217
223
@cursor_bitmap .setter
218
- def cursor_bitmap (self , bmp ) :
224
+ def cursor_bitmap (self , bmp : displayio . Bitmap ) -> None :
219
225
"""Set a new cursor bitmap.
220
226
221
227
:param ~displayio.Bitmap bmp: A Bitmap to use for the cursor
@@ -225,7 +231,7 @@ def cursor_bitmap(self, bmp):
225
231
self ._cur_sprite = displayio .TileGrid (bmp , pixel_shader = self ._cur_palette )
226
232
self ._cursor_grp .append (self ._cur_sprite )
227
233
228
- def generate_cursor (self , bmp ) :
234
+ def generate_cursor (self , bmp : displayio . Bitmap ) -> None :
229
235
"""Generates a cursor icon
230
236
231
237
:param ~displayio.Bitmap bmp: A Bitmap to use for the cursor
0 commit comments