Hello,
I found out what the problem was. I made modification to the code:
rom __future__ import unicode_literals
import cx_Oracle
import ctypes
import uno, unohelper
from com.sun.star.awt import XActionListener
from com.sun.star.awt import ActionEvent
from com.sun.star.lang import EventObject
from com.sun.star.ui.dialogs.ExecutableDialogResults import OK, CANCEL
import msgbox as util
_MY_BUTTON = "btnLogin"
_MY_LABEL = 'Python listens..'
_DLG_PROVIDER = "com.sun.star.awt.DialogProvider"
## Here is the modification to the code - the original def for login was def login():
## you can see the modification below. For some reason during events parameters are fed to any def
##even if non are specified. the parameter with default (embedded=False) is simply a dummy so that
## the code can execute without error
def login(embedded=False):
txtUserId = _ui.getControl("txtUserId").getText()
txtPwd = _ui.getControl("txtPwd").getText()
cbDbSources=_ui.getControl("cbDbSources").getText()
connection = cx_Oracle.connect(user=txtUserId,password=txtPwd,dsn=cbDbSources)
try:
connection.cursor()
connection.close()
MsgBox('success')
except Exception as ex:
MsgBox('fail')
return None
def checkDB():
global _ui
_ui = createUnoDialog("Standard.dlgLogin", embedded=False)
ctl=_ui.getControl(_MY_BUTTON)
#act = ActionListener()
#ctl.addActionListener(act)
_ui.execute()
return None
def createUnoDialog(libr_dlg: str, embedded=False):
ctx = XSCRIPTCONTEXT.getComponentContext()
smgr = ctx.ServiceManager
if embedded:
model = XSCRIPTCONTEXT.getDocument()
dp = smgr.createInstanceWithArguments(_DLG_PROVIDER, (model,))
location = "?location=document"
else:
dp = smgr.createInstanceWithContext(_DLG_PROVIDER, ctx)
location = "?location=application"
return dp.createDialog("vnd.sun.star.script:"+libr_dlg+location)
def MsgBox(txt:str):
mb = util.MsgBox(uno.getComponentContext())
mb.addButton("0k")
mb.show(txt,0, "Python")
return None
It seems that all python def’s require some parameter, even if they are dummy parameters, when they are part of an Assigned Action from an object within a dialog.