54 lines
934 B
Python
54 lines
934 B
Python
#!/usr/bin/env python3
|
|
|
|
import easymacro as app
|
|
import qrcode
|
|
import qrcode.image.svg as svg
|
|
from barcode import generate
|
|
|
|
|
|
ID_EXTENSION = ''
|
|
_ = None
|
|
|
|
TITLE = 'ZAZ BarCode'
|
|
QR = 'qrcode'
|
|
|
|
|
|
def _use_dialog():
|
|
print('dialog')
|
|
return
|
|
|
|
|
|
@app.catch_exception
|
|
def _insert_code(type_code):
|
|
sel = app.selection
|
|
data = sel.value
|
|
path = app.paths.tmp()
|
|
|
|
if type_code == QR:
|
|
factory = svg.SvgImage
|
|
img = qrcode.make(data, border=2, image_factory=factory)
|
|
img.save(path)
|
|
else:
|
|
try:
|
|
generate(type_code, data, output=open(path, 'wb'))
|
|
except Exception as e:
|
|
app.errorbox(e)
|
|
return
|
|
|
|
sel.offset().insert_image(path)
|
|
app.paths.kill(path)
|
|
return
|
|
|
|
|
|
def run(args, path_locales):
|
|
global _
|
|
|
|
_ = app.install_locales(path_locales)
|
|
|
|
if args == 'used_dialog':
|
|
_use_dialog()
|
|
else:
|
|
_insert_code(args)
|
|
|
|
return
|