Trigger radio button event from macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
edhannahs
Posts: 9
Joined: Mon Aug 22, 2016 1:57 am

Trigger radio button event from macro

Post by edhannahs »

I have 15 radio groups on a spreadsheet. They are named mgrp 1 ... mgrp 15. They all call the same macro, set_medals(oevent), which uses the oevent to determine which group was activated and different things happen based on the name of the group. Each radio group has 3 radio button controls. Everything works as desired. My problem comes with a reset button. I want the macro triggered by the reset button, reset_grps(oevent), to set all 15 radio groups to the first option in the group and to perform the same action that a manual change of each group would. I've got the first part done. I can change all of the groups to the first option. I hoped that would trigger the executed event for the various radio groups but it did not. So now I am trying to add code that either triggers the event or calls the set_medals macro with the proper oevent. I haven't been able to figure out how to do either method. I have a ctrl variable containing the control I am trying to activate. I have done

ctrl.state = 1.

I need something like
execute(ctrl) or
oevent = ctrl.execute
call set_medals(oevent) or
oevent.changed = true which hopefully would trigger a changed event. I found a statement that seemed to claim that events could be triggered by event handlers but it was not demonstrated.

Is something like this possible? using oo basic
openoffice 4.1.2 on windows 10
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: trigger radio button event from macro

Post by Zizi64 »

You must get the objects by their names (or by they numbers) but not by the oEvent. The oEvent can get one object only.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
edhannahs
Posts: 9
Joined: Mon Aug 22, 2016 1:57 am

Re: trigger radio button event from macro

Post by edhannahs »

Thanks for the reply. I am already getting the controls by name. The push button event triggers reset_grps which then loops through the 15 controls one at a time, resetting them one at a time. But for each control within the loop, can I fire an execute or change event from within the reser_grps macro or can I set an event variable equal to something that represents the ctrl execute event without that event having been executed. The key is whether or not it is possible to trigger (or fire) an event from within a macro having already set a ctrl variable to the radio button control. Or alternatively can I set an oevent variable to an event that has not occurred. Or is there some property of the control I can change within my macro that would trigger the controls change event. I can work around it but I'd really like to know if it is possible.
openoffice 4.1.2 on windows 10
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: trigger radio button event from macro

Post by Zizi64 »

Can you upload an example ODF file with the macro code here?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
edhannahs
Posts: 9
Joined: Mon Aug 22, 2016 1:57 am

Re: trigger radio button event from macro

Post by edhannahs »

I've attached a file. Tried to strip out unrelated material and hope it is not too much.

Observe radio groups in column AG. Except for name they are all the same except the first group has the first button call the macro on a change event instead of execute event. All others use execute event. The first one was just to see if it made a difference.

Select one of the buttons in a couple of the groups and observe the changes in columns AD and AE.

The clearscores command button calls the macro clearscores(oevent) which sets some parameters and calls sub reset_chkbox_grps(oevent,baseName,nstart,nfinish).

Line 57 of the code changes the state of one of the groups to 1 for the first button in the group. I had hoped that would trigger an event for that group but it does not.

line 58, which is now commented out, was an attempt to set the changed property to true to trigger the event but that wasn't a valid property.

line 60 , which is now commented out, was an attempt to call the macro directly but I need to pass either a change or execute event instead of the control and I don't know how to refer to it or if it is possible to refer to it. Was hoping for something like
oevent = execute(control) or oevent = control.execute followed by call set_medals(oevent)
Attachments
event_from_macro.ods
(23.07 KiB) Downloaded 343 times
openoffice 4.1.2 on windows 10
Post Reply