From bfffab0b19a4fa10a4ac08ee89aab5db062286e1 Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Sat, 17 Jul 2021 12:58:11 -0500 Subject: [PATCH] First most basic example --- oxt/my_first_extension.oxt | Bin 0 -> 1998 bytes source/my_first_extension/Addons.xcu | 33 +++++++ .../my_first_extension/META-INF/manifest.xml | 5 + source/my_first_extension/description.xml | 12 +++ source/my_first_extension/main.py | 49 ++++++++++ zaz.py | 91 ++++++++++++++++++ 6 files changed, 190 insertions(+) create mode 100644 oxt/my_first_extension.oxt create mode 100644 source/my_first_extension/Addons.xcu create mode 100644 source/my_first_extension/META-INF/manifest.xml create mode 100644 source/my_first_extension/description.xml create mode 100644 source/my_first_extension/main.py create mode 100755 zaz.py diff --git a/oxt/my_first_extension.oxt b/oxt/my_first_extension.oxt new file mode 100644 index 0000000000000000000000000000000000000000..87629ea9963ef5b9c5cd33fb492573731077fc49 GIT binary patch literal 1998 zcmZ`)c{mj69v;k)B^*+g$&&SAEZHVRGa1`FGe&1dab*c71|za(X$%et(-^W#!$Bh3 z5E&ImmXUo+mO5oE>)2K9bnbnwp8Isa?~mW}`=0Op=Y4-r_B z5T-nt0{~D40RVjLSD3rIAK|7(s9R7mbqY<=5|8f-5kvJ^WaW!i)`5H3&q?hC39WVdYja8`Lg&41Bhv() ztUt-yHVY`y}p+ zFB*e)0_|E(>TeZD)#LBb$_{7p(SOCPL1218EFPqj-~{h8U?^SLer- z=F59zl;>4qC5Kz1B%PdBQ+V^ zZv6Hd+6Jd2wMM@vC4!)|?ozhp#$#9mF%oZ2db`j*L3=oQuFdVC+ni%VX*o5Sdf9y? zQQ1oRjLHeO{P~DHlm0nV??-oq6OU)!hQ!EUE|#b2c8T}kt0aw|l^cn|F)gh#ho+V< zGr;w>q-lJRk+|NALCcC_1qTQRv2bM8+#%3}JddIr!Vb*js|9&(EEza$6dV*K%Sc8F z5mp=Gv73Su5ZMBeC9NvMN8}bAVdw%3(e#YT0g`G~a$Hfwg0cjMC8 zj9p<*I}e*RUso@J#*MIKEb3;CmN0{*HoOVw(FzE7eOHL?);`DOJHu?C}d2w$7+IONj@ zyP2)ALm!!gu*$9hc<(`lr0*$^A%Gp z4s)*=0QR=V5FaMNJ++Q8LeT_1{FHX)^{iG$mF{UE#F&&@%ngK}5gRB!!KtX4FrM@$ ziei}m9!ovh`p?t>Wfp&dPH;;8?I`iSMz_4JdJ8z167Yrk>o|;9dYD>t(U8nBDG_vc zMXk)IdK86e+%pqU%+T5_Xfdvqxi#rIYvHqOuJ1UR7VUfy{-973SIN7yqvv$>YPJ84 z-)NflhIE?oJA!>GEtr>9q}pU8PD6zp)N<9X5+JY7wR2auoE9*Hg#BZTJ1~F96YAwk zUK|#5w-Xfj$Yph2r_qwAOP*9PP#~?yD%L5N)tt9ewn8JU`KDRN?Pd!zR?I4x6=wL) z2gHNbxZe93qam*=?~KHKwR?21BQVGt{{xu&lx!Rt4Vn}Oe5pMDQTXp?2T-UM{bZ!#EX zYh>%!uO=%FR>*{XG2327<{A2r;DTQ?vrX@6togE5t?2VH&yq z>eBb?jp<>jZO>PYf@UyC4$c!?|9_dWdHVYl5xqA r@Xs>k2)x2hn*SuskD#B)c?2qDN7GNm#UMf4-@gIbcbQ$8e|P@^ybWaJ literal 0 HcmV?d00001 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)