libreoffice-extensions-by-e.../source/others_libraries/main.py

54 lines
1.4 KiB
Python

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
import requests
ID_EXTENSION = 'org.examples.zaz.other'
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 Other Libraries', 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 OtherLibraries(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
# ~ XJobExecutor
def trigger(self, event):
print(event)
msg = f'Requests version: {requests.__version__}'
msgbox(msg)
return
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(OtherLibraries, ID_EXTENSION, SERVICE)