Using APSO to embed scripts in python, how to import functions from one module to another?
I have two modules, one named ‘other_module’ , with this content:
# coding: utf-8
import getpass
def get_username():
return getpass.getuser()
And a module named ‘Main_Module’, with this content:
# -*- coding: UTF-8 -*-
from __future__ import unicode_literals
import uno
from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS
import other_module
CTX = XSCRIPTCONTEXT.getComponentContext()
SM = CTX.ServiceManager
def create_instance(name, with_context=False):
if with_context:
instance = SM.createInstanceWithContext(name, CTX)
else:
instance = SM.createInstance(name)
return instance
def msg(message, title='LibreOffice', buttons=MSG_BUTTONS.BUTTONS_OK, type_msg='INFOBOX'):
toolkit = create_instance('com.sun.star.awt.Toolkit')
parent = toolkit.getDesktopWindow()
mb = toolkit.createMessageBox(parent, type_msg, buttons, title, str(message)+'\n\n')
return mb.execute()
def show_info(*args):
infoText = other_module.get_username()
#infoText = 'hello'
result = msg(infoText, 'Title', 1, 'INFOBOX')
return
how do I call the get_username() function of the ‘other_module’ module, through the ‘Main_Module’?
Here is an example file
test.ods (9,3,KB)