[wxPython] dumping/retrieving window state information

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

[wxPython] dumping/retrieving window state information

F. Oliver Gathmann-2
Hello all,

I would like to be able to efficiently save the current state of my
wxPython
application to a dictionary for later retrieval. Obviously, different
standard
widgets would dump different state information; a ListBox only needs to
report the current selection, a Text widget the current text and possibly
the
cursor position, and so on.

The most elegant solution to solve this problem seemed to me to subclass
the standard wxPython classes and add dump_state() and retrieve_state()
methods to them. Coming from Tkinter, I thought that I could get a list of
the
current Python objects associated with each window at runtime by calling
the
GetChildren() method. However, the corresponding method of the wxWindow
class returns a list of pointers to the underlying C++ objects wrapped by
the
wxPython objects and there seems to be no way to access the wrapping Python
objects directly - is that right? If so, is there any other solution to my
problem?
And how does the 'Dynamic Class' wxPyValidator fit into that picture?

Many thanks in advance,

Oliver

F. Oliver Gathmann
CRI Inc., 80 Ashford St., Boston, 02134 MA
phone: (617) 787-5400#224 ; fax: (617) 787-4488
e-mail: [hidden email]
web: http://www.scar.utoronto.ca/~gathmann


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



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] dumping/retrieving window state information

Robin Dunn
>
> The most elegant solution to solve this problem seemed to me to subclass
> the standard wxPython classes and add dump_state() and retrieve_state()
> methods to them. Coming from Tkinter, I thought that I could get a list of
> the
> current Python objects associated with each window at runtime by calling
> the
> GetChildren() method. However, the corresponding method of the wxWindow
> class returns a list of pointers to the underlying C++ objects wrapped by
> the
> wxPython objects and there seems to be no way to access the wrapping Python
> objects directly - is that right?

Correct.  SWIG doesn't correlate object pointers returned from functions with
any existing shadow objects.  I think it would add too much overhead.
Instead it just creates a new shadow.

> If so, is there any other solution to my
> problem?

Since you are subclassing all the window classes anyway, you could keep your
own list of child windows.  One way is to add something to their __init__
methods that appends self to a list in the parent:

    def __init__(self, parent, ID, ....):
        ParentClass.__init__(self, parent, ID, ....)
        self.children = []
        if parent:
            parent.children.append(self)


> And how does the 'Dynamic Class' wxPyValidator fit into that picture?
>

What do you want to do with it?

--
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] dumping/retrieving window state information

Oliver Gathmann
In reply to this post by F. Oliver Gathmann-2

> Since you are subclassing all the window classes anyway, you could
> keep your own list of child windows.  One way is to add something to
> their __init__ methods that appends self to a list in the parent:
>
>     def __init__(self, parent, ID, ....):
>         ParentClass.__init__(self, parent, ID, ....)
>         self.children = []
>         if parent:
>             parent.children.append(self)
>

Thanks; this really seems the way to go.

>
> > And how does the 'Dynamic Class' wxPyValidator fit into that picture?
>
> What do you want to do with it?
>

Well, from (briefly) glancing over the C++ code I got the impression that
wxPyValidator might possibly be an exception to the rule and provide some
mechanism of accessing the wrapping Python objects; I guess I was wrong...

Thanks again,

Oliver

F. Oliver Gathmann ([hidden email])
CRI Inc., 80 Ashford St., 02134 Boston, MA
phone: (617) 787-5700#224 ; fax: (617) 787-4488
web: http://www.scar.utoronto.ca/~gathmann



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