48
48
from adafruit_button import Button
49
49
import terminalio
50
50
51
+ try :
52
+ from typing import Dict , Optional , List
53
+ except ImportError :
54
+ pass
55
+
51
56
__version__ = "0.0.0-auto.0"
52
57
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PYOA.git"
53
58
@@ -56,7 +61,7 @@ class PYOA_Graphics:
56
61
# pylint: disable=too-many-instance-attributes
57
62
"""A choose your own adventure game framework."""
58
63
59
- def __init__ (self ):
64
+ def __init__ (self ) -> None :
60
65
self .root_group = displayio .Group ()
61
66
self ._display = board .DISPLAY
62
67
self ._background_group = displayio .Group ()
@@ -113,7 +118,7 @@ def __init__(self):
113
118
self ._right_button = None
114
119
self ._middle_button = None
115
120
116
- def load_game (self , game_directory ) :
121
+ def load_game (self , game_directory : str ) -> None :
117
122
"""Load a game.
118
123
119
124
:param str game_directory: where the game files are stored
@@ -183,7 +188,7 @@ def load_game(self, game_directory):
183
188
except OSError as err :
184
189
raise OSError ("Could not open game file " + self ._gamefilename ) from err
185
190
186
- def _fade_to_black (self ):
191
+ def _fade_to_black (self ) -> None :
187
192
"""Turn down the lights."""
188
193
if self .mouse_cursor :
189
194
self .mouse_cursor .is_hidden = True
@@ -196,7 +201,7 @@ def _fade_to_black(self):
196
201
if self .mouse_cursor :
197
202
self .mouse_cursor .is_hidden = False
198
203
199
- def _display_buttons (self , card ) :
204
+ def _display_buttons (self , card : Dict [ str , str ]) -> None :
200
205
"""Display the buttons of a card.
201
206
202
207
:param card: The active card
@@ -214,15 +219,15 @@ def _display_buttons(self, card):
214
219
self ._button_group .append (self ._right_button )
215
220
self ._button_group .append (self ._left_button )
216
221
217
- def _display_background_for (self , card ) :
222
+ def _display_background_for (self , card : Dict [ str , str ]) -> None :
218
223
"""If there's a background on card, display it.
219
224
220
225
:param card: The active card
221
226
:type card: dict(str, str)
222
227
"""
223
228
self .set_background (card .get ("background_image" , None ), with_fade = False )
224
229
225
- def _display_text_for (self , card ) :
230
+ def _display_text_for (self , card : Dict [ str , str ]) -> None :
226
231
"""Display the main text of a card.
227
232
228
233
:param card: The active card
@@ -248,7 +253,7 @@ def _display_text_for(self, card):
248
253
249
254
self .set_text (text , text_color , background_color = text_background_color )
250
255
251
- def _play_sound_for (self , card ) :
256
+ def _play_sound_for (self , card : Dict [ str , str ]) -> None :
252
257
"""If there's a sound, start playing it.
253
258
254
259
:param card: The active card
@@ -261,7 +266,7 @@ def _play_sound_for(self, card):
261
266
print ("Loop:" , loop )
262
267
self .play_sound (sound , wait_to_finish = False , loop = loop )
263
268
264
- def _wait_for_press (self , card ) :
269
+ def _wait_for_press (self , card : Dict [ str , str ]) -> str :
265
270
"""Wait for a button to be pressed.
266
271
267
272
:param card: The active card
@@ -299,7 +304,7 @@ def _wait_for_press(self, card):
299
304
return card .get ("button02_goto_card_id" , None )
300
305
time .sleep (0.1 )
301
306
302
- def display_card (self , card_num ) :
307
+ def display_card (self , card_num : int ) -> int :
303
308
"""Display and handle input on a card.
304
309
305
310
:param int card_num: the index of the card to process
@@ -339,7 +344,7 @@ def display_card(self, card_num):
339
344
"Could not find card with matching 'card_id': " , destination_card_id
340
345
)
341
346
342
- def play_sound (self , filename , * , wait_to_finish = True , loop = False ):
347
+ def play_sound (self , filename : Optional [ str ] , * , wait_to_finish : bool = True , loop : bool = False ) -> None :
343
348
"""Play a sound
344
349
345
350
:param filename: The filename of the sound to play. Use `None` to stop
@@ -375,7 +380,7 @@ def play_sound(self, filename, *, wait_to_finish=True, loop=False):
375
380
self ._wavfile = None
376
381
self ._speaker_enable .value = False
377
382
378
- def set_text (self , text , color , background_color = None ):
383
+ def set_text (self , text : Optional [ str ] , color : Optional [ str ] , background_color : Optional [ int ] = None ) -> None :
379
384
"""Display the test for a card.
380
385
381
386
:param text: the text to display
@@ -412,7 +417,7 @@ def set_text(self, text, color, background_color=None):
412
417
self ._text .background_color = background_color
413
418
self ._text_group .append (self ._text )
414
419
415
- def set_background (self , filename , * , with_fade = True ):
420
+ def set_background (self , filename : Optional [ str ] , * , with_fade : bool = True ) -> None :
416
421
"""The background image to a bitmap file.
417
422
418
423
:param filename: The filename of the chosen background
@@ -437,7 +442,7 @@ def set_background(self, filename, *, with_fade=True):
437
442
self ._display .refresh (target_frames_per_second = 60 )
438
443
self .backlight_fade (1.0 )
439
444
440
- def backlight_fade (self , to_light ) :
445
+ def backlight_fade (self , to_light : float ) -> None :
441
446
"""
442
447
Adjust the TFT backlight. Fade from the current value to the ``to_light`` value
443
448
@@ -457,7 +462,7 @@ def backlight_fade(self, to_light):
457
462
458
463
# return a list of lines with wordwrapping
459
464
@staticmethod
460
- def wrap_nicely (string , max_chars ) :
465
+ def wrap_nicely (string : str , max_chars : int ) -> List [ str ] :
461
466
"""A helper that will return a list of lines with word-break wrapping.
462
467
463
468
:param str string: The text to be wrapped.
0 commit comments