Re: Phoenix - wx.PyCommandEvent

Robin Dunn <[email protected]>
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
Werner wrote:
> On 9/18/2015 18:41, Werner wrote:
>> Hi,
>>
>> With Phoenix I see a problem with a custom event that the 'setter' is
>> not called.
>>
>> The event is define like this:
>>
>> class ScEventDbItemSet(wx.PyCommandEvent):
>> """Custom event to be notified when a dbItem is set on the control"""
>> def __init__(self, evtType, id):
>> wx.PyCommandEvent.__init__(self, evtType, id)
>> self._dbItem = None
>>
>> @property
>> def dbItem(self):
>> return self._dbItem
>>
>> @dbItem.setter
>> def dbItem(self, dbitem):
>> self._dbItem = dbitem
>>

Hmm...  I expected that would work correctly. It looks like __getattr__ 
and friends don't always play nice with properties.  See 
http://stackoverflow.com/questions/15401180/using-getattr-and-meeting-expected-behaviour-for-subclasses. 
  The wx.PyEvent and wx.PyCommandEvent classes have implementations for 
__[get|set|del]attr__ and is how they ensure that all attributes are 
stored in the dictionary that gets shared by the clones that go through 
the event system.  I'll add a TODO to my list to take another look at 
that implementation and see if there is another way to do it.

>> and I am using it like this:
>>
>> evt = ScEventDbItemSet(scEVT_SEARCHCTRL_DBITEMSET, self.GetId())
>> evt.dbItem = item
>> self.GetEventHandler().ProcessEvent(evt)
>>
>> Anyone knows why this is not working?
> If I add this, as mentioned on
> http://wxpython.org/Phoenix/docs/html/MigrationGuide.html?highlight=pycommandevent:
>

Yeah, that example is broken.  I'll fix that too when I reinvestigate 
the current implementation.  For clarification, you should only need to 
follow this example if your class already had __getattr__ etc. 
implementations in Classic, and the intent is to show how they would 
need to be updated to work with Phoenix using the extra dictionary.


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

-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.