@@ -279,6 +279,8 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
279
279
print ("No SD card found:" , error )
280
280
281
281
self ._qr_group = None
282
+ # Tracks whether we've hidden the background when we showed the QR code.
283
+ self ._qr_only = False
282
284
283
285
if self ._debug :
284
286
print ("Init caption" )
@@ -795,13 +797,14 @@ def fetch(self, refresh_url=None):
795
797
return values [0 ]
796
798
return values
797
799
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
799
801
"""Display a QR code on the TFT
800
802
801
803
:param qr_data: The data for the QR code.
802
804
:param int qr_size: The scale of the QR code.
803
805
:param x: The x position of upper left corner of the QR code on the display.
804
806
: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.
805
808
806
809
"""
807
810
import adafruit_miniqr
@@ -840,7 +843,21 @@ def show_QR(self, qr_data, qr_size=1, x=0, y=0): # pylint: disable=invalid-name
840
843
self ._qr_group .x = x
841
844
self ._qr_group .y = y
842
845
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
844
861
845
862
# return a list of lines with wordwrapping
846
863
@staticmethod
0 commit comments