diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 1a36177..f7d2ed5 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -268,6 +268,8 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None, print("No SD card found:", error) self._qr_group = None + # Tracks whether we've hidden the background when we showed the QR code. + self._qr_only = False if self._debug: print("Init caption") @@ -784,13 +786,14 @@ def fetch(self, refresh_url=None): return values[0] return values - def show_QR(self, qr_data, qr_size=1, x=0, y=0): # pylint: disable=invalid-name + def show_QR(self, qr_data, *, qr_size=1, x=0, y=0, hide_background=False): # pylint: disable=invalid-name """Display a QR code on the TFT :param qr_data: The data for the QR code. :param int qr_size: The scale of the QR code. :param x: The x position of upper left corner of the QR code on the display. :param y: The y position of upper left corner of the QR code on the display. + :param hide_background: Show the QR code on a black background if True. """ import adafruit_miniqr @@ -829,7 +832,21 @@ def show_QR(self, qr_data, qr_size=1, x=0, y=0): # pylint: disable=invalid-name self._qr_group.x = x self._qr_group.y = y self._qr_group.append(qr_sprite) - board.DISPLAY.show(self._qr_group) + if hide_background: + board.DISPLAY.show(self._qr_group) + self._qr_only = hide_background + + def hide_QR(self): # pylint: disable=invalid-name + """Clear any QR codes that are currently on the screen + """ + + if self._qr_only: + board.DISPLAY.show(self.splash) + else: + try: + self._qr_group.pop() + except (IndexError, AttributeError): # later test if empty + pass # return a list of lines with wordwrapping @staticmethod