I am trying to rewrite some basic macros in Python. Right now I am experimenting with using a dialog designed in basic dialog editor in a Python macro. I have found some code I adapted to use an ActionListener to respond to one button on the dialog but am completely lost on how to use a second button on the same dialog.
Could anyone poiint me to a code example that demonstrates this type of usage?
Thanks, Jim
Looking for an example in Python for a 2-button dialog
Looking for an example in Python for a 2-button dialog
OpenOffice 3.2 on Ubuntu
Re: Looking for an example in Python for a 2-button dialog
Strange request.
Download Grammalecte here:
https://grammalecte.net/#download
Have a look in TextFormatter.py, you should find what you need.
Download Grammalecte here:
https://grammalecte.net/#download
Have a look in TextFormatter.py, you should find what you need.
Last edited by OlivierR on Tue Jun 11, 2019 9:22 am, edited 1 time in total.
LibreOffice 6.4 • Windows 10
Re: Looking for an example in Python for a 2-button dialog
Thanks. Looking at TextFormatter.py allowed me to get both buttons working.
I am curious about what seemed strange in the request.
Thanks again, Jim
I am curious about what seemed strange in the request.
Thanks again, Jim
OpenOffice 3.2 on Ubuntu
Re: Looking for an example in Python for a 2-button dialog
I was just wondering what might prevent you to do one more time what you succeeded to do once. I thought it was possibly related to widget naming but it seemed too obvious.
BTW, I’m interested to try dialog design by editor and controlling it via Python. Do you have some code to publish about that?
BTW, I’m interested to try dialog design by editor and controlling it via Python. Do you have some code to publish about that?
LibreOffice 6.4 • Windows 10
Re: Looking for an example in Python for a 2-button dialog
viewtopic.php?f=20&t=66391&p=295703&hil ... ON#p295691 relates to an xdl file of an extension. A simple file:///path/dialog.xdl may work as well.cleanman2 wrote:Could anyone poiint me to a code example that demonstrates this type of usage?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Looking for an example in Python for a 2-button dialog
Well that is pretty close to being true. All of the examples I was finding only had one button and I could not tell from them how to identify individual buttons to attach code to their events. Until I saw your code I did not know about setActionCommand() and ActionCommand after that it all made sense.
I was just wondering what might prevent you to do one more time what you succeeded to do once. I thought it was possibly related to widget naming but it seemed too obvious.
My code is far from done but this minimal example will pop up a dialog and take action depending on which button is clicked. The dialog (in this case enter_pmts.dialog) was designed in the dialog portion of the basic IDE and saved with the spreadsheet in which it will be used. You can look up the various properties in the IDE and use them in your Python code.
Code: Select all
class ButtonListen( unohelper.Base, XActionListener ):
def __init__(self, oControl, oButton, oDialog):
self.textField = oControl
self.button = oButton
self.dialog = oDialog
#actionPerformed not to be renamed
def actionPerformed(self, XActionEvent): # actionEvent)
if XActionEvent.ActionCommand == 'OK':
omsgbox(self.textField.getText())
elif XActionEvent.ActionCommand == 'Cancel':
self.dialog.endExecute()
def test_dlg():
doc = XSCRIPTCONTEXT.getDocument()
ctx = XSCRIPTCONTEXT.getComponentContext()
sm = ctx.ServiceManager
dp = sm.createInstanceWithArgumentsAndContext(
"com.sun.star.awt.DialogProvider", (doc, ), ctx)
dlg = dp.createDialog("vnd.sun.star.script:Standard.enter_pmts_dialog?location=document")
textField1_ctrl = dlg.getControl('textField1')
ok_btn_ctrl = dlg.getControl('ok_Btn')
ok_btn_listener = ButtonListen(textField1_ctrl, ok_btn_ctrl, dlg)
ok_btn_ctrl.addActionListener(ok_btn_listener)
ok_btn_ctrl.setActionCommand('OK')
cancel_btn_ctrl = dlg.getControl('cancel_Btn')
cancel_btn_listener = ButtonListen(textField1_ctrl, cancel_btn_ctrl, dlg)
cancel_btn_ctrl.addActionListener(cancel_btn_listener)
cancel_btn_ctrl.setActionCommand('Cancel')
dlg.execute()
dlg.dispose()
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
#shows message. Used for debugging
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, Rectangle(), oMsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
OpenOffice 3.2 on Ubuntu