50 lines
1.3 KiB
Python
50 lines
1.3 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
|
|
|
|
|
|
ID_EXTENSION = 'org.examples.zaz.001'
|
|
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 001', 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 MyExample001(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(MyExample001, ID_EXTENSION, SERVICE)
|