I am trying to write a function that will programmatically raise a (non-custom) event, but I can’t figure out how to do it. I’ve posted some sample code below. It is a simple application with a button, and when that button is clicked, it should raise the EVT_TEXT_MAXLEN event. Instead, I’m getting the following error: “TypeError: in method ‘PostEvent’, expected argument 2 of type ‘wxEvent &’”
Can anyone see what I’m doing wrong? Thanks in advance.
Thanks for the response Carsten. It definitely pointed me in the right direction.
However, I’m looking to raise a wx defined event type, not create a custom event type of my own. After a little bit more fiddling around, this is what I came up with. It seems to do what do what I want.
Thanks for the response Carsten. It definitely pointed me in the right direction.
However, I’m looking to raise a wx defined event type, not create a custom event type of my own. After a little bit more fiddling around, this is what I came up with. It seems to do what do what I want.
Yes, you’re right, given the example I posted in my initial message.
It probably would have been more helpful if I had posted an example that was closer to what I was actually trying to achieve. What I was initially trying to do was create a subclass of wx.Notebook that raised the EVT_NOTEBOOK_PAGE_CHANGED event in the ChangeSelection method.
It ended up being surprisingly easy once I figured it out:
if not event is None: event.Skip()
print “Inside OnMaxLength()”
class Notebook(wx.Notebook):
def ChangeSelection(self, page):
wx.Notebook.ChangeSelection(self, page)
e = wx.NotebookEvent()
e.SetEventType(wx.EVT_NOTEBOOK_PAGE_CHANGED.typeId)
e.SetSelection(page)
wx.PostEvent(self, e)
Does anybody know why the wx.Notebook.ChangeSelection method doesn’t raise the EVT_NOTEBOOK_PAGE_CHANGED method? This seems really strange to me. The documentation indicates that ChangeSelection doesn’t raise the event, but doesn’t give any justification why.
Does anybody know why the wx.Notebook.ChangeSelection method doesn't raise the EVT_NOTEBOOK_PAGE_CHANGED method? This seems really strange to me. The documentation indicates that ChangeSelection doesn't raise the event, but doesn't give any justification why.
Because the policy is that calling a method to do something does not generate the events that would be done if the user does the same thing. The exception to the rule is that if the method was already generating the event at the time that the policy was adopted then it will continue to do so.
Several months ago one of the developers went through the code and added a bunch of ChangeFoo methods that don't generate an event to go along with some of the legacy SetFoo methods that already exist and do generate the event. In other words, if you call the notebook's SetSelection instead of ChangeSelection then you should be getting an event.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!