def show(self, delete_after=20, scale=10, border=None, color='#000',
background='#fff'): # pragma: no cover
"""\
Displays this QR code.
This method is mainly intended for debugging purposes.
This method saves the output of the :py:meth:`png` method (by default
with a scaling factor of 10) to a temporary file and opens it with the
standard PNG viewer application or within the standard webbrowser.
The temporary file is deleted afterwards (unless `delete_after` is set
to ``None``).
If this method does not show any result, try to increase the
`delete_after` value or set it to ``None``
:param delete_after: Time in seconds to wait till the temporary file is
deleted.
"""
import os
import time
import tempfile
import webbrowser
import threading
try: # Python 2
from urlparse import urljoin
from urllib import pathname2url
except ImportError: # Python 3
from urllib.parse import urljoin
from urllib.request import pathname2url
def delete_file(name):
time.sleep(delete_after)
try:
os.unlink(name)
except OSError:
pass
f = tempfile.NamedTemporaryFile('wb', suffix='.png', delete=False)
try:
self.save(f, scale=scale, color=color, background=background,
border=border)
except:
f.close()
os.unlink(f.name)
raise
f.close()
webbrowser.open_new_tab(urljoin('file:', pathname2url(f.name)))
if delete_after is not None:
t = threading.Thread(target=delete_file, args=(f.name,))
t.start()
评论列表
文章目录