Skip to content

Commit 8c4133b

Browse files
committed
Linted and reduced file size
1 parent 89d9bba commit 8c4133b

File tree

2 files changed

+15
-44
lines changed

2 files changed

+15
-44
lines changed

adafruit_pyportal/__init__.py

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,21 @@ def __init__(
182182
debug=debug,
183183
)
184184

185-
self.peripherals = Peripherals(spi, display=self.display, debug=debug)
185+
# Convenience Shortcuts for compatibility
186+
self.peripherals = Peripherals(
187+
spi, display=self.display, splash_group=self.splash, debug=debug
188+
)
186189
self.set_backlight = self.peripherals.set_backlight
187190
self.sd_check = self.peripherals.sd_check
188191
self.play_file = self.peripherals.play_file
189192

193+
self.image_converter_url = self.network.image_converter_url
194+
self.wget = self.network.wget
195+
# pylint: disable=invalid-name
196+
self.show_QR = self.graphics.qrcode
197+
self.hide_QR = self.graphics.hide_QR
198+
# pylint: enable=invalid-name
199+
190200
if hasattr(self.peripherals, "touchscreen"):
191201
self.touchscreen = self.peripherals.touchscreen
192202
if hasattr(self.peripherals, "mouse_cursor"):
@@ -288,22 +298,6 @@ def set_caption(self, caption_text, caption_position, caption_color):
288298
)
289299
self.set_text(caption_text, index)
290300

291-
def image_converter_url(self, image_url, width, height, color_depth=16):
292-
"""Generate a converted image url from the url passed in,
293-
with the given width and height. aio_username and aio_key must be
294-
set in secrets."""
295-
return self.network.image_converter_url(image_url, width, height, color_depth)
296-
297-
def wget(self, url, filename, *, chunk_size=12000):
298-
"""Download a url and save to filename location, like the command wget.
299-
300-
:param url: The URL from which to obtain the data.
301-
:param filename: The name of the file to save the data to.
302-
:param chunk_size: how much data to read/write at a time.
303-
304-
"""
305-
return self.network.wget(url, filename, chunk_size=chunk_size)
306-
307301
def fetch(self, refresh_url=None, timeout=10):
308302
"""Fetch data from the url we initialized with, perfom any parsing,
309303
and display text or graphics. This function does pretty much everything
@@ -368,27 +362,3 @@ def fetch(self, refresh_url=None, timeout=10):
368362
gc.collect()
369363

370364
return values
371-
372-
def show_QR(
373-
self, qr_data, *, qr_size=1, x=0, y=0, hide_background=False
374-
): # pylint: disable=invalid-name
375-
"""Display a QR code on the TFT
376-
377-
:param qr_data: The data for the QR code.
378-
:param int qr_size: The scale of the QR code.
379-
:param x: The x position of upper left corner of the QR code on the display.
380-
:param y: The y position of upper left corner of the QR code on the display.
381-
:param hide_background: Show the QR code on a black background if True.
382-
383-
"""
384-
self.graphics.qrcode(
385-
qr_data,
386-
qr_size=qr_size,
387-
x=x,
388-
y=y,
389-
hide_background=hide_background,
390-
)
391-
392-
def hide_QR(self): # pylint: disable=invalid-name
393-
"""Clear any QR codes that are currently on the screen"""
394-
self.graphics.hide_qrcode()

adafruit_pyportal/peripherals.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Peripherals:
4949
"""Peripherals Helper Class for the PyPortal Library"""
5050

5151
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
52-
def __init__(self, spi, display, debug=False):
52+
def __init__(self, spi, display, splash_group, debug=False):
5353
# Speaker Enable
5454
self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE)
5555
self._speaker_enable.switch_to_output(False)
@@ -89,7 +89,7 @@ def __init__(self, spi, display, debug=False):
8989
except ValueError:
9090
self._backlight = None
9191
self.set_backlight(1.0) # turn on backlight
92-
92+
# pylint: disable=import-outside-toplevel
9393
if hasattr(board, "TOUCH_XL"):
9494
import adafruit_touchscreen
9595

@@ -114,14 +114,15 @@ def __init__(self, spi, display, debug=False):
114114
if debug:
115115
print("Init cursor")
116116
self.mouse_cursor = Cursor(
117-
board.DISPLAY, display_group=self.splash, cursor_speed=8
117+
board.DISPLAY, display_group=splash_group, cursor_speed=8
118118
)
119119
self.mouse_cursor.hide()
120120
self.cursor = CursorManager(self.mouse_cursor)
121121
else:
122122
raise AttributeError(
123123
"PyPortal module requires either a touchscreen or gamepad."
124124
)
125+
# pylint: enable=import-outside-toplevel
125126

126127
gc.collect()
127128

0 commit comments

Comments
 (0)