Skip to content

Commit 763d5a3

Browse files
authored
Merge pull request #32 from seantibor/master
Add hide_qr method & clear_background param to show_qr
2 parents b94fcde + 0eb618a commit 763d5a3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

adafruit_pyportal.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
279279
print("No SD card found:", error)
280280

281281
self._qr_group = None
282+
# Tracks whether we've hidden the background when we showed the QR code.
283+
self._qr_only = False
282284

283285
if self._debug:
284286
print("Init caption")
@@ -795,13 +797,14 @@ def fetch(self, refresh_url=None):
795797
return values[0]
796798
return values
797799

798-
def show_QR(self, qr_data, qr_size=1, x=0, y=0): # pylint: disable=invalid-name
800+
def show_QR(self, qr_data, *, qr_size=1, x=0, y=0, hide_background=False): # pylint: disable=invalid-name
799801
"""Display a QR code on the TFT
800802
801803
:param qr_data: The data for the QR code.
802804
:param int qr_size: The scale of the QR code.
803805
:param x: The x position of upper left corner of the QR code on the display.
804806
:param y: The y position of upper left corner of the QR code on the display.
807+
:param hide_background: Show the QR code on a black background if True.
805808
806809
"""
807810
import adafruit_miniqr
@@ -840,7 +843,21 @@ def show_QR(self, qr_data, qr_size=1, x=0, y=0): # pylint: disable=invalid-name
840843
self._qr_group.x = x
841844
self._qr_group.y = y
842845
self._qr_group.append(qr_sprite)
843-
board.DISPLAY.show(self._qr_group)
846+
if hide_background:
847+
board.DISPLAY.show(self._qr_group)
848+
self._qr_only = hide_background
849+
850+
def hide_QR(self): # pylint: disable=invalid-name
851+
"""Clear any QR codes that are currently on the screen
852+
"""
853+
854+
if self._qr_only:
855+
board.DISPLAY.show(self.splash)
856+
else:
857+
try:
858+
self._qr_group.pop()
859+
except (IndexError, AttributeError): # later test if empty
860+
pass
844861

845862
# return a list of lines with wordwrapping
846863
@staticmethod

0 commit comments

Comments
 (0)