Refactorice make code
This commit is contained in:
parent
86c7224b5b
commit
490975b268
Binary file not shown.
|
@ -41,14 +41,34 @@ class Controllers(object):
|
|||
@app.catch_exception
|
||||
def _use_dialog():
|
||||
dlg = _create_dialog()
|
||||
if dlg.open():
|
||||
data = dlg.text.value.strip()
|
||||
type_barcode = dlg.listbox.value
|
||||
if not dlg.open():
|
||||
return
|
||||
|
||||
app.debug(data, type_barcode)
|
||||
data = dlg.text.value.strip()
|
||||
type_code = dlg.listbox.value
|
||||
path = _make_code(type_code, data)
|
||||
app.selection.insert_image(path)
|
||||
app.paths.kill(path)
|
||||
return
|
||||
|
||||
|
||||
def _make_code(type_code, data):
|
||||
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 ''
|
||||
|
||||
return path
|
||||
|
||||
|
||||
def _create_dialog():
|
||||
args = {
|
||||
'Name': 'dialog',
|
||||
|
@ -134,18 +154,7 @@ def _insert_code(type_code):
|
|||
app.errorbox(msg)
|
||||
return
|
||||
|
||||
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
|
||||
path = _make_code(type_code, data)
|
||||
|
||||
sel.offset().insert_image(path)
|
||||
app.paths.kill(path)
|
||||
|
|
Loading…
Reference in New Issue