From 09702c6c591a0099a6b530e33fe5ea53a227c22f Mon Sep 17 00:00:00 2001 From: Sean Tibor Date: Sat, 4 May 2019 17:49:13 -0400 Subject: [PATCH 1/7] add hide_qr function & clear_background in show_qr --- adafruit_pyportal.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 1a36177..4a1b3f9 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, clear_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 clear_background: Show the QR code on a black background if True, otherwise put it on top of the existing background. """ import adafruit_miniqr @@ -829,7 +832,23 @@ 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 clear_background: + board.DISPLAY.show(self._qr_group) + self._qr_only = True + else: + self._qr_only = False + + def hide_QR(self): + """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: # later test if empty + pass # return a list of lines with wordwrapping @staticmethod From 0b1761293093f858ca5e4c857dc2cef4c8c112e8 Mon Sep 17 00:00:00 2001 From: Sean Tibor Date: Sat, 4 May 2019 18:00:07 -0400 Subject: [PATCH 2/7] fixed when hide_QR is called before show --- adafruit_pyportal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 4a1b3f9..2b691bd 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -847,7 +847,7 @@ def hide_QR(self): else: try: self._qr_group.pop() - except IndexError: # later test if empty + except IndexError, AttributeError: # later test if empty pass # return a list of lines with wordwrapping From 5249b178dc45a72fc8eb83cd4e04e6435e99219d Mon Sep 17 00:00:00 2001 From: Sean Tibor Date: Sat, 4 May 2019 18:11:29 -0400 Subject: [PATCH 3/7] fixed exception typo --- adafruit_pyportal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 2b691bd..b73f20a 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -847,7 +847,7 @@ def hide_QR(self): else: try: self._qr_group.pop() - except IndexError, AttributeError: # later test if empty + except (IndexError, AttributeError): # later test if empty pass # return a list of lines with wordwrapping From 0fa020cb7166fbf5821f8c16299bcdeeb2cc8c05 Mon Sep 17 00:00:00 2001 From: Sean Tibor Date: Sat, 4 May 2019 18:16:44 -0400 Subject: [PATCH 4/7] good formatting changes --- adafruit_pyportal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index b73f20a..4b50054 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -793,7 +793,7 @@ def show_QR(self, qr_data, qr_size=1, x=0, y=0, clear_background=False): # pyli :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 clear_background: Show the QR code on a black background if True, otherwise put it on top of the existing background. + :param clear_background: Show the QR code on a black background if True. """ import adafruit_miniqr From 81a55518e8846345342daf268d873552f3ef53c2 Mon Sep 17 00:00:00 2001 From: Sean Tibor Date: Mon, 6 May 2019 09:11:45 -0400 Subject: [PATCH 5/7] changed clear_background to hide_background --- adafruit_pyportal.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 4b50054..fe7fed2 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -786,14 +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, clear_background=False): # 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 clear_background: Show the QR code on a black background if True. + :param hide_background: Show the QR code on a black background if True. """ import adafruit_miniqr @@ -832,7 +832,7 @@ def show_QR(self, qr_data, qr_size=1, x=0, y=0, clear_background=False): # pyli self._qr_group.x = x self._qr_group.y = y self._qr_group.append(qr_sprite) - if clear_background: + if hide_background: board.DISPLAY.show(self._qr_group) self._qr_only = True else: From accd991d7c5ab94c247e28679ae9afb9003591df Mon Sep 17 00:00:00 2001 From: Sean Tibor Date: Thu, 9 May 2019 07:32:59 -0400 Subject: [PATCH 6/7] boolean zen change --- adafruit_pyportal.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index fe7fed2..445f4a8 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -834,9 +834,7 @@ def show_QR(self, qr_data, qr_size=1, x=0, y=0, hide_background=False): # pylin self._qr_group.append(qr_sprite) if hide_background: board.DISPLAY.show(self._qr_group) - self._qr_only = True - else: - self._qr_only = False + self._qr_only = hide_background def hide_QR(self): """Clear any QR codes that are currently on the screen From 0eb618a90a98cd7145420317a53b55415ea44de9 Mon Sep 17 00:00:00 2001 From: Sean Tibor Date: Fri, 10 May 2019 07:44:03 -0400 Subject: [PATCH 7/7] linting changes. --- adafruit_pyportal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 445f4a8..f7d2ed5 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -786,7 +786,7 @@ def fetch(self, refresh_url=None): return values[0] return values - def show_QR(self, qr_data, qr_size=1, x=0, y=0, hide_background=False): # 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. @@ -836,7 +836,7 @@ def show_QR(self, qr_data, qr_size=1, x=0, y=0, hide_background=False): # pylin board.DISPLAY.show(self._qr_group) self._qr_only = hide_background - def hide_QR(self): + def hide_QR(self): # pylint: disable=invalid-name """Clear any QR codes that are currently on the screen """