This works reliably in that changes, at all levels, change the high
level object instance.
What I'd like to do is pass the object as an argument via the widgets'
interfaces so that I don't need to recreate the hierarchy when unit
testing an individual module. The problem is that this method seems
unreliable ie sometimes the changes don't get reflected in the original
instance and sometimes I get an error message saying the object doesn't
have a member that I know it does have.
Its as if after a couple of levels the object gets corrupted.
This works reliably in that changes, at all levels, change the high
level object instance.
What I'd like to do is pass the object as an argument via the widgets'
interfaces so that I don't need to recreate the hierarchy when unit
testing an individual module.
This is just screaming out for a decoupling refactor of some sort. In other words, requiring some widget deep in the hierarchy to have to know details about the containment environment above it is prone to all sorts of problems and makes for a very brittle architecture. What happens if you decide to reuse that component elsewhere in your app? What if you change the hierarchy in the current instance?
One suggestion already made is to use the app object (or any other shared intermediate object would work too) to allow you to get a reference to the target object from anywhere. This is good, but there are 2 simple ways in wx to be able to decouple these two portions of the app even more so the nested component doesn't have to know any details about the containment hierarchy or other shared objects, or even to know any specifics about the target object:
* Send a custom event from the nested component and catch that event up the hierarchy where the target object lives. Since you are going up the hierarchy then wx.ComamndEvents fit perfectly. If you want to go down the hierarchy or side-to-side, then look at the next option.
* Use wx.lib.pubsub (or similar 3rd party module) to send messages from the nested component, and subscribe to that message in the object where the target object lives. This has the advantage that it is not tied to the widget hierarchy at all. The subscriber(s) can be located anywhere in your application.
ยทยทยท
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!