2626from adafruit_display_shapes .roundrect import RoundRect
2727from adafruit_button .button_base import ButtonBase , _check_color
2828
29+ try :
30+ from typing import Optional , Union
31+ from fontio import FontProtocol
32+ from displayio import Group
33+ except ImportError :
34+ pass
35+
2936__version__ = "0.0.0+auto.0"
3037__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button.git"
3138
@@ -117,22 +124,22 @@ def _create_body(self):
117124 def __init__ (
118125 self ,
119126 * ,
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 :
136143 super ().__init__ (
137144 x = x ,
138145 y = y ,
@@ -167,7 +174,7 @@ def __init__(
167174
168175 self .label = label
169176
170- def _subclass_selected_behavior (self , value ) :
177+ def _subclass_selected_behavior (self , value : bool ) -> None :
171178 if self ._selected :
172179 new_fill = self .selected_fill
173180 new_out = self .selected_outline
@@ -180,7 +187,7 @@ def _subclass_selected_behavior(self, value):
180187 self .body .outline = new_out
181188
182189 @property
183- def group (self ):
190+ def group (self ) -> Group :
184191 """Return self for compatibility with old API."""
185192 print (
186193 "Warning: The group property is being deprecated. "
@@ -189,7 +196,7 @@ def group(self):
189196 )
190197 return self
191198
192- def contains (self , point ) :
199+ def contains (self , point : tuple [ int , int ]) -> bool :
193200 """Used to determine if a point is contained within a button. For example,
194201 ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for
195202 determining that a button has been touched.
@@ -199,56 +206,56 @@ def contains(self, point):
199206 )
200207
201208 @property
202- def fill_color (self ):
209+ def fill_color (self ) -> int :
203210 """The fill color of the button body"""
204211 return self ._fill_color
205212
206213 @fill_color .setter
207- def fill_color (self , new_color ) :
214+ def fill_color (self , new_color : int ) -> None :
208215 self ._fill_color = _check_color (new_color )
209216 if not self .selected :
210217 self .body .fill = self ._fill_color
211218
212219 @property
213- def outline_color (self ):
220+ def outline_color (self ) -> int :
214221 """The outline color of the button body"""
215222 return self ._outline_color
216223
217224 @outline_color .setter
218- def outline_color (self , new_color ) :
225+ def outline_color (self , new_color : int ) -> None :
219226 self ._outline_color = _check_color (new_color )
220227 if not self .selected :
221228 self .body .outline = self ._outline_color
222229
223230 @property
224- def selected_fill (self ):
231+ def selected_fill (self ) -> int :
225232 """The fill color of the button body when selected"""
226233 return self ._selected_fill
227234
228235 @selected_fill .setter
229- def selected_fill (self , new_color ) :
236+ def selected_fill (self , new_color : int ) -> None :
230237 self ._selected_fill = _check_color (new_color )
231238 if self .selected :
232239 self .body .fill = self ._selected_fill
233240
234241 @property
235- def selected_outline (self ):
242+ def selected_outline (self ) -> int :
236243 """The outline color of the button body when selected"""
237244 return self ._selected_outline
238245
239246 @selected_outline .setter
240- def selected_outline (self , new_color ) :
247+ def selected_outline (self , new_color : int ) -> None :
241248 self ._selected_outline = _check_color (new_color )
242249 if self .selected :
243250 self .body .outline = self ._selected_outline
244251
245252 @property
246- def width (self ):
253+ def width (self ) -> int :
247254 """The width of the button"""
248255 return self ._width
249256
250257 @width .setter
251- def width (self , new_width ) :
258+ def width (self , new_width : int ) -> None :
252259 self ._width = new_width
253260 self ._empty_self_group ()
254261 self ._create_body ()
@@ -257,20 +264,20 @@ def width(self, new_width):
257264 self .label = self .label
258265
259266 @property
260- def height (self ):
267+ def height (self ) -> int :
261268 """The height of the button"""
262269 return self ._height
263270
264271 @height .setter
265- def height (self , new_height ) :
272+ def height (self , new_height : int ) -> None :
266273 self ._height = new_height
267274 self ._empty_self_group ()
268275 self ._create_body ()
269276 if self .body :
270277 self .append (self .body )
271278 self .label = self .label
272279
273- def resize (self , new_width , new_height ) :
280+ def resize (self , new_width : int , new_height : int ) -> None :
274281 """Resize the button to the new width and height given
275282 :param new_width int the desired width
276283 :param new_height int the desired height
0 commit comments