Index radio box and contained buttons

I have multiple radio boxes containing three buttons as shown below. I want to keep track of clicked radio buttons within radio boxes then do some processing. I am not sure how to index radio box and then clicked radio buttons within that radio box as there are multiple boxes. Any suggestions?
class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, "test", wx.DefaultPosition, wx.Size(900, 600))
        radio1Choices = ['F','G','P']
        # rb_list has 23 records -- basically used to set the distance b/w radio boxes
        for i in rb_list:
            self.radio1 = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,i), (20,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
            self.radio1.SetSelection( 0 )
            grid_sizer.Add( self.radio1, 0, wx.ALL, 5)

        # Bind the radio box select event to a function
        self.radio1.Bind( wx.EVT_RADIOBOX, self.on_selected )

    def on_selected(self, event):
        if self.radio1.GetStringSelection() == 'F':
            print "F"
        elif self.radio1.GetStringSelection() == 'G':
            print "G"
        else:
            self.radio1.GetStringSelection() == 'P'
            print "P"

A couple of possibilities:

···

On 18/07/14 05:07, Ibraheem Khan wrote:

I have multiple radio boxes containing three buttons as shown below. I want to keep track of clicked radio buttons within radio boxes then do some processing. I am not sure how to index radio box and then clicked radio buttons within that radio box as there are multiple boxes. Any suggestions?
class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, "test", wx.DefaultPosition, wx.Size(900, 600))
        radio1Choices = ['F','G','P']
        # rb_list has 23 records -- basically used to set the distance b/w radio boxes
        for i in rb_list:
            self.radio1 = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,i), (20,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
            self.radio1.SetSelection( 0 )
            grid_sizer.Add( self.radio1, 0, wx.ALL, 5)

        # Bind the radio box select event to a function
        self.radio1.Bind( wx.EVT_RADIOBOX, self.on_selected )

    def on_selected(self, event):
        if self.radio1.GetStringSelection() == 'F':
            print "F"
        elif self.radio1.GetStringSelection() == 'G':
            print "G"
        else:
            self.radio1.GetStringSelection() == 'P'
            print "P"

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
  1.     Make your choices list have a structure [(method,
    

[choices])…] then you can bind to a specific handler method
for each group.

  1.     In your handler get the originating radio group from the event
    

and then decide what to do.
Gadget/Steve

I am not very good at wxpython so a little bit more explanation about possibilities would be really helpful with some form of simple examples. Appreciate it.

···

On Fri, Jul 18, 2014 at 1:08 AM, Steve Barnes gadgetsteve@live.co.uk wrote:

On 18/07/14 05:07, Ibraheem Khan wrote:

I have multiple radio boxes containing three buttons as shown below. I want to keep track of clicked radio buttons within radio boxes then do some processing. I am not sure how to index radio box and then clicked radio buttons within that radio box as there are multiple boxes. Any suggestions?
class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, "test", wx.DefaultPosition, wx.Size(900, 600))
        radio1Choices = ['F','G','P']
        # rb_list has 23 records -- basically used to set the distance b/w radio boxes
        for i in rb_list:
            self.radio1 = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,i), (20,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
            self.radio1.SetSelection( 0 )
            grid_sizer.Add( self.radio1, 0, wx.ALL, 5)

        # Bind the radio box select event to a function
        self.radio1.Bind( wx.EVT_RADIOBOX, self.on_selected )

    def on_selected(self, event):
        if self.radio1.GetStringSelection() == 'F':
            print "F"
        elif self.radio1.GetStringSelection() == 'G':
            print "G"
        else:
            self.radio1.GetStringSelection() == 'P'
            print "P"

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

A couple of possibilities:

  1.     Make your choices list have a structure [(method,
    

[choices])…] then you can bind to a specific handler method
for each group.

  1.     In your handler get the originating radio group from the event
    

and then decide what to do.
Gadget/Steve

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/Sju8vsYe7cM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Option 1:
In option 2:
Of course this being python you can also use a similar method to
that in 1 to add additional information to each radio group that is
then retrieved and used in a single handler using option 2.
Personally I would say that option 1 results in clearer code for a
relative beginner.
Gadget/Steve

···

On 18/07/14 06:12, Ibraheem Khan wrote:

    I am not very good at wxpython so a

little bit more explanation about possibilities would be really
helpful with some form of simple examples. Appreciate it.

A couple of possibilities:

  1.               Make your choices list have a structure [(method,
    

[choices])…] then you can bind to a specific
handler method for each group.

  1.               In your handler get the originating radio group from
    

the event and then decide what to do.
Gadget/Steve

            You received this message because you are subscribed to

a topic in the Google Groups “wxPython-users” group.

            To unsubscribe from this topic, visit [https://groups.google.com/d/topic/wxpython-users/Sju8vsYe7cM/unsubscribe](https://groups.google.com/d/topic/wxpython-users/Sju8vsYe7cM/unsubscribe).

            To unsubscribe from this group and all its topics, send

an email to wxpython-users+unsubscribe@googlegroups.com.

            For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
                rb_list = [(self.OnRadio1, ['a', 'b', 'c']), (self.OnRadio2, ['d', 'e', 'f', 'g']), ......]
for (method, choices) in rb_list:
radio_item = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (-1, -1),
span> (-1, -1),
                                     radio1Choices, wx.RA_SPECIFY_COLS|wx.NO_BORDER)
            radio_item.SetSelection( 0 )
            grid_sizer.Add(radio_item, 0, wx.ALL, 5)
            # Bind the radio box select event to a function
            self.Bind(wx.EVT_RADIOBOX, method, source=radio_item
   )
def OnRadio1(self, evt):
""" Handler for Radio Group 1 """
:
:
def OnRadio2(self, evt):
:

   def OnRadioHandler(self, evt):
""" Handler for Radio Groups """
where_from = evt.GetEventObject()
# Code based on which object & object contents caused the event.

In 2nd option, when I printed:

print event.GetEventObject()

Then I get this:

<wx._controls.RadioBox; proxy of <Swig Object of type ‘wxRadioBox *’ at 0x2c36230> >

Please suggest how do I get index of radiobox within which I clicked radio button, if possible.

···

On Fri, Jul 18, 2014 at 1:35 AM, Steve Barnes gadgetsteve@live.co.uk wrote:

On 18/07/14 06:12, Ibraheem Khan wrote:

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

Option 1:

        # Bind the radio box select event to a function
                rb_list = [(self.OnRadio1, ['a', 'b', 'c']), (self.OnRadio2, ['d', 'e', 'f', 'g']), ......]
for (method, choices) in rb_list:
radio_item = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (-1, -1), (-1, -1),
                                     radio1Choices, wx.RA_SPECIFY_COLS|wx.NO_BORDER)
            radio_item.SetSelection( 0 )
            grid_sizer.Add(radio_item, 0, wx.ALL, 5)
            self.Bind(wx.EVT_RADIOBOX, method, source=radio_item
   )
