Coding: Radio Buttons don't work

Hi,

I use always the same mechanism to add radio buttons by code. Usually I add one after one, directly after each other, and they get grouped automatically. But this time I can choose more than one and the others don't get disabled. (See screenshot)

I know, it's better to show some code, but it would be a bit too much, as the creation of widgets is splitted into several steps.

My questions are:
- Is there a mechanism to group radio buttons by code instead of adding them one directly after the other?
- Can someone guess, what else can go wrong?

Regards,
Xaver

Screenshot can be found here:

https://github.com/XRoemer/Organon/blob/master/Screenshots/radio%20buttons%20dont%20work.png

Hi Johnny,

thanks for your reply.

Usually my radio buttons are working. Just in this case, they don't. - And all of them had the same listener.
But I discovered that I can get them working, when I don't set all of the buttons, labels etc. in one loop. I seperated the radio buttons and set them in an extra loop. Now they are working again.

That doesn't make much sense to me, but at least it works.

2015-05-16 13:08 GMT+02:00 Johnny Rosenberg <gurus.knugum@gmail.com <mailto:gurus.knugum@gmail.com>>:

    2015-05-16 8:59 GMT+02:00 X Roemer <x-roemer@web.de
    <mailto:x-roemer@web.de>>:

        Hi,

        I use always the same mechanism to add radio buttons by code.
        Usually I add one after one, directly after each other, and they
        get grouped automatically. But this time I can choose more than
        one and the others don't get disabled. (See screenshot)

        I know, it's better to show some code, but it would be a bit too
        much, as the creation of widgets is splitted into several steps.

        My questions are:
        - Is there a mechanism to group radio buttons by code instead of
        adding them one directly after the other?

    The first way that comes to my mind is to assign a macro to each one
    of them (the same macro). It's possible for a macro to determine
    which radiobutton the call came from, so what the macro could do is
    just to unselect all the other radio buttons.

Here's an example from my Maxy-Yatzy Game for Calc (OpenOffice, but I think that doesn't matter much in this case):
' Code starts here
Sub NumbersButton(Button As Object)
Dim ButtonName As String, ButtonNumber As Integer, State As Boolean
ButtonName=Button.Source.getModel().Name
ButtonNumber=GetButtonNumber(ButtonName)
ButtonState(ButtonNumber)=Not ButtonState(ButtonNumber)

'If Button state is TRUE, unselect Category.
If ButtonState(ButtonNumber) Then' Save relevant dice.
UnselectCategoryButtonPushed
Button.Source.getModel().setPropertyValue("TextColor",Black)
Else' Re-roll relevant dice.
Button.Source.getModel().setPropertyValue("TextColor",Gray)
EndIf

SetAllDiceState
SetRollButtonState(Auto)
End Sub
' End of code

In this case, Button is the object to use for determining what caused the subroutine to start. I call a couple of functions in this to make things happen to other buttons and things like that. For instance, the name of the button that was pressed is found in Button.Source.getModel().Name.

In this case no radio buttons were involved, but that doesn't matter much. It would be pretty much the same. In this case it's just an ordinary button without a frame and with a unicode character label, for instance ”⚂”, so it looks like I'm clicking a die, but the procedure is the same for check boxes, radio buttons and even images. Everything that's clickable.

