[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proxy for RadioButton


On Fri, 20 Sept 2024 at 20:40, BB <adamnt42@xxxxxxxxx> wrote:

>
> On 21/9/24 4:57 am, Jussi Lahtinen wrote:
>
> Not sure what happens there... maybe you could provide a small runnable
> project to demonstrate the problem?
> I think RadioButton should behave the same no matter where it is. Maybe I
> miss something.
>
> Jussi
>
> On Tue, Sep 17, 2024 at 12:58 PM BB <adamnt42@xxxxxxxxx> wrote:
>
>> Is there any way to have the RadioButton's mutex nature exposed through
>> its proxy (or otherwise)?
>>
>> I'm using the RadioButton in a custom control, so when that control is
>> inside a container the mutex nature is gone.
>>
>> regards
>>
>> bruce
>>
>>
>> The class (say NewRadio) inherits UserContainer, it has a RadioButton as
> one of its Children and the Proxy is set to the Radio Button.
>
> If I put a NewRadio control in say a Frame on a form then the mutex is
> gone because there are layers of containers between the Frame and the
> RadioButton. To try and simplify:
>
> [ Form [ Frame [ NewRadio1 [ _UserContainer [ RadioButton ] ] ]
>
>                [ NewRadio2 [ _UserContainer [ RadioButton ] ] ] ] ]
>
>
> So the RadioButtons are in different containers and the mutex doesn't work.
>
> I had solved this many years ago in some now long gone project and I cant
> recall anything about how I did it. I thought someone else may have solved
> it.
>
> regards
>
> bruce
>

You can use Action, although for some reason i can't fine Action in the IDE
properties for RadioButton but the property still exists.

This code works with RadioButtons in any containers i want to put them..
But it only works with QT as with gtk3 if you only have one RadioButton in
a container you cannot set its value to False.
And it does not work if 2 radiobuttons DO share the same parent as the
toolkit wants to do it's own thing.

' Gambas class file

'' RadioButtons seem to not have Action property in the IDE so set by code
Public Sub Form_Open()

  RadioButton1.Action = "rbG1"
  RadioButton2.Action = "rbG1"
  RadioButton3.Action = "rbG1"

End

'' Radio's share the group name rbtnGroup1 and the Action name rbG1
'' So they all activate this method on click and Action["rbG1"] can be used
to access them all
Public Sub rbtnGroup1_Click()

  If Last.Value Then

    For Each hRB As RadioButton In Action["rbG1"].Controls

      If hRB.Name <> Last.Name And If hRB.Value Then
        Object.Lock(hRB)
        hRB.Value = False
        Object.UnLock(hRB)
      Endif

    Next

  Endif

End

'' Stop the user setting Value to false by clicking
'' Had to use MouseUp event as RadioButton_Click only fires with QT when
setting value true but not when false.
Public Sub rbtnGroup1_MouseUp()

  If Last.Value Then
    Stop Event
  Endif

End

Follow-Ups:
Re: Proxy for RadioButtonBruce Steers <bsteers4@xxxxxxxxx>
Re: Proxy for RadioButtonJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>
References:
Proxy for RadioButtonBB <adamnt42@xxxxxxxxx>
Re: Proxy for RadioButtonJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>
Re: Proxy for RadioButtonBB <adamnt42@xxxxxxxxx>