def OnRadio1(self, evt):
""" Handler for Radio Group 1 """
:
:
def OnRadio2(self, evt):
:

In option 2:
   def OnRadioHandler(self, evt):
""" Handler for Radio Groups """
where_from = evt.GetEventObject()
# Code based on which object & object contents caused the event.

Of course this being python you can also use a similar method to

that in 1 to add additional information to each radio group that is
then retrieved and used in a single handler using option 2.

Personally I would say that option 1 results in clearer code for a

relative beginner.

Gadget/Steve

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/Sju8vsYe7cM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

    I am not very good at wxpython so a

little bit more explanation about possibilities would be really
helpful with some form of simple examples. Appreciate it.

A couple of possibilities:

  1.               Make your choices list have a structure [(method,
    

[choices])…] then you can bind to a specific
handler method for each group.

  1.               In your handler get the originating radio group from
    

the event and then decide what to do.
Gadget/Steve

            You received this message because you are subscribed to

a topic in the Google Groups “wxPython-users” group.

            To unsubscribe from this topic, visit [https://groups.google.com/d/topic/wxpython-users/Sju8vsYe7cM/unsubscribe](https://groups.google.com/d/topic/wxpython-users/Sju8vsYe7cM/unsubscribe).


            To unsubscribe from this group and all its topics, send

an email to wxpython-users+unsubscribe@googlegroups.com.

            For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

Ibraheem Khan wrote:

In 2nd option, when I printed:

print event.GetEventObject()

Then I get this:

<wx._controls.RadioBox; proxy of <Swig Object of type 'wxRadioBox *'
at 0x2c36230> >

Please suggest how do I get index of radiobox within which I clicked
radio button, if possible.

Did you check the documentation even once? You use GetSelection to
fetch the currently selected button.

    choice = event.GetEventObject().GetSelection()

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Tim: I exactly tried that before posting this question. The only missing link is how to index that box first within which I did selection.

print event.GetEventObject().GetSelection()

gives only whether I clicked on radio button 1,2, or 3 but it doesn’t tell about which row/radiobox as there are multiple boxes.

···

On Fri, Jul 18, 2014 at 11:56 AM, Tim Roberts timr@probo.com wrote:

Ibraheem Khan wrote:

In 2nd option, when I printed:

print event.GetEventObject()

Then I get this:

<wx._controls.RadioBox; proxy of <Swig Object of type ‘wxRadioBox *’

at 0x2c36230> >

Please suggest how do I get index of radiobox within which I clicked

radio button, if possible.

Did you check the documentation even once? You use GetSelection to

fetch the currently selected button.

choice = event.GetEventObject().GetSelection()

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/Sju8vsYe7cM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ibraheem Khan wrote:

Tim: I exactly tried that before posting this question. The only
missing link is how to index that box first within which I did
selection.

print event.GetEventObject().GetSelection()

gives only whether I clicked on radio button 1,2, or 3 but it doesn't
tell about which row/radiobox as there are multiple boxes.

I'm sorry, I misunderstood. So, the issue is NOT finding out which
button was clicked, but rather finding out which BOX that button was in,
right?

What you get back from GetEventObject() is the original RadioBox object
you created. So, if you add your own private store:
        self.radio1.my_identity = i

Then in the event handler you can refer to
        event.GetEventObject().my_identity

Probably "i" is not the piece of information you want, but I think you
get the idea.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Hmm. This is interesting, instead of giving me identity (sequential number) it gives me its unique position where I placed it in split window.

···

On Fri, Jul 18, 2014 at 12:32 PM, Tim Roberts timr@probo.com wrote:

Ibraheem Khan wrote:

Tim: I exactly tried that before posting this question. The only

missing link is how to index that box first within which I did

selection.

print event.GetEventObject().GetSelection()

gives only whether I clicked on radio button 1,2, or 3 but it doesn’t

tell about which row/radiobox as there are multiple boxes.

I’m sorry, I misunderstood. So, the issue is NOT finding out which

button was clicked, but rather finding out which BOX that button was in,

right?

What you get back from GetEventObject() is the original RadioBox object

you created. So, if you add your own private store:

    self.radio1.my_identity = i

Then in the event handler you can refer to

    event.GetEventObject().my_identity

Probably “i” is not the piece of information you want, but I think you

get the idea.

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/Sju8vsYe7cM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Yes, of course it does, because that’s what “i” contains in your
original code. That’s exactly why I said this:
You must learn to understand code suggestions before you implement
them.

···

Ibraheem Khan wrote:

    Hmm. This is interesting, instead of giving me

identity (sequential number) it gives me its unique position
where I placed it in split window.

        Probably "i" is not the piece of information you want, but I

think you

        get the idea.
-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com