[wxPython] Set/GetTopWindow inconstistency?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Set/GetTopWindow inconstistency?

alexander smishlajev-3
hello all!

my problem is:  when i pass a certain object to wxApp.SetTopWindow()
method, i expect to receive the same object from app.GetTopWindow()
call.  usually the top window belongs to customised class derived from
wxFrame or wxDialog.  in wxPython, GetTopWindow() returns a plain
wxFrame (or wxDialog) that is part of my top window object.

do wxWindows in c++ behave in the same way?  if not, may i volunteer to
patch wxPython code?

or maybe i am totally wrong in my expectations (in fact, there is
similar problem with wxWindow.GetParent() method, and probably with
GetChildren() method also)?

best wishes,
alex.


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Set/GetTopWindow inconstistency?

Robin Dunn
>
> my problem is:  when i pass a certain object to wxApp.SetTopWindow()
> method, i expect to receive the same object from app.GetTopWindow()
> call.  usually the top window belongs to customised class derived from
> wxFrame or wxDialog.  in wxPython, GetTopWindow() returns a plain
> wxFrame (or wxDialog) that is part of my top window object.
>
> do wxWindows in c++ behave in the same way?

Yes, it does.  The value returned is a pointer to wxWindow and in C++ you
would just typecast it to a pointer of the right type.  For wxPython SWIG
sees the return value being of type wxWindow* and creates a shadow wxWindow
object to wrap the pointer.  There is no built-in typecast capabilities.
The trick is to throw away the wxWindow shadow object and wap the pointer in
a wxFrame shadow object instead.  Then you can call the frame methods and so
on.  To facilitate this I added a helper function to wx.py named
wxPyTypeCast.  See wx.py for more details but you can use it like this in
your case:

frame = wxPyTypeCast(app.GetTopWindow(), "wxFrame")


--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Set/GetTopWindow inconstistency?

alexander smishlajev-3
Robin Dunn wrote:
>
> Yes, it does.  The value returned is a pointer to wxWindow and in C++ you
> would just typecast it to a pointer of the right type.  For wxPython SWIG
> sees the return value being of type wxWindow* and creates a shadow wxWindow
> object to wrap the pointer.  There is no built-in typecast capabilities.
> The trick is to throw away the wxWindow shadow object and wap the pointer in
> a wxFrame shadow object instead.

i see.  things are even worse than i thought... <grin>  may
wxObject::IsKindOf() make such operations easier?  as far as i
understand, it is not exported in current wxPython version, is it?

best wishes,
alex.


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Set/GetTopWindow inconstistency?

Robin Dunn
> Robin Dunn wrote:
> >
> > Yes, it does.  The value returned is a pointer to wxWindow and in C++
you
> > would just typecast it to a pointer of the right type.  For wxPython
SWIG
> > sees the return value being of type wxWindow* and creates a shadow
wxWindow
> > object to wrap the pointer.  There is no built-in typecast capabilities.
> > The trick is to throw away the wxWindow shadow object and wap the
pointer in
> > a wxFrame shadow object instead.
>
> i see.  things are even worse than i thought... <grin>  may
> wxObject::IsKindOf() make such operations easier?  as far as i
> understand, it is not exported in current wxPython version, is it?
>

I originally didn't wrap wxObject because I didn't want to have to deal with
the wxClassInfo objects and such, and I didn't think they would really be
necessary from wxPython.  However I have been slowly changing my opinion on
such things so they may show up some day.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users