[Solved] Spin button event listener

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
fdjsklf
Posts: 8
Joined: Fri Feb 18, 2022 8:07 pm

[Solved] Spin button event listener

Post by fdjsklf »

Hello,

I'm trying to make a spin button not only increment an associated cell, but also update another cell to a predetermined value.

I've associated an OpenOffice Basic macro with the event 'after updating', but I haven't been able to get this to work. Running the macro on its own works fine, but it's not being registered as a listener.

Assuming this can work, I was also wondering if it would be possible to determine whether the up or down arrow was pressed, but I can't find any documentation on the specific Event object.

Any ideas?

Thanks
Last edited by Hagar Delest on Sat Feb 19, 2022 12:29 pm, edited 1 time in total.
Reason: Tagged [Solved].
OpenOffice 4.1.5 on Windows 10
fdjsklf
Posts: 8
Joined: Fri Feb 18, 2022 8:07 pm

Re: Spin button event listener

Post by fdjsklf »

I've managed to get the listener to work with the 'mouse release' event, but I'm still trying to figure out how to get more information about the event itself to guide the logic within the macro.
OpenOffice 4.1.5 on Windows 10
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Spin button event listener

Post by JeJe »

https://www.openoffice.org/api/docs/com ... Event.html

Code: Select all

sub eventname(ev)
'ev.buttons etc
end sub
Edit: if its not that mouse events struct, and if it is as well, you should be using MRI which will give you all the information.

https://extensions.openoffice.org/en/pr ... ction-tool
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
fdjsklf
Posts: 8
Joined: Fri Feb 18, 2022 8:07 pm

Re: Spin button event listener

Post by fdjsklf »

Yeah I don't think the first one will have information about the spin button pressed, but I'm not sure.

But the MRI link looks promising--thanks!
OpenOffice 4.1.5 on Windows 10
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Spin button event listener

Post by JeJe »

Its the same struct. Mri gives me this:

(Name) (Value Type) (Value) (AccessMode)
Buttons short 1
ClickCount long 1
Modifiers short 0
PopupTrigger boolean False
Source .uno.XInterface -INTERFACE-
X long 21
Y long 33
One way to find whether the up or down was clicked would be this:

Code: Select all

if ev.y > ev.source.getpossize.height\2 then
'its the lower one
end if
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Spin button event listener

Post by JeJe »

a better way might be:

Code: Select all


global vv

Sub mousedown(ev)
vv= ev.source.value
End Sub

Sub whileadjusting(ev)
'top of spin pressed vv - ev.value = -1 else =1
End Sub

Edit: removed the msgbox line - can be hard to stop those keep popping up.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
fdjsklf
Posts: 8
Joined: Fri Feb 18, 2022 8:07 pm

Re: Spin button event listener

Post by fdjsklf »

Awesome, that worked beautifully, thanks very much
OpenOffice 4.1.5 on Windows 10
fdjsklf
Posts: 8
Joined: Fri Feb 18, 2022 8:07 pm

Re: [Solved] Spin button event listener

Post by fdjsklf »

You know what, this doesn't seem to work as well as I thought. It seems like there's some kind of internal counter to each spin button, and the math is being performed on these, so that when you switch to another button, if the first was incremented twice, incrementing the second button somehow produces a net -1, rather than a +1 for itself, or with decrementing a net +1 instead of a -1. Is there any way around this?

Actually it seems more complicated than that. I'm still trying to figure out what the pattern is.
OpenOffice 4.1.5 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11363
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Spin button event listener

Post by Zizi64 »

Please upload your ODF type sample file together with the embedded macro code.
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.
fdjsklf
Posts: 8
Joined: Fri Feb 18, 2022 8:07 pm

Re: [Solved] Spin button event listener

Post by fdjsklf »

Sure thing, here's a file that replicates the behaviour. I think the macros should be there, but if they aren't, please let me know and I'll try to reupload.
Attachments
test.ods
(10.85 KiB) Downloaded 132 times
OpenOffice 4.1.5 on Windows 10
fdjsklf
Posts: 8
Joined: Fri Feb 18, 2022 8:07 pm

Re: [Solved] Spin button event listener

Post by fdjsklf »

It looks like it might be that the delta measured spans the two inputs when switching.

Okay so I've moved the mouse listener from 'mouse button released' to 'mouse button pressed' and it seems to have resolved the issue. I realized that if the delta is spanning the inputs, then the mouse event must happen after the 'while updating' one, and logically pressed must come before it. If there's a better way to do it, that's great, but at least this seems to work. Thanks for all the help, in any case.
OpenOffice 4.1.5 on Windows 10
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Spin button event listener

Post by JeJe »

Yeah sorry, I should have explicitly said the mousedown sub is for the mouse press not the mouse up.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
fdjsklf
Posts: 8
Joined: Fri Feb 18, 2022 8:07 pm

Re: [Solved] Spin button event listener

Post by fdjsklf »

Oh I'm sure it was partly my fault, as I already had mouse up in mind. Anyway, thanks for the help!
OpenOffice 4.1.5 on Windows 10
Post Reply