Subclassing wx.NotifyEvent

Ok, I don't know what I am doing wrong... Here is the smallest sample I could put together to demonstrate the problem. Does anyone have some suggestions about it?

Thank you :frowning:

Andrea.

NotifyEvent.py (1.31 KB)

···

_________________________________________
Andrea Gavana (gavana@kpo.kz)
Reservoir Engineer
KPDL
4, Millbank
SW1P 3JA London

Direct Tel: +44 (0) 20 717 08936
Mobile Tel: +44 (0) 77 487 70534
Fax: +44 (0) 20 717 08900
Web: http://xoomer.virgilio.it/infinity77
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

-----Original Message-----
From: Andrea Gavana [mailto:andrea.gavana@gmail.com]
Sent: 11 May 2006 00:18
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] Subclassing wx.NotifyEvent

Hello NG,
    In an application I am trying to create, I have
subclassed wx.NotifyEvent in this way:

wxEVT_MY_EVENT = wx.NewEventType()
EVT_MY_EVENT = wx.PyEventBinder(wxEVT_MY_EVENT, 1)

class MyEvent(wx.NotifyEvent):

    def __init__(self, eventType, id=1):

        wx.NotifyEvent.__init__(self, eventType, id)

    def GetItem(self):

        return self._item

    def SetItem(self, item):

        self._item = item

And so forth. What I do in the event handler inside the
control, is this:

event = MyEvent(wxEVT_MY_EVENT, self.GetId()) event._item = item
event.SetEventObject(self)
if self.ProcessEvent(event) and not event.IsAllowed():
    # cancelled by program
    return

In the demo, this is what I do:

self.myobject.Bind(EVT_MY_EVENT, self.OnEvent)

def OnEvent(self, event):
    item = event.GetItem()
    # do other processing

What I get is:

AttributeError: 'NotifyEvent' object has no attribute 'GetItem'

?!?!? ... First of all, it should not be 'NotifyEvent' but
'MyEvent', and secondly I have explicitely implemented the
function GetItem() inside the class... I am sure I am missing
something.
Could someone please give me a hint on what I am doing wrong?

Thank you very much.

Andrea.

--
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.virgilio.it/infinity77/

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

I tried your example and it seems that your MyEvent is casted to a wx.NotifyEvent and also thrown as such a one. I suspect this is because swig (or the _oor magic?!) was not configured so that you can derive from wx.NotifyEvent and use it simply as-is.
My best idea here is that you derive from wx.PyCommandEvent instead. See the wxpython demo under "Process and Events -> Python Events" which shows how to do this.

-Matthias

···

Am Thu, 11 May 2006 12:32:02 +0200 hat Gavana, Andrea <gavana@kpo.kz> geschrieben:

Ok, I don't know what I am doing wrong... Here is the smallest sample I could put together to demonstrate the problem. Does anyone have some suggestions about it?

Thank you :frowning:

Andrea.

Nitro wrote:

···

Am Thu, 11 May 2006 12:32:02 +0200 hat Gavana, Andrea <gavana@kpo.kz> > geschrieben:

Ok, I don't know what I am doing wrong... Here is the smallest sample I could put together to demonstrate the problem. Does anyone have some suggestions about it?

Thank you :frowning:

Andrea.

I tried your example and it seems that your MyEvent is casted to a wx.NotifyEvent and also thrown as such a one. I suspect this is because swig (or the _oor magic?!) was not configured so that you can derive from wx.NotifyEvent and use it simply as-is.
My best idea here is that you derive from wx.PyCommandEvent instead. See the wxpython demo under "Process and Events -> Python Events" which shows how to do this.

Correct. In order for events created in Python to pass through the wx event system and still retain their python-ness when they come out the other end they need to have some special handling done in the wrappers and some special engineering for the event class, (different from normal OOR.) wx.PyEvent and wx.PyCommandEvent have been setup to work that way.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!