26
26
from adafruit_display_shapes .roundrect import RoundRect
27
27
from adafruit_button .button_base import ButtonBase , _check_color
28
28
29
+ try :
30
+ from typing import Optional , Union
31
+ from fontio import FontProtocol
32
+ from displayio import Group
33
+ except ImportError :
34
+ pass
35
+
29
36
__version__ = "0.0.0+auto.0"
30
37
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button.git"
31
38
@@ -117,22 +124,22 @@ def _create_body(self):
117
124
def __init__ (
118
125
self ,
119
126
* ,
120
- x ,
121
- y ,
122
- width ,
123
- height ,
124
- name = None ,
125
- style = RECT ,
126
- fill_color = 0xFFFFFF ,
127
- outline_color = 0x0 ,
128
- label = None ,
129
- label_font = None ,
130
- label_color = 0x0 ,
131
- selected_fill = None ,
132
- selected_outline = None ,
133
- selected_label = None ,
134
- label_scale = None
135
- ):
127
+ x : int ,
128
+ y : int ,
129
+ width : int ,
130
+ height : int ,
131
+ name : Optional [ str ] = None ,
132
+ style : int = RECT ,
133
+ fill_color : Optional [ Union [ int , tuple [ int , int , int ]]] = 0xFFFFFF ,
134
+ outline_color : Optional [ Union [ int , tuple [ int , int , int ]]] = 0x0 ,
135
+ label : Optional [ str ] = None ,
136
+ label_font : Optional [ FontProtocol ] = None ,
137
+ label_color : Optional [ Union [ int , tuple [ int , int , int ]]] = 0x0 ,
138
+ selected_fill : Optional [ Union [ int , tuple [ int , int , int ]]] = None ,
139
+ selected_outline : Optional [ Union [ int , tuple [ int , int , int ]]] = None ,
140
+ selected_label : Optional [ Union [ int , tuple [ int , int , int ]]] = None ,
141
+ label_scale : Optional [ int ] = None
142
+ ) -> None :
136
143
super ().__init__ (
137
144
x = x ,
138
145
y = y ,
@@ -167,7 +174,7 @@ def __init__(
167
174
168
175
self .label = label
169
176
170
- def _subclass_selected_behavior (self , value ) :
177
+ def _subclass_selected_behavior (self , value : bool ) -> None :
171
178
if self ._selected :
172
179
new_fill = self .selected_fill
173
180
new_out = self .selected_outline
@@ -180,7 +187,7 @@ def _subclass_selected_behavior(self, value):
180
187
self .body .outline = new_out
181
188
182
189
@property
183
- def group (self ):
190
+ def group (self ) -> Group :
184
191
"""Return self for compatibility with old API."""
185
192
print (
186
193
"Warning: The group property is being deprecated. "
@@ -189,7 +196,7 @@ def group(self):
189
196
)
190
197
return self
191
198
192
- def contains (self , point ) :
199
+ def contains (self , point : tuple [ int , int ]) -> bool :
193
200
"""Used to determine if a point is contained within a button. For example,
194
201
``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for
195
202
determining that a button has been touched.
@@ -199,56 +206,56 @@ def contains(self, point):
199
206
)
200
207
201
208
@property
202
- def fill_color (self ):
209
+ def fill_color (self ) -> int :
203
210
"""The fill color of the button body"""
204
211
return self ._fill_color
205
212
206
213
@fill_color .setter
207
- def fill_color (self , new_color ) :
214
+ def fill_color (self , new_color : int ) -> None :
208
215
self ._fill_color = _check_color (new_color )
209
216
if not self .selected :
210
217
self .body .fill = self ._fill_color
211
218
212
219
@property
213
- def outline_color (self ):
220
+ def outline_color (self ) -> int :
214
221
"""The outline color of the button body"""
215
222
return self ._outline_color
216
223
217
224
@outline_color .setter
218
- def outline_color (self , new_color ) :
225
+ def outline_color (self , new_color : int ) -> None :
219
226
self ._outline_color = _check_color (new_color )
220
227
if not self .selected :
221
228
self .body .outline = self ._outline_color
222
229
223
230
@property
224
- def selected_fill (self ):
231
+ def selected_fill (self ) -> int :
225
232
"""The fill color of the button body when selected"""
226
233
return self ._selected_fill
227
234
228
235
@selected_fill .setter
229
- def selected_fill (self , new_color ) :
236
+ def selected_fill (self , new_color : int ) -> None :
230
237
self ._selected_fill = _check_color (new_color )
231
238
if self .selected :
232
239
self .body .fill = self ._selected_fill
233
240
234
241
@property
235
- def selected_outline (self ):
242
+ def selected_outline (self ) -> int :
236
243
"""The outline color of the button body when selected"""
237
244
return self ._selected_outline
238
245
239
246
@selected_outline .setter
240
- def selected_outline (self , new_color ) :
247
+ def selected_outline (self , new_color : int ) -> None :
241
248
self ._selected_outline = _check_color (new_color )
242
249
if self .selected :
243
250
self .body .outline = self ._selected_outline
244
251
245
252
@property
246
- def width (self ):
253
+ def width (self ) -> int :
247
254
"""The width of the button"""
248
255
return self ._width
249
256
250
257
@width .setter
251
- def width (self , new_width ) :
258
+ def width (self , new_width : int ) -> None :
252
259
self ._width = new_width
253
260
self ._empty_self_group ()
254
261
self ._create_body ()
@@ -257,20 +264,20 @@ def width(self, new_width):
257
264
self .label = self .label
258
265
259
266
@property
260
- def height (self ):
267
+ def height (self ) -> int :
261
268
"""The height of the button"""
262
269
return self ._height
263
270
264
271
@height .setter
265
- def height (self , new_height ) :
272
+ def height (self , new_height : int ) -> None :
266
273
self ._height = new_height
267
274
self ._empty_self_group ()
268
275
self ._create_body ()
269
276
if self .body :
270
277
self .append (self .body )
271
278
self .label = self .label
272
279
273
- def resize (self , new_width , new_height ) :
280
+ def resize (self , new_width : int , new_height : int ) -> None :
274
281
"""Resize the button to the new width and height given
275
282
:param new_width int the desired width
276
283
:param new_height int the desired height
0 commit comments