Refactory insert barcode in Calc
This commit is contained in:
parent
f410bf3d19
commit
e5b37216ba
Binary file not shown.
|
@ -5,18 +5,8 @@ from com.sun.star.task import XJobExecutor, XJob
|
|||
import main
|
||||
|
||||
|
||||
import easymacro as app
|
||||
|
||||
import qrcode
|
||||
import qrcode.image.svg as svg
|
||||
from barcode import generate
|
||||
|
||||
|
||||
ID_EXTENSION = 'net.elmau.zaz.BarCode'
|
||||
SERVICE = ('com.sun.star.task.Job',)
|
||||
TITLE = 'ZAZ BarCode'
|
||||
QR = 'qrcode'
|
||||
|
||||
|
||||
|
||||
class Controllers(object):
|
||||
|
@ -75,13 +65,6 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor):
|
|||
def trigger(self, args):
|
||||
main.ID_EXTENSION = ID_EXTENSION
|
||||
main.run(args, __file__)
|
||||
# ~ self._type = args
|
||||
# ~ if args == 'ask' and not self._get_values():
|
||||
# ~ return
|
||||
|
||||
# ~ doc = app.get_document()
|
||||
# ~ getattr(self, '_insert_in_{}'.format(doc.type))(doc)
|
||||
# ~ app.kill(self._path)
|
||||
return
|
||||
|
||||
def _create_code(self, path=''):
|
||||
|
|
|
@ -1,23 +1,45 @@
|
|||
#!/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):
|
||||
print(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
|
||||
|
||||
|
||||
@app.catch_exception
|
||||
def run(args, path_locales):
|
||||
global _
|
||||
|
||||
|
|
Loading…
Reference in New Issue