Make a native control emit an event

Hey,

I have some controls, (wx.RadioButton) that are bound to methods on
EVT_RADIOBUTTON events which is all well.

The issue is I have some other bits that I want to extend to appear be
apart of the radiobutton, so I bound EVT_LEFT_UP to that, which calls
SetValue(True) on the radio button. However setting the value from
code doesn't the fire the radio button event so the EVT_RADIOBUTTON
binding only works if I click actually on the radio button part and
not on the extended part which goes through the left up event.

Is there a way I can get the radio button to fire the event? Do I have
to make a new radio button event in OnLeftUp and send it to the radio
button ProcessEvent?

I understand why this happens, as this is normally unwanted behaviour
- but I think I want it here

Cheers!

Hi Paul,

I believe you can do this. Rather than spend time trying to re-invent the wheel, check out the following exchange of information: http://stackoverflow.com/questions/1128074/wxpython-how-do-i-fire-events

I think that the conversation documented there will be of help to you.

Cheers!!

Dermot.

···

On 29 January 2013 12:27, Paul Wiseman poalman@gmail.com wrote:

Hey,

I have some controls, (wx.RadioButton) that are bound to methods on

EVT_RADIOBUTTON events which is all well.

The issue is I have some other bits that I want to extend to appear be

apart of the radiobutton, so I bound EVT_LEFT_UP to that, which calls

SetValue(True) on the radio button. However setting the value from

code doesn’t the fire the radio button event so the EVT_RADIOBUTTON

binding only works if I click actually on the radio button part and

not on the extended part which goes through the left up event.

Is there a way I can get the radio button to fire the event? Do I have

to make a new radio button event in OnLeftUp and send it to the radio

button ProcessEvent?

I understand why this happens, as this is normally unwanted behaviour

  • but I think I want it here

Cheers!

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en


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/groups/opt_out.

Ahhh wxCommandEvent, that's what I needed :slight_smile:

Thanks! Working well now

···

On 29 January 2013 11:38, Dermot Doran <dppdoran@gmail.com> wrote:

Hi Paul,

I believe you can do this. Rather than spend time trying to re-invent the
wheel, check out the following exchange of information:
python - wxPython, how do I fire events? - Stack Overflow

I think that the conversation documented there will be of help to you.

Cheers!!

Dermot.

On 29 January 2013 12:27, Paul Wiseman <poalman@gmail.com> wrote:

Hey,

I have some controls, (wx.RadioButton) that are bound to methods on
EVT_RADIOBUTTON events which is all well.

The issue is I have some other bits that I want to extend to appear be
apart of the radiobutton, so I bound EVT_LEFT_UP to that, which calls
SetValue(True) on the radio button. However setting the value from
code doesn't the fire the radio button event so the EVT_RADIOBUTTON
binding only works if I click actually on the radio button part and
not on the extended part which goes through the left up event.

Is there a way I can get the radio button to fire the event? Do I have
to make a new radio button event in OnLeftUp and send it to the radio
button ProcessEvent?

I understand why this happens, as this is normally unwanted behaviour
- but I think I want it here

Cheers!

--
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
---
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/groups/opt_out.

--
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
---
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/groups/opt_out.

Paul Wiseman wrote:

Hey,

I have some controls, (wx.RadioButton) that are bound to methods on
EVT_RADIOBUTTON events which is all well.

The issue is I have some other bits that I want to extend to appear be
apart of the radiobutton, so I bound EVT_LEFT_UP to that, which calls
SetValue(True) on the radio button. However setting the value from
code doesn't the fire the radio button event so the EVT_RADIOBUTTON
binding only works if I click actually on the radio button part and
not on the extended part which goes through the left up event.

Is there a way I can get the radio button to fire the event? Do I have
to make a new radio button event in OnLeftUp and send it to the radio
button ProcessEvent?

I understand why this happens, as this is normally unwanted behaviour
- but I think I want it here

Ahhh wxCommandEvent, that's what I needed

Alternatively, if you call event.Skip() in your handler then that will allow the native event handler to still run and do its normal functionality.

···

--
Robin Dunn
Software Craftsman

Paul Wiseman wrote:

Hey,

I have some controls, (wx.RadioButton) that are bound to methods on
EVT_RADIOBUTTON events which is all well.

The issue is I have some other bits that I want to extend to appear be
apart of the radiobutton, so I bound EVT_LEFT_UP to that, which calls
SetValue(True) on the radio button. However setting the value from
code doesn't the fire the radio button event so the EVT_RADIOBUTTON
binding only works if I click actually on the radio button part and
not on the extended part which goes through the left up event.

Is there a way I can get the radio button to fire the event? Do I have
to make a new radio button event in OnLeftUp and send it to the radio
button ProcessEvent?

I understand why this happens, as this is normally unwanted behaviour
- but I think I want it here

Ahhh wxCommandEvent, that's what I needed

Alternatively, if you call event.Skip() in your handler then that will allow
the native event handler to still run and do its normal functionality.

event.Skip() in which handler?

did you mean in EVT_LEFT_UP? That is just the click on the other
control, so that wont fire the radio buttons EVT_RADIOBUTTON so I'm
not sure what you mean.

The LEFT_UP was calling SetValue, which changed the radio buttons
appearance and value to checked, but none of the bindings were getting
run as no event was fired.

···

On 29 January 2013 17:14, Robin Dunn <robin@alldunn.com> wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
--- 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/groups/opt_out.

Paul Wiseman wrote:

Hey,

I have some controls, (wx.RadioButton) that are bound to methods on
EVT_RADIOBUTTON events which is all well.

The issue is I have some other bits that I want to extend to appear be
apart of the radiobutton, so I bound EVT_LEFT_UP to that, which calls
SetValue(True) on the radio button. However setting the value from
code doesn't the fire the radio button event so the EVT_RADIOBUTTON
binding only works if I click actually on the radio button part and
not on the extended part which goes through the left up event.

Is there a way I can get the radio button to fire the event? Do I have
to make a new radio button event in OnLeftUp and send it to the radio
button ProcessEvent?

I understand why this happens, as this is normally unwanted behaviour
- but I think I want it here

Ahhh wxCommandEvent, that's what I needed

Alternatively, if you call event.Skip() in your handler then that will allow
the native event handler to still run and do its normal functionality.

I just experienced some odd behaviour as well, wx.TextCtrl.SetValue
seems to fire EVT_TEXT on linux but not on mac, not sure why that
might be. I've changed some of these to ChangeValue which doesn't seem
to fire the event on either platform. This doesn't seem to be the case
for other controls though, only textctrls seem to fire an event from
SetValue - is this normal?

···

On 29 January 2013 17:14, Robin Dunn <robin@alldunn.com> wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
--- 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/groups/opt_out.

...

I just experienced some odd behaviour as well, wx.TextCtrl.SetValue
seems to fire EVT_TEXT on linux but not on mac, not sure why that
might be. I've changed some of these to ChangeValue which doesn't seem
to fire the event on either platform. This doesn't seem to be the case
for other controls though, only textctrls seem to fire an event from
SetValue - is this normal?

I think there are historic reasons for this behaviour.

http://wxpython.org/Phoenix/docs/html/TextEntry.html?highlight=setvalue#TextEntry.SetValue

Werner

···

On 30/01/2013 14:44, Paul Wiseman wrote:

Paul Wiseman wrote:

Paul Wiseman wrote:

Hey,

I have some controls, (wx.RadioButton) that are bound to methods on
EVT_RADIOBUTTON events which is all well.

The issue is I have some other bits that I want to extend to appear be
apart of the radiobutton, so I bound EVT_LEFT_UP to that, which calls
SetValue(True) on the radio button. However setting the value from
code doesn't the fire the radio button event so the EVT_RADIOBUTTON
binding only works if I click actually on the radio button part and
not on the extended part which goes through the left up event.

Is there a way I can get the radio button to fire the event? Do I have
to make a new radio button event in OnLeftUp and send it to the radio
button ProcessEvent?

I understand why this happens, as this is normally unwanted behaviour
- but I think I want it here

Ahhh wxCommandEvent, that's what I needed

Alternatively, if you call event.Skip() in your handler then that will allow
the native event handler to still run and do its normal functionality.

event.Skip() in which handler?

did you mean in EVT_LEFT_UP? That is just the click on the other
control, so that wont fire the radio buttons EVT_RADIOBUTTON so I'm
not sure what you mean.

Sorry, I thought you were saying that you were doing it in the radio button's event handler. Sending your own event for the other control is the right way to do it.

The LEFT_UP was calling SetValue, which changed the radio buttons
appearance and value to checked, but none of the bindings were getting
run as no event was fired.

The general rule is that events are not sent when values are changed programatically, only when they are changed by the user. But there are exceptions to the rule as you've discovered. The widgets/methods that were already sending an event when the rule was decided upon were typically left as-is. That is why wx.TextCtrl got the ChangeValue method, so it could have a way to change the value programatically without sending the event while keeping SetValue that still worked the old way.

···

On 29 January 2013 17:14, Robin Dunn<robin@alldunn.com> wrote:

--
Robin Dunn
Software Craftsman