From: John R. <jr...@ce...> - 2006-11-07 16:50:20
|
On Nov 7, 2006, at 6:03 AM, Mark Wardell wrote: > Hi All, > > **Warning - fairly long post - patience required. > > In another attempt at using subclassed control in XRC I come > unstuck with code initialisation. > In the new() method the windows have not been created so the window > hierarchy does not exist, so calls like GetParent() do not work. I > tried to init() my derived TreeCtrl by putting AddRoot() and > AppendItem() calls in the new() method but this did not work > (nothing appears in the tree). > > So I started looking around and found this page below in the > wxPython wiki which sums up the situation nicely. I recommend this > wiki to all wxPerl people as it contains a huge amount of > information that can be adapted for wxPerl developers, I often > visit looking for new info. > > http://wiki.wxpython.org/index.cgi/SubclassingListCtrlWithXrc > > The key area here is binding to the EVT_WINDOW_CREATE event. I > could not find this in the wxPerl sources but there is a EVT_CREATE > event defined on line 929 in Constant.xs. So I created the > following sub in my class as is the normal way as seen in Event.pm: > > sub EVT_CREATE($$) { $_[0]->Connect( -1, -1, &Wx::wxEVT_CREATE, $_ > [1] ) } > > So now in my code I can bind to the event using: > > EVT_CREATE( $self, \&OnCreateWindow ); > > Then I can put my code in my derived class like below: > > sub OnCreateWindow { # own code goes here } > > This seems to work perfectly although I haven't had much time to > test and find any pitfalls. > Has anyone alse tried using this technique? > Does this sound like a reasonable solution Mattia? (Nobody > understand the event tables and refcounting like you) > > If I find this works without problems then I will look at a generic > way of providing this functionality for ALL objects created using > XRC subclassing. > > Hope this helps others that find themselves in a similar position. > > Regards > Mark > Mark, Sounds too complicated, so I must be missing something. Could you post some code snippets which show why the approach documented in http://wxperl.pvoice.org/kwiki/index.cgi?SubclassingXRC doesn't work? Regards, John Ralls |