diff --git a/CHANGELOG b/CHANGELOG index 2a0b076..0264444 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +v 0.6.0 [15-nov-2019] +--------------------- + - Call by code + + v 0.5.0 [10-nov-2019] --------------------- - Update library easymacro.py diff --git a/README.md b/README.md index c46c353..d1e7d64 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,11 @@ Barcodes provided * qrcode +Requirements: + +LibreOffice 6.2+ with support for Python macros + + Thanks! https://gitlab.com/mauriciobaeza/zaz @@ -36,9 +41,9 @@ https://github.com/lincolnloop/python-qrcode This extension have a cost of maintenance of 1 euro every year. -BCH: `1RPLWHJW34p7pMQV1ft4x7eWhAYw69Dsb` +BCH: `qztd3l00xle5tffdqvh2snvadkuau2ml0uqm4n875d` -BTC: `3Fe4JuADrAK8Qs7GDAxbSXR8E54avwZJLW` +BTC: `3FhiXcXmAesmQzrNEngjHFnvaJRhU1AGWV` * [Look the wiki](https://gitlab.com/mauriciobaeza/zaz-barcode/wikis/home) diff --git a/VERSION b/VERSION index 8ea2ddf..009695b 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -0.5.0 +0.6.0 diff --git a/conf.py b/conf.py index 6bd2354..9a4b900 100644 --- a/conf.py +++ b/conf.py @@ -26,7 +26,7 @@ import logging TYPE_EXTENSION = 1 # ~ https://semver.org/ -VERSION = '0.5.0' +VERSION = '0.6.0' # ~ Your great extension name, not used spaces NAME = 'ZAZBarCode' diff --git a/easymacro.py b/easymacro.py index df89fbb..30e717e 100644 --- a/easymacro.py +++ b/easymacro.py @@ -34,6 +34,7 @@ import shlex import shutil import socket import subprocess +import ssl import sys import tempfile import threading @@ -268,6 +269,12 @@ def mri(obj): return +def inspect(obj): + zaz = create_instance('net.elmau.zaz.inspect') + zaz.inspect(obj) + return + + def catch_exception(f): @wraps(f) def func(*args, **kwargs): @@ -443,12 +450,14 @@ def call_dispatch(url, args=()): return -def get_temp_file(): +def get_temp_file(only_name=False): delete = True if IS_WIN: delete = False - return tempfile.NamedTemporaryFile(delete=delete) - + tmp = tempfile.NamedTemporaryFile(delete=delete) + if only_name: + tmp = tmp.name + return tmp def _path_url(path): if path.startswith('file://'): @@ -1643,7 +1652,7 @@ class LODrawImpress(LODocument): def insert_image(self, path, **kwargs): w = kwargs.get('width', 3000) - h = kwargs.get('Height', 1000) + h = kwargs.get('Height', 3000) x = kwargs.get('X', 1000) y = kwargs.get('Y', 1000) @@ -2445,23 +2454,23 @@ class UnoBaseObject(object): return self._model.Width @width.setter def width(self, value): - if hasattr(self.obj, 'PosSize'): + if hasattr(self.model, 'Width'): + self.model.Width = value + elif hasattr(self.obj, 'PosSize'): self._set_possize('Width', value) - else: - self._model.Width = value @property def height(self): - if hasattr(self._model, 'Height'): - return self._model.Height + if hasattr(self.model, 'Height'): + return self.model.Height ps = self.obj.getPosSize() return ps.Height @height.setter def height(self, value): - if hasattr(self.obj, 'PosSize'): + if hasattr(self.model, 'Height'): + self.model.Height = value + elif hasattr(self.obj, 'PosSize'): self._set_possize('Height', value) - else: - self._model.Height = value @property def tag(self): @@ -4206,8 +4215,12 @@ def json_loads(data): def get_path_extension(id): + path = '' pip = CTX.getValueByName('/singletons/com.sun.star.deployment.PackageInformationProvider') - path = _path_system(pip.getPackageLocation(id)) + try: + path = _path_system(pip.getPackageLocation(id)) + except Exception as e: + error(e) return path @@ -4404,23 +4417,29 @@ def popen(command, stdin=None): yield (e.errno, e.strerror) -def url_open(url, options={}, json=False): +def url_open(url, options={}, verify=True, json=False): data = '' + err = '' req = Request(url) try: - response = urlopen(req) - # ~ response.info() + if verify: + response = urlopen(req) + else: + context = ssl._create_unverified_context() + response = urlopen(req, context=context) except HTTPError as e: error(e) + err = str(e) except URLError as e: error(e.reason) + err = str(e.reason) else: if json: data = json_loads(response.read()) else: data = response.read() - return data + return data, err def run(command, wait=False): diff --git a/files/ZAZBarCode_v0.1.0.oxt b/files/ZAZBarCode_v0.1.0.oxt deleted file mode 100644 index ec1f8a0..0000000 Binary files a/files/ZAZBarCode_v0.1.0.oxt and /dev/null differ diff --git a/files/ZAZBarCode_v0.2.0.oxt b/files/ZAZBarCode_v0.2.0.oxt deleted file mode 100644 index 3e0dc38..0000000 Binary files a/files/ZAZBarCode_v0.2.0.oxt and /dev/null differ diff --git a/files/ZAZBarCode_v0.2.1.oxt b/files/ZAZBarCode_v0.2.1.oxt deleted file mode 100644 index 21c5190..0000000 Binary files a/files/ZAZBarCode_v0.2.1.oxt and /dev/null differ diff --git a/files/ZAZBarCode_v0.3.0.oxt b/files/ZAZBarCode_v0.3.0.oxt deleted file mode 100644 index 492ab05..0000000 Binary files a/files/ZAZBarCode_v0.3.0.oxt and /dev/null differ diff --git a/files/ZAZBarCode_v0.4.0.oxt b/files/ZAZBarCode_v0.4.0.oxt deleted file mode 100644 index bfc2a4e..0000000 Binary files a/files/ZAZBarCode_v0.4.0.oxt and /dev/null differ diff --git a/files/ZAZBarCode_v0.5.0.oxt b/files/ZAZBarCode_v0.6.0.oxt similarity index 85% rename from files/ZAZBarCode_v0.5.0.oxt rename to files/ZAZBarCode_v0.6.0.oxt index 210cfba..3ca7495 100644 Binary files a/files/ZAZBarCode_v0.5.0.oxt and b/files/ZAZBarCode_v0.6.0.oxt differ diff --git a/files/zazbarcode.update.xml b/files/zazbarcode.update.xml index dc83af5..0893f42 100644 --- a/files/zazbarcode.update.xml +++ b/files/zazbarcode.update.xml @@ -5,10 +5,10 @@ xmlns:xlink="http://www.w3.org/1999/xlink"> - + - + diff --git a/source/META-INF/manifest.xml b/source/META-INF/manifest.xml index c5251c4..b723309 100644 --- a/source/META-INF/manifest.xml +++ b/source/META-INF/manifest.xml @@ -1,5 +1,5 @@ - + diff --git a/source/ZAZBarCode.py b/source/ZAZBarCode.py index 9659bc0..bb514eb 100644 --- a/source/ZAZBarCode.py +++ b/source/ZAZBarCode.py @@ -44,29 +44,32 @@ class Controllers(object): class ZAZBarCode(unohelper.Base, XJob, XJobExecutor): - IMAGES = 'images' def __init__(self, ctx): self.ctx = ctx self._data = '' self._type = '' self._ask = False - self.path_ext = app.get_path_extension(ID_EXTENSION) - self.IMAGES = app.join(self.path_ext, self.IMAGES) + self._path = '' def execute(self, args): data = app.property_to_dict(args) + self._type = data['Type'].lower() + self._data = data['Data'] - if data['Type'] == QR: - factory = svg.SvgImage - img = qrcode.make(data['Data'], image_factory=factory) - img.save(data['Path']) + if 'Path' in data: + if not self._type == QR: + p, _, n, _ = app.get_info_path(data['Path']) + data['Path'] = app.join(p, n) else: - try: - generate(data['Type'].lower(), data['Data'], output=data['Path']) - except Exception as e: - app.debug(str(e)) - return + data['Path'] = '' + + result = self._create_code(data['Path']) + if result: + app.error(result) + self._path = '' + + return self._path def trigger(self, args): self._type = args @@ -75,21 +78,25 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor): doc = app.get_document() getattr(self, '_insert_in_{}'.format(doc.type))(doc) + app.kill(self._path) return - def _create_code(self, tmp_file): + def _create_code(self, path=''): + if not path: + path = app.get_temp_file(True) if self._type == QR: factory = svg.SvgImage - img = qrcode.make(self._data, image_factory=factory) - img.save(tmp_file.name) + img = qrcode.make(self._data, border=2, image_factory=factory) + img.save(path) else: try: - generate(self._type, self._data, output=tmp_file) + path = generate(self._type, self._data, output=path) except Exception as e: app.error(e) return str(e) - if app.is_created(tmp_file.name): + if app.is_created(path): + self._path = path return '' return _('Not generated') @@ -114,57 +121,42 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor): self._show_error(msg) return - tf = app.get_temp_file() - result = self._create_code(tf) + result = self._create_code() if result: - tf.close() self._show_error(result) return if not self._ask: cell = cell.offset(0, 1) - if app.IS_WIN: - tf.close() - cell.insert_image(tf.name) - tf.close() + cell.insert_image(self._path) return def _insert_in_writer(self, doc): doc = app.get_document() - sel = app.get_selection() if not self._data: + sel = app.get_selection() self._data = sel.string if not self._data: msg = _('Select data') self._show_error(msg) return - tf = app.get_temp_file() - result = self._create_code(tf) + result = self._create_code() if result: - tf.close() self._show_error(result) return - if app.IS_WIN: - tf.close() - doc.insert_image(tf.name) - tf.close() + doc.insert_image(self._path) return def _insert_in_draw(self, doc): - tf = app.get_temp_file() - result = self._create_code(tf) + result = self._create_code() if result: - tf.close() self._show_error(result) return - if app.IS_WIN: - tf.close() - doc.insert_image(tf.name) - tf.close() + doc.insert_image(self._path) return def _insert_in_impress(self, doc): @@ -186,6 +178,7 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor): } dlg = app.create_dialog(args) dlg.events = Controllers(dlg) + dlg.id_extension = ID_EXTENSION args = { 'Type': 'Label', @@ -238,7 +231,7 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor): 'Label': _('~Insert Barcode'), 'Width': 70, 'Height': 15, - 'ImageURL': app.join(self.IMAGES, 'qr.png'), + 'ImageURL': 'qr.png', 'ImagePosition': 1, } dlg.add_control(args) diff --git a/source/description.xml b/source/description.xml index d56f0d4..6d95b82 100644 --- a/source/description.xml +++ b/source/description.xml @@ -1,7 +1,7 @@ - + ZAZ Bar Code ZAZ Códigos de Barras diff --git a/source/locales/eo/LC_MESSAGES/base.mo b/source/locales/eo/LC_MESSAGES/base.mo index d58bbe8..391719e 100644 Binary files a/source/locales/eo/LC_MESSAGES/base.mo and b/source/locales/eo/LC_MESSAGES/base.mo differ diff --git a/source/locales/eo/LC_MESSAGES/base.po b/source/locales/eo/LC_MESSAGES/base.po index 1445617..0e5812a 100644 --- a/source/locales/eo/LC_MESSAGES/base.po +++ b/source/locales/eo/LC_MESSAGES/base.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "POT-Creation-Date: 2019-11-10 15:06-0600\n" -"PO-Revision-Date: 2019-11-10 15:26-0600\n" +"PO-Revision-Date: 2019-11-12 13:30-0600\n" "Last-Translator: \n" "Language-Team: \n" "Language: eo\n" @@ -27,7 +27,7 @@ msgstr "Datumkampo estas deviga" #: source/ZAZBarCode.py:91 msgid "Not generated" -msgstr "Ne generita" +msgstr "Ne eligata" #: source/ZAZBarCode.py:109 source/ZAZBarCode.py:135 msgid "Select data" diff --git a/source/pythonpath/barcode/__init__.py b/source/pythonpath/barcode/__init__.py index 0c2592d..427d094 100644 --- a/source/pythonpath/barcode/__init__.py +++ b/source/pythonpath/barcode/__init__.py @@ -19,11 +19,6 @@ from barcode.upc import UPCA from barcode.itf import ITF from barcode.version import version # noqa: F401 -try: - _strbase = basestring # lint:ok -except NameError: - _strbase = str - __BARCODE_MAP = dict( ean8=EAN8, @@ -73,7 +68,7 @@ def generate(name, code, writer=None, output=None, writer_options=None, barcode = get(name, code, writer, options) if pil: return barcode.render(writer_options, text) - if isinstance(output, _strbase): + if isinstance(output, str): fullname = barcode.save(output, options, text) return fullname else: diff --git a/source/pythonpath/easymacro.py b/source/pythonpath/easymacro.py index df89fbb..30e717e 100644 --- a/source/pythonpath/easymacro.py +++ b/source/pythonpath/easymacro.py @@ -34,6 +34,7 @@ import shlex import shutil import socket import subprocess +import ssl import sys import tempfile import threading @@ -268,6 +269,12 @@ def mri(obj): return +def inspect(obj): + zaz = create_instance('net.elmau.zaz.inspect') + zaz.inspect(obj) + return + + def catch_exception(f): @wraps(f) def func(*args, **kwargs): @@ -443,12 +450,14 @@ def call_dispatch(url, args=()): return -def get_temp_file(): +def get_temp_file(only_name=False): delete = True if IS_WIN: delete = False - return tempfile.NamedTemporaryFile(delete=delete) - + tmp = tempfile.NamedTemporaryFile(delete=delete) + if only_name: + tmp = tmp.name + return tmp def _path_url(path): if path.startswith('file://'): @@ -1643,7 +1652,7 @@ class LODrawImpress(LODocument): def insert_image(self, path, **kwargs): w = kwargs.get('width', 3000) - h = kwargs.get('Height', 1000) + h = kwargs.get('Height', 3000) x = kwargs.get('X', 1000) y = kwargs.get('Y', 1000) @@ -2445,23 +2454,23 @@ class UnoBaseObject(object): return self._model.Width @width.setter def width(self, value): - if hasattr(self.obj, 'PosSize'): + if hasattr(self.model, 'Width'): + self.model.Width = value + elif hasattr(self.obj, 'PosSize'): self._set_possize('Width', value) - else: - self._model.Width = value @property def height(self): - if hasattr(self._model, 'Height'): - return self._model.Height + if hasattr(self.model, 'Height'): + return self.model.Height ps = self.obj.getPosSize() return ps.Height @height.setter def height(self, value): - if hasattr(self.obj, 'PosSize'): + if hasattr(self.model, 'Height'): + self.model.Height = value + elif hasattr(self.obj, 'PosSize'): self._set_possize('Height', value) - else: - self._model.Height = value @property def tag(self): @@ -4206,8 +4215,12 @@ def json_loads(data): def get_path_extension(id): + path = '' pip = CTX.getValueByName('/singletons/com.sun.star.deployment.PackageInformationProvider') - path = _path_system(pip.getPackageLocation(id)) + try: + path = _path_system(pip.getPackageLocation(id)) + except Exception as e: + error(e) return path @@ -4404,23 +4417,29 @@ def popen(command, stdin=None): yield (e.errno, e.strerror) -def url_open(url, options={}, json=False): +def url_open(url, options={}, verify=True, json=False): data = '' + err = '' req = Request(url) try: - response = urlopen(req) - # ~ response.info() + if verify: + response = urlopen(req) + else: + context = ssl._create_unverified_context() + response = urlopen(req, context=context) except HTTPError as e: error(e) + err = str(e) except URLError as e: error(e.reason) + err = str(e.reason) else: if json: data = json_loads(response.read()) else: data = response.read() - return data + return data, err def run(command, wait=False):