[wxPython] Access to custom windows inside Notebook
While this message has a specific subject, this may be a more general
question. I have a notebook control, populated with a custom composite
widget that has some data and a couple of other controls. From my main
program I would like to be able to do the following to set some toolbar and
menu specific settings for the current visible page:
The problem is that GetPage returns a generic wxWindow and I can't seem to
get access to the members via the "current" as returned above.
I would like to use the OO to hide my data inside each "notebook page"
object, but I need to access it from the parent of the control.
Am I missing something fundamentally simple here? Is there a set of methods
I must implement in my "derived" class so that it will play well with the
rest of wxPython. My custom class is simply derived from wxSplitterWindow as
Thanks for your help,
Robert W. Tolbert, Ph.D. ph.
Senior Principal Systems Engineer fax 203.798.5660
Boehringer Ingelheim Pharmaceuticals, Inc.
900 Ridgebury Road/P. O. Box 368
Ridgefield, CT 06877-0368
Re: [wxPython] Access to custom windows inside Notebook
> While this message has a specific subject, this may be a more general
And a more general problem within wxPython... This issue comes up in several
places and is derived from the fact that there are two objects for
everything, the Python object and the C++ object, and the C++ object usually
knows nothing or almost nothing about the Python object...
> I have a notebook control, populated with a custom composite
> widget that has some data and a couple of other controls.
...When you call self.notebook.AddPage(myWin) you are passing a Python object
to a Python object, but what really happens behind the scenes is the C++
version of the notebook object is getting a pointer to the C++ version of
> From my main
> program I would like to be able to do the following to set some toolbar and
> menu specific settings for the current visible page:
...So when you make this call it asks the C++ notbook for a page, and all it
knows about is the C++ pointer to the window it was given and nothing about
the coresponding Python object. A wxWindow pointer is returned and SWIG
wraps a new Python object around it.
There is a helper function in wx.py called wxPyTypeCast that can be usefull
in some of these situations, but it still doesn't give you the original
Python object but just changes the type of the new shadow object. For
I could probably come up with a way to keep track of the actual Python
objects and add code to all the wrappers to return references to the real
objects instead of creating a new shadow, but I'm afraid that it would
increase complexity, fragility, the potential for memory leaks and runtime
overhead, and decrease maintainability to the point of not being worth the
effort. Especially when simple workarounds can usually be found.
> I would like to use the OO to hide my data inside each "notebook page"
> object, but I need to access it from the parent of the control.
My suggestion would be to derive a class from wxNotebook and override its
AddPage, DeletePage, GetPage and etc. methods. These methods could call the
coresponding wxNotebook method and then maintain/use a python list or
dictionary of the actual objects added.
Each of the wxPython objects has a string attribute named "this" that holds a
"SWIGged pointer" which is essentially the combinarion of the address of the
C++ object and the name of its type. If you wrote a function to extract the
numeric (hex) portion of this string it would make a great key to the
dictionary. The numeric portion of the window.this returned from GetPage
should be the same as for the window you sent to AddPage.