mike cantor wrote:
Hi all,
I have a RadioBox in a wxPython app. The EVT_RADIOBOX associated with this control is bound to an event handler which enables or disables various other controls according to the selection:
self.controls["dataSourcesRB"] = wx.RadioBox(self, -1, "Data Sources",
wx.DefaultPosition, wx.DefaultSize, DATA_LIST, 1, wx.RA_SPECIFY_COLS)
self.Bind(wx.EVT_RADIOBOX, self.dataSourcesRB, self.controls["dataSourcesRB"])def dataSourcesRB(self, evt):
i = evt.GetInt()
for j in range(len(FUNCTION_TABLE[i])):
if FUNCTION_TABLE[i_data][j] == "none":
self.controls["plotButtons"][j].Enable(False)
else:
self.controls["plotButtons"][j].Enable(True)I would like to make an initial call to this handler when the dialog is constructed by sending an event as if the first radio button had been selected. What is the proper way to do this?
Something like this:
rb = self.controls["dataSourcesRB"]
evt = wx.CommandEvent(wx.wxEVT_COMMAND_RADIOBOX_SELECTED)
evt.SetEventObject(rb)
evt.SetId(rb.GetId())
evt.SetInt(0) # which item was selected
rb.GetEventHandler().ProcessEvent(evt)
Or, since you know that dataSourceRB only needs to get the int value from the event, and doesn't need to propagate the event to parents or other special event handling features, you can just call the handler directly, like this:
evt = wx.CommandEvent()
evt.SetInt(0)
self.dataSourcesRB(evt)
Or you can factor out the guts of dataSourceRB into another function that both dataSourceRB and your initialization code calls passing the int value:
self.dataSourceRB_helper(0)
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!