Skip to content

Add hide_qr method & clear_background param to show_qr #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions adafruit_pyportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down