diff --git a/oxt/my_first_extension.oxt b/oxt/my_first_extension.oxt new file mode 100644 index 0000000..87629ea Binary files /dev/null and b/oxt/my_first_extension.oxt differ diff --git a/source/my_first_extension/Addons.xcu b/source/my_first_extension/Addons.xcu new file mode 100644 index 0000000..48e3605 --- /dev/null +++ b/source/my_first_extension/Addons.xcu @@ -0,0 +1,33 @@ + + + + + + + My extension + Mi extensión + + + _self + + + + + Say hello + Di hola + + + + + + service:org.examples.zaz.000?argument + + + _self + + + + + + + diff --git a/source/my_first_extension/META-INF/manifest.xml b/source/my_first_extension/META-INF/manifest.xml new file mode 100644 index 0000000..14f491b --- /dev/null +++ b/source/my_first_extension/META-INF/manifest.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/source/my_first_extension/description.xml b/source/my_first_extension/description.xml new file mode 100644 index 0000000..6fcd0c2 --- /dev/null +++ b/source/my_first_extension/description.xml @@ -0,0 +1,12 @@ + + + + + + My first extension + Mi primera extension + + + El Mau + + diff --git a/source/my_first_extension/main.py b/source/my_first_extension/main.py new file mode 100644 index 0000000..b54bbea --- /dev/null +++ b/source/my_first_extension/main.py @@ -0,0 +1,49 @@ +import uno +import unohelper +from com.sun.star.task import XJobExecutor + +from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS +OK = MSG_BUTTONS.BUTTONS_OK + + +ID_EXTENSION = 'org.examples.zaz.000' +SERVICE = ('com.sun.star.task.Job',) + + +CTX = uno.getComponentContext() +SM = CTX.getServiceManager() + + +def create_instance(name, with_context=False): + if with_context: + instance = SM.createInstanceWithContext(name, CTX) + else: + instance = SM.createInstance(name) + return instance + + +def msgbox(message, title='ZAZ Python', buttons=OK, type_msg='infobox'): + """ Create message box + type_msg: infobox, warningbox, errorbox, querybox, messbox + http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1awt_1_1XMessageBoxFactory.html + """ + toolkit = create_instance('com.sun.star.awt.Toolkit') + parent = toolkit.getDesktopWindow() + box = toolkit.createMessageBox(parent, type_msg, buttons, title, str(message)) + return box.execute() + + +class MyFirstExtension(unohelper.Base, XJobExecutor): + + def __init__(self, ctx): + self.ctx = ctx + + # ~ XJobExecutor + def trigger(self, event): + print(event) + msgbox('Dammed World!') + return + + +g_ImplementationHelper = unohelper.ImplementationHelper() +g_ImplementationHelper.addImplementation(MyFirstExtension, ID_EXTENSION, SERVICE) diff --git a/zaz.py b/zaz.py new file mode 100755 index 0000000..e78c507 --- /dev/null +++ b/zaz.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 + +import argparse +import zipfile +import os +from subprocess import call + + +PATH_SOFFICE = 'soffice' +APP_TEST = 'calc' +UNOPKG = ('unopkg', 'add', '-v', '-f', '-s') + + +PATH_SOURCE = 'source' +PATH_TARGET = 'oxt' + + +_join = os.path.join +_abspath = os.path.abspath +_exists = os.path.exists + + +def _make_oxt(name): + path_oxt = _join(PATH_TARGET, f'{name}.oxt') + path_source = _join(PATH_SOURCE, name) + + if not _exists(path_source): + print(f'\tNot found: {path_source}') + return + + print('\tStart compress OXT extension...') + + z = zipfile.ZipFile(path_oxt, 'w', compression=zipfile.ZIP_DEFLATED) + root_len = len(_abspath(path_source)) + for root, dirs, files in os.walk(path_source): + relative = _abspath(root)[root_len:] + for f in files: + fullpath = _join(root, f) + file_name = _join(relative, f) + z.write(fullpath, file_name, zipfile.ZIP_DEFLATED) + z.close() + + print('\tOXT extension created successfully...') + return + + +def _install(name): + path_oxt = _join(PATH_TARGET, f'{name}.oxt') + + if not _exists(path_oxt): + print(f'\tNot found: {path_oxt}') + return + + print('\tStart install extension...') + + call(UNOPKG + (path_oxt,)) + print('\tInstall correctly...') + print(f'\tStart LibreOffice {APP_TEST}') + call((PATH_SOFFICE, f'--{APP_TEST}')) + + print('\tExtension make successfully...') + return + + +def main(args): + print(f'Extension: {args.name}') + + if args.make_oxt: + _make_oxt(args.name) + + if args.install: + _install(args.name) + return + + +def _process_command_line_arguments(): + parser = argparse.ArgumentParser(description='Make LibreOffice extensions') + + parser.add_argument('-m', '--make-oxt', action='store_true', + default=False, required=False) + parser.add_argument('-i', '--install', action='store_true', + default=False, required=False) + parser.add_argument('name') + + args = parser.parse_args() + return args + + +if __name__ == '__main__': + args = _process_command_line_arguments() + main(args)