2017-08-15 20:24:38 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
import qrcode
|
|
|
|
|
|
|
|
|
|
|
|
class AssetQRCode(qrcode.QRCode):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def make_new_asset_qr(self, data) -> qrcode.image:
|
2017-08-15 21:30:11 +03:00
|
|
|
self.clear()
|
2017-08-15 20:24:38 +03:00
|
|
|
self.add_data(data)
|
|
|
|
return self.make_image()
|
|
|
|
|
|
|
|
def make_new_model_qr(self, data) -> qrcode.image:
|
2017-08-15 21:30:11 +03:00
|
|
|
self.clear()
|
2017-08-15 20:24:38 +03:00
|
|
|
self.add_data(data)
|
|
|
|
return self.make_image()
|
|
|
|
|
|
|
|
def save(self, file_name, data):
|
|
|
|
desktop = os.path.expanduser('~/Desktop')
|
2017-08-18 04:24:18 +03:00
|
|
|
full_path = os.path.join(desktop, '{}.png'.format(file_name))
|
|
|
|
self.prevent_duplicate_file(full_path)
|
|
|
|
with open(full_path, 'wb') as fp:
|
2017-08-15 20:24:38 +03:00
|
|
|
return self.make_new_asset_qr(data).save(fp)
|
|
|
|
|
|
|
|
def display(self, data):
|
|
|
|
img = self.make_new_asset_qr(data)
|
|
|
|
img.show()
|
|
|
|
|
|
|
|
def prevent_duplicate_file(self, file):
|
|
|
|
if os.path.exists(file):
|
2017-08-18 04:24:18 +03:00
|
|
|
raise FileExistsError
|