(OFF TOPIC: Maxy-Yatzy is a Swedish variant of Yatzee where six dice are used and you can save rolls for later. New categories, due to the six dices, are three pairs – XXYYZZ, five of a kind – XXXXX?, full straight – 123456, tower – XXYYYY and house – XXXYYY. A total of ≥84 p in the upper categories gives a 100 p Bonus, Maxi-Yatzy – XXXXXX, gives 100 p. That's pretty much it… kind of.)

Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

    Maybe there are better ways, I don't know…

        - Can someone guess, what else can go wrong?

        Regards,
        Xaver

Hi Xaver,

X Roemer schrieb:

Hi,

I use always the same mechanism to add radio buttons by code. Usually I
add one after one, directly after each other, and they get grouped
automatically. But this time I can choose more than one and the others
don't get disabled. (See screenshot)

I know, it's better to show some code, but it would be a bit too much,
as the creation of widgets is splitted into several steps.

My questions are:
- Is there a mechanism to group radio buttons by code instead of adding
them one directly after the other?
- Can someone guess, what else can go wrong?

See https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Control_Elements

There the last paragraph in section 'Option Buttons'
"To combine several option buttons in a group, you must position them one after another in the activation sequence without any gaps (Model.TabIndex property, described as Order in the dialog editor). If the activation sequence is interrupted by another control element, then OpenOffice.org automatically starts with a new control element group that can be activated regardless of the first group of control elements."

So this is different from option buttons in forms, where grouping is done by the name property.

I have tested, that you really get a grouping, when the TabIndex is consecutive. That happens automatically, when you insert them in that order.

You can change the property 'Tab index' after you have inserted a control, but that will change the other tab indexes too. You might want to have a list of the wanted tab order when designing the dialog and start changing at tab index 0.

You can set and change the property TabIndex as well inside your program before executing the dialog. But unless you insert option buttons newly (instead of setting visible) when running your program, I think, that generating the dialog controls in the correct order while designing the dialog is much easier.

Kind regards
Regina

Hi Regina,

thanks for your reply also.

The TabIndex you're writing about sounds pretty much like what I'm looking for - but I can't find it.
I use python / pyuno and I can't find a property called TabIndex or something similar.

In this folder are two screenshots with all the properties of a RadioButton:
https://github.com/XRoemer/Organon/tree/master/Screenshots/misc

Or is it the case, that TabIndex means the index in the parent container?

Well, I tried to add all mixed elements from a list (RadioButtons were directly after each other) and it didn't work.
When I add the RadioButtons in a separate loop, they work.

Sometimes it would be handy to have more control, as you might have more elements inbetween the RadioButtons. So the designing gets more complicated. Like here in the middle row, where the checkboxes are working like radiobuttons.
The advantage of a radiobutton is to see immediately what kind of choices are possible.

Regards,
Xaver

Sorry, forgot the screenshot:
https://github.com/XRoemer/Organon/blob/master/Screenshots/Export%20vers%200.9.1b.png

Hi Xaver,

X Roemer schrieb:

Hi Regina,

thanks for your reply also.

The TabIndex you're writing about sounds pretty much like what I'm
looking for - but I can't find it.
I use python / pyuno and I can't find a property called TabIndex or
something similar.

"I use python / pyuno" explains it. I have tested it with a StarBasic dialog. I have never used Python and therefore don't know whether it works the same there. The property TabIndex belongs to the service UnoControlDialogElement in com.sun.star.awt, see http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/UnoControlDialogElement.html

Perhaps you ask in the forum https://forum.openoffice.org/en/forum/viewforum.php?f=45 or http://ask.libreoffice.org/en/questions/
Please include in the subject, that it is about python.

Kind regards
Regina

Hi,

I already asked this question in the forum, but didn't receive any anwsers:
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=77289

Provided that there is a theme called "Dark Blue" in the galery folder on disk, I can set a new Persona theme in LO by this code:

/config_provider = smgr.createInstanceWithContext("com.sun.star.configuration.ConfigurationProvider",ctx)//
//
//prop = uno.createUnoStruct("com.sun.star.beans.PropertyValue")//
//prop.Name = "nodepath"//
//prop.Value = "/org.openoffice.Office.Common/Misc"//
////
//config_access = config_provider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", (prop,))//
////
//persona = config_access.PersonaSettings//
//
//values = persona.split(';')//
//values[0] = 'Dark Blue/Header.png'//
//values[1] = 'Dark Blue/Footer.png'//
//values[2] = '#ff0000' # red//
//value = ';'.join(values)//
//config_access.PersonaSettings = value//
////
//config_access.commitChanges()/

Is there a way to make the changes visible without restarting Office? Like it is done, when I use a Persona theme from the option menu in LO?

Thanks for any help,
Xaver