diff --git a/files/ZAZBarCode_v0.7.0.oxt b/files/ZAZBarCode_v0.7.0.oxt index 450b679..9636a9b 100644 Binary files a/files/ZAZBarCode_v0.7.0.oxt and b/files/ZAZBarCode_v0.7.0.oxt differ diff --git a/source/ZAZBarCode.py b/source/ZAZBarCode.py index 80f3e65..8175b1e 100644 --- a/source/ZAZBarCode.py +++ b/source/ZAZBarCode.py @@ -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=''): diff --git a/source/pythonpath/main.py b/source/pythonpath/main.py index f2fa222..e45cf52 100644 --- a/source/pythonpath/main.py +++ b/source/pythonpath/main.py @@ -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 _