Skip to content

Commit 7de9f43

Browse files
authored
Merge pull request #25 from lesamouraipourpre/remove-old-refresh
Remove old display refresh code
2 parents a6050d9 + 8b1f310 commit 7de9f43

File tree

2 files changed

+68
-74
lines changed

2 files changed

+68
-74
lines changed

.pylintrc

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2-
#
3-
# SPDX-License-Identifier: Unlicense
4-
5-
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
62
#
73
# SPDX-License-Identifier: Unlicense
84

@@ -13,11 +9,11 @@
139
# run arbitrary code
1410
extension-pkg-whitelist=
1511

16-
# Add files or directories to the blacklist. They should be base names, not
12+
# Add files or directories to the ignore-list. They should be base names, not
1713
# paths.
1814
ignore=CVS
1915

20-
# Add files or directories matching the regex patterns to the blacklist. The
16+
# Add files or directories matching the regex patterns to the ignore-list. The
2117
# regex matches against base names, not paths.
2218
ignore-patterns=
2319

@@ -59,7 +55,8 @@ confidence=
5955
# no Warning level messages displayed, use"--disable=all --enable=classes
6056
# --disable=W"
6157
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
62-
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding
58+
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding,pointless-string-statement
59+
6360

6461
# Enable the message, report, category or checker with the given id(s). You can
6562
# either give multiple identifier separated by comma (,) or put this option

adafruit_pyoa.py

+63-66
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
1717
**Hardware:**
1818
19-
* PyPortal
20-
https://www.adafruit.com/product/4116
19+
* PyPortal https://www.adafruit.com/product/4116
20+
* PyPortal Pynt https://www.adafruit.com/product/4465
21+
* PyPortal Titano https://www.adafruit.com/product/4444
22+
* PyBadge https://www.adafruit.com/product/4200
23+
* PyGamer https://www.adafruit.com/product/4242
24+
* HalloWing M4 https://www.adafruit.com/product/4300
2125
2226
**Software and Dependencies:**
2327
2428
* Adafruit CircuitPython firmware for the supported boards:
2529
https://github.com/adafruit/circuitpython/releases
2630
"""
2731

28-
# pylint: disable=too-many-instance-attributes,no-self-use,line-too-long
29-
3032
# imports
3133
import time
3234
import json
@@ -51,6 +53,7 @@
5153

5254

5355
class PYOA_Graphics:
56+
# pylint: disable=too-many-instance-attributes
5457
"""A choose your own adventure game framework."""
5558

5659
def __init__(self):
@@ -113,7 +116,7 @@ def __init__(self):
113116
def load_game(self, game_directory):
114117
"""Load a game.
115118
116-
:param game_directory: where the game files are stored
119+
:param str game_directory: where the game files are stored
117120
"""
118121
self._gamedirectory = game_directory
119122
self._text_font = terminalio.FONT
@@ -131,42 +134,42 @@ def load_game(self, game_directory):
131134
button_width = 120
132135
button_height = 40
133136
if self._display.height < 200:
134-
button_y /= 2
137+
button_y //= 2
135138
button_y += 10
136-
button_width /= 2
137-
button_height /= 2
138-
btn_right /= 2
139-
btn_mid /= 2
139+
button_width //= 2
140+
button_height //= 2
141+
btn_right //= 2
142+
btn_mid //= 2
140143
elif self._display.height > 250:
141-
button_y *= 0.75
144+
button_y = (button_y * 3) // 4
142145
button_y -= 20
143-
button_width *= 0.75
144-
button_height *= 0.75
145-
btn_right *= 0.75
146-
btn_mid *= 0.75
146+
button_width = (button_width * 3) // 4
147+
button_height = (button_height * 3) // 4
148+
btn_right = (btn_right * 3) // 4
149+
btn_mid = (btn_right * 3) // 4
147150
self._left_button = Button(
148-
x=int(btn_left),
149-
y=int(button_y),
150-
width=int(button_width),
151-
height=int(button_height),
151+
x=btn_left,
152+
y=button_y,
153+
width=button_width,
154+
height=button_height,
152155
label="Left",
153156
label_font=self._text_font,
154157
style=Button.SHADOWROUNDRECT,
155158
)
156159
self._right_button = Button(
157-
x=int(btn_right),
158-
y=int(button_y),
159-
width=int(button_width),
160-
height=int(button_height),
160+
x=btn_right,
161+
y=button_y,
162+
width=button_width,
163+
height=button_height,
161164
label="Right",
162165
label_font=self._text_font,
163166
style=Button.SHADOWROUNDRECT,
164167
)
165168
self._middle_button = Button(
166-
x=int(btn_mid),
167-
y=int(button_y),
168-
width=int(button_width),
169-
height=int(button_height),
169+
x=btn_mid,
170+
y=button_y,
171+
width=button_width,
172+
height=button_height,
170173
label="Middle",
171174
label_font=self._text_font,
172175
style=Button.SHADOWROUNDRECT,
@@ -283,7 +286,7 @@ def _wait_for_press(self, card):
283286
def display_card(self, card_num):
284287
"""Display and handle input on a card.
285288
286-
:param card_num: the index of the card to process
289+
:param int card_num: the index of the card to process
287290
"""
288291
card = self._game[card_num]
289292
print(card)
@@ -296,11 +299,7 @@ def display_card(self, card_num):
296299
self._display_background_for(card)
297300
self.backlight_fade(1.0)
298301
self._display_text_for(card)
299-
try:
300-
self._display.refresh(target_frames_per_second=60)
301-
except AttributeError:
302-
self._display.refresh_soon()
303-
self._display.wait_for_frame()
302+
self._display.refresh(target_frames_per_second=60)
304303

305304
self._play_sound_for(card)
306305

@@ -325,9 +324,10 @@ def display_card(self, card_num):
325324
def play_sound(self, filename, *, wait_to_finish=True, loop=False):
326325
"""Play a sound
327326
328-
:param filename: The filename of the sound to play
329-
:param wait_to_finish: Whether playing the sound should block
330-
:param loop: Whether the sound should loop
327+
:param Union(None,str) filename: The filename of the sound to play. Use `None` to stop
328+
playing anything.
329+
:param bool wait_to_finish: Whether playing the sound should block
330+
:param bool loop: Whether the sound should loop
331331
"""
332332
self._speaker_enable.value = False
333333
self.audio.stop()
@@ -339,10 +339,7 @@ def play_sound(self, filename, *, wait_to_finish=True, loop=False):
339339
return # nothing more to do, just stopped
340340
filename = self._gamedirectory + "/" + filename
341341
print("Playing sound", filename)
342-
try:
343-
self._display.refresh(target_frames_per_second=60)
344-
except AttributeError:
345-
self._display.wait_for_frame()
342+
self._display.refresh(target_frames_per_second=60)
346343
try:
347344
self._wavfile = open(filename, "rb") # pylint: disable=consider-using-with
348345
except OSError as err:
@@ -362,8 +359,8 @@ def play_sound(self, filename, *, wait_to_finish=True, loop=False):
362359
def set_text(self, text, color):
363360
"""Display the test for a card.
364361
365-
:param text: the text to display
366-
:param color: the text color
362+
:param Union(None,str) text: the text to display
363+
:param Union(None,int) color: the text color
367364
368365
"""
369366
if self._text_group:
@@ -393,7 +390,9 @@ def set_text(self, text, color):
393390
def set_background(self, filename, *, with_fade=True):
394391
"""The background image to a bitmap file.
395392
396-
:param filename: The filename of the chosen background
393+
:param Union(None,str) filename: The filename of the chosen background
394+
:param bool with_fade: If `True` fade out the backlight while loading the new background
395+
and fade in the backlight once completed.
397396
"""
398397
print("Set background to", filename)
399398
if with_fade:
@@ -407,32 +406,31 @@ def set_background(self, filename, *, with_fade=True):
407406
with open(
408407
self._gamedirectory + "/" + filename, "rb"
409408
) as self._background_file:
409+
# TODO: Once CP6 is no longer supported, pass combined filename into OnDiskBitmap
410410
background = displayio.OnDiskBitmap(self._background_file)
411-
self._background_sprite = displayio.TileGrid(
412-
background,
413-
pixel_shader=getattr(
414-
background, "pixel_shader", displayio.ColorConverter()
415-
),
416-
# TODO: Once CP6 is no longer supported, replace the above line with below
417-
# pixel_shader=background.pixel_shader,
418-
x=0,
419-
y=0,
420-
)
421-
self._background_group.append(self._background_sprite)
411+
self._background_sprite = displayio.TileGrid(
412+
background,
413+
pixel_shader=getattr(
414+
background, "pixel_shader", displayio.ColorConverter()
415+
),
416+
# TODO: Once CP6 is no longer supported, replace the above line with below
417+
# pixel_shader=background.pixel_shader,
418+
)
419+
self._background_group.append(self._background_sprite)
422420
if with_fade:
423-
try:
424-
self._display.refresh(target_frames_per_second=60)
425-
except AttributeError:
426-
self._display.refresh_soon()
427-
self._display.wait_for_frame()
421+
self._display.refresh(target_frames_per_second=60)
428422
self.backlight_fade(1.0)
429423

430424
def backlight_fade(self, to_light):
431-
"""Adjust the TFT backlight. Fade from one value to another"""
425+
"""
426+
Adjust the TFT backlight. Fade from the current value to the ``to_light`` value
427+
428+
:param float to_light: the desired backlight brightness between :py:const:`0.0` and
429+
:py:const:`1.0`.
430+
"""
432431
from_light = self._display.brightness
433432
from_light = int(from_light * 100)
434-
to_light = max(0, min(1.0, to_light))
435-
to_light = int(to_light * 100)
433+
to_light = max(0, min(100, int(to_light * 100)))
436434
delta = 1
437435
if from_light > to_light:
438436
delta = -1
@@ -442,7 +440,6 @@ def backlight_fade(self, to_light):
442440
self._display.brightness = to_light / 100
443441

444442
# return a list of lines with wordwrapping
445-
# pylint: disable=invalid-name
446443
@staticmethod
447444
def wrap_nicely(string, max_chars):
448445
"""A helper that will return a list of lines with word-break wrapping.
@@ -457,10 +454,10 @@ def wrap_nicely(string, max_chars):
457454
the_line = ""
458455
for w in words:
459456
if "\n" in w:
460-
w1, w2 = w.split("\n")
461-
the_line += " " + w1
457+
_w1, _w2 = w.split("\n")
458+
the_line += " " + _w1
462459
the_lines.append(the_line)
463-
the_line = w2
460+
the_line = _w2
464461
elif len(the_line + " " + w) > max_chars:
465462
the_lines.append(the_line)
466463
the_line = "" + w

0 commit comments

Comments
 (0)