Call by code
This commit is contained in:
commit
9e374568fc
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
2
conf.py
2
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'
|
||||
|
|
53
easymacro.py
53
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):
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -5,10 +5,10 @@
|
|||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<identifier value="net.elmau.zaz.BarCode" />
|
||||
<version value="0.5.0" />
|
||||
<version value="0.6.0" />
|
||||
|
||||
<update-download>
|
||||
<src xlink:href="https://gitlab.com/mauriciobaeza/zaz-barcode/raw/master/files/ZAZBarCode_v0.5.0.oxt"/>
|
||||
<src xlink:href="https://gitlab.com/mauriciobaeza/zaz-barcode/raw/master/files/ZAZBarCode_v0.6.0.oxt"/>
|
||||
</update-download>
|
||||
<release-notes>
|
||||
</release-notes>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest:manifest manifest:version="1.2" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
|
||||
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" manifest:version="1.2">
|
||||
<manifest:file-entry manifest:full-path="ZAZBarCode.py" manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
|
||||
<manifest:file-entry manifest:full-path="Office/Accelerators.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
|
||||
<manifest:file-entry manifest:full-path="Addons.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:d="http://openoffice.org/extensions/description/2006">
|
||||
<identifier value="net.elmau.zaz.BarCode" />
|
||||
<version value="0.5.0" />
|
||||
<version value="0.6.0" />
|
||||
<display-name>
|
||||
<name lang="en">ZAZ Bar Code</name>
|
||||
<name lang="es">ZAZ Códigos de Barras</name>
|
||||
|
|
Binary file not shown.
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue