hello,
I couldn't find much consistent information about custom events on the web,
the best I found was: http://wiki.wxpython.org/CustomEventClasses.
Although I succeeded in my goal, I'm still left with a few questions:
1. What's the difference between NewEvent and NewCommandEvent ?
I somewhere read that only one of them can propagate,
whatever that means ?
I found out that NewCommandEvent is not allowed to have arbitrary data attached.
2. Why in wx, sometimes is used "parent" and sometimes "Parent" ?
thanks,
Stef Mientki
Stef Mientki wrote:
hello,
I couldn't find much consistent information about custom events on the web,
the best I found was: CustomEventClasses - wxPyWiki.
This should be sufficient.
Although I succeeded in my goal, I'm still left with a few questions:
1. What's the difference between NewEvent and NewCommandEvent ?
I somewhere read that only one of them can propagate,
whatever that means ?
It means that you have to bind directly to those controls, which send plain
Events in order to receive them, whereas CommandEvents can be received by
binding to any parent control. Here propagation means, that a CommandEvent will
travel up the hierarchy of nested controls and an Event will not.
Consider your custom control sitting in a panel sending out Events:
panel.Bind(evt.YOUR_EVENT, self.OnDoSomething, your_control)
will not work, whereas
your_control.Bind(evt.YOUR_EVENT, self.OnDoSomething)
will. (Anybody correct me if that is wrong)
I found out that NewCommandEvent is not allowed to have arbitrary data
attached.
Then I think it's a bug. Are you sure?
2. Why in wx, sometimes is used "parent" and sometimes "Parent" ?
What do you mean? Variable names? They are arbitrary.
Christian
Christian K wrote:
Stef Mientki wrote:
hello,
I couldn't find much consistent information about custom events on the web,
the best I found was: CustomEventClasses - wxPyWiki.
This should be sufficient.
for you 
Although I succeeded in my goal, I'm still left with a few questions:
1. What's the difference between NewEvent and NewCommandEvent ?
I somewhere read that only one of them can propagate,
whatever that means ?
It means that you have to bind directly to those controls, which send plain
Events in order to receive them, whereas CommandEvents can be received by
binding to any parent control. Here propagation means, that a CommandEvent will
travel up the hierarchy of nested controls and an Event will not.
thanks Cristian,
that explains.
I found out that NewCommandEvent is not allowed to have arbitrary data
attached.
Then I think it's a bug. Are you sure?
I'm not sure, but this works:
JALsPy_Properties_Event, EVT_JALSPY_PROPERTIES_CHANGED = wx.lib.newevent.NewEvent()
new_evt = JALsPy_Properties_Event( attr1="hello", attr2=654 )
And this gives an error:
JALsPy_Properties_Event, EVT_JALSPY_PROPERTIES_CHANGED = wx.lib.newevent.NewCommandEvent()
new_evt = JALsPy_Properties_Event( attr1="hello", attr2=654 )
Traceback (most recent call last):
File "D:\data_to_test\JALsPy\JALsPy_properties.py", line 165, in OnEditorChange
new_evt = JALsPy_Properties_Event( attr1="hello", attr2=654 )
TypeError: __init__() takes exactly 2 non-keyword arguments (1 given)
2. Why in wx, sometimes is used "parent" and sometimes "Parent" ?
What do you mean? Variable names? They are arbitrary.
Yes,
but I think programming was more "reasoning" than "knowing" 
cheers,
Stef Mientki
Stef Mientki wrote:
Christian K wrote:
Stef Mientki wrote:
hello,
I couldn't find much consistent information about custom events on
the web,
the best I found was: CustomEventClasses - wxPyWiki.
This should be sufficient.
for you 
What I wanted to say is, that it is not (much) more complicated than that. Now,
that I think of it a second time, there's indeed some information missing. See
below.
Although I succeeded in my goal, I'm still left with a few questions:
1. What's the difference between NewEvent and NewCommandEvent ?
I somewhere read that only one of them can propagate,
whatever that means ?
It means that you have to bind directly to those controls, which send
plain
Events in order to receive them, whereas CommandEvents can be received by
binding to any parent control. Here propagation means, that a
CommandEvent will
travel up the hierarchy of nested controls and an Event will not.
thanks Cristian,
that explains.
I found out that NewCommandEvent is not allowed to have arbitrary data
attached.
Then I think it's a bug. Are you sure?
I'm not sure, but this works:
JALsPy_Properties_Event, EVT_JALSPY_PROPERTIES_CHANGED =
wx.lib.newevent.NewEvent()
new_evt = JALsPy_Properties_Event( attr1="hello", attr2=654 )
And this gives an error:
JALsPy_Properties_Event, EVT_JALSPY_PROPERTIES_CHANGED =
wx.lib.newevent.NewCommandEvent()
new_evt = JALsPy_Properties_Event( attr1="hello", attr2=654 )
Traceback (most recent call last):
File "D:\data_to_test\JALsPy\JALsPy_properties.py", line 165, in
OnEditorChange
new_evt = JALsPy_Properties_Event( attr1="hello", attr2=654 )
TypeError: __init__() takes exactly 2 non-keyword arguments (1 given)
As the error message says, a non-keyword arg is missing. In that case, the first
argument has to be the ID of the control which sends the event, which can be
determined by ctrl.GetID().
I did not know that this is not neccessary for non CommandEvents, though.
2. Why in wx, sometimes is used "parent" and sometimes "Parent" ?
What do you mean? Variable names? They are arbitrary.
Yes,
but I think programming was more "reasoning" than "knowing" 
I hope so, but that small difference is just not intentional, I'd say.
Christian
And this gives an error:
JALsPy_Properties_Event, EVT_JALSPY_PROPERTIES_CHANGED =
wx.lib.newevent.NewCommandEvent()
new_evt = JALsPy_Properties_Event( attr1="hello", attr2=654 )
Traceback (most recent call last):
File "D:\data_to_test\JALsPy\JALsPy_properties.py", line 165, in
OnEditorChange
new_evt = JALsPy_Properties_Event( attr1="hello", attr2=654 )
TypeError: __init__() takes exactly 2 non-keyword arguments (1 given)
As the error message says, a non-keyword arg is missing. In that case, the first
argument has to be the ID of the control which sends the event, which can be
determined by ctrl.GetID().
I did not know that this is not neccessary for non CommandEvents, though.
Thanks for the detailed explanantion Cristian.
cheers,
Stef Mientki