newbie question: switching windows

In a nutshell: How can I create 2 different windows with the same parent and alternatively show only one of them?

More specifically. I have 2 different views for the same object and I am trying to implement both of them as SplitterWindow subclasses, both of them as children of the main window. I want to have both windows in memory at the same time and switch between them with a menu command. Is that possible? If so, how? I tried a few things but nothing worked.

Thanks,

Dan

A few more details, as I have been trying some other things. I’ve tried all sorts of combinations of using Show( ) on the children in the SplitterWindow’s and the SplitterWindow’s themselves and Splitting and Unsplitting the SplitterWindows and Layout( ). Is there a sequence of these calls that I have to follow and that I haven’t found? Or are there some other calls that I have to make?

I am not getting any exceptions, but I only get a small, undistinguishable widget in the top left corner.

Dan

···

----- Original Message -----

From:
Dan Perl

To: wxpython-users@lists.wxwidgets.org

Sent: Thursday, October 07, 2004 7:10 PM

Subject: [wxPython-users] newbie question: switching windows

In a nutshell: How can I create 2 different windows with the same parent and alternatively show only one of them?

More specifically. I have 2 different views for the same object and I am trying to implement both of them as SplitterWindow subclasses, both of them as children of the main window. I want to have both windows in memory at the same time and switch between them with a menu command. Is that possible? If so, how? I tried a few things but nothing worked.

Thanks,

Dan

My advice is to use sizers not SplitterWindow, I've had the same problem and using SplitterWindow was also my first choice :slight_smile: BUT the thing that worked in the end for me was something like:
put both windows in a sizer one after the other and call sizer.Hide() on the one that you want hidden then uppon user action (menu, button, whatever) do something like:

sizer.Hide(firstWindow)
sizer.Show(secondWindow)
sizer.Layout()

Maybe it will work for you too.

···

On Thu, 7 Oct 2004 22:52:01 -0400, Dan Perl <dperl@rogers.com> wrote:

A few more details, as I have been trying some other things. I've tried all sorts of combinations of using Show( ) on the children in the SplitterWindow's and the SplitterWindow's themselves and Splitting and Unsplitting the SplitterWindows and Layout( ). Is there a sequence of these calls that I have to follow and that I haven't found? Or are there some other calls that I have to make?

I am not getting any exceptions, but I only get a small, undistinguishable widget in the top left corner.

--
Peter Damoc
Hacker Wannabe

I was using a sizer initially and I replaced it with the SplitterWindow, so the latter is definitely my first choice also. I would still like to keep it instead of moving back to sizers.

I even have another way around the problem: considering the fact that both views use a SplitterWindow, I keep it shown all the time, but I alternately hide and show the children. This is going to fall apart if I decide to move away from a SplitterWindow in one of the views and then going back to a sizer will be more compelling. But for now I'll try to stay with the SplitterWindow's.

Thanks for letting me know though that I'm not alone. It may mean that there is no good solution and we have to live with one of the compromises.

I'm trying to reproduce the problem in a code snippet and show it here, maybe someone will still be able to point a better way to do it. If there is still no solution, then I'll move on with one of the compromises.

Dan

···

----- Original Message ----- From: "Peter Damoc" <pdamoc@gmx.net>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Friday, October 08, 2004 2:21 AM
Subject: Re: [wxPython-users] newbie question: switching windows

On Thu, 7 Oct 2004 22:52:01 -0400, Dan Perl <dperl@rogers.com> wrote:

A few more details, as I have been trying some other things. I've tried all sorts of combinations of using Show( ) on the children in the SplitterWindow's and the SplitterWindow's themselves and Splitting and Unsplitting the SplitterWindows and Layout( ). Is there a sequence of these calls that I have to follow and that I haven't found? Or are there some other calls that I have to make?

I am not getting any exceptions, but I only get a small, undistinguishable widget in the top left corner.

My advice is to use sizers not SplitterWindow, I've had the same problem and using SplitterWindow was also my first choice :slight_smile: BUT the thing that worked in the end for me was something like:
put both windows in a sizer one after the other and call sizer.Hide() on the one that you want hidden then uppon user action (menu, button, whatever) do something like:

sizer.Hide(firstWindow)
sizer.Show(secondWindow)
sizer.Layout()

Maybe it will work for you too.
--
Peter Damoc
Hacker Wannabe
http://www.sigmacore.net/

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

That's a good idea... we might be talking about different things here :smiley:

···

On Fri, 8 Oct 2004 08:26:38 -0400, Dan Perl <dperl@rogers.com> wrote:

I'm trying to reproduce the problem in a code snippet and show it here, maybe someone will still be able to point a better way to do it. If there is still no solution, then I'll move on with one of the compromises.

--
Peter Damoc
Hacker Wannabe

Here is a code snippet to illustrate the problem (also attached):
    #!/usr/bin/env python
    import wx

    class myFrame(wx.Frame):
        def __init__(self, parent):
            wx.Frame.__init__(self,
                              parent=parent)
            self.SetClientSize(wx.Size(600, 500))
            self.splitter1=wx.SplitterWindow(self)
            self.splitter1.Hide()
            #self.splitter2=wx.SplitterWindow(self) # un-comment and you'll
            #self.splitter2.Hide() # see the problem
        def showSplitter(self, id):
            if id==1:
                self.splitter1.Show()
            if id==2:
                self.splitter2.Show()

    class myApp(wx.App):
        def OnInit(self):
            wx.InitAllImageHandlers()
            self.mainWin = myFrame(None)
            self.mainWin.Show()
            self.SetTopWindow(self.mainWin)
            self.mainWin.showSplitter(1)

            return True

    if __name__ == '__main__':
        application = myApp(0)
        application.MainLoop()

I have cut it down to the bone, so there are no children in the SplitterWindow's and they are not even splitted. I assure you that the same is happening in those cases. I am not invoking any Layout( ) here, but I've tried that too.

The above example actually works. But un-comment the 2 lines for splitter2 and you will see the problem.

So am I missing a step somewhere? Or could this actually be a bug in SplitterWindow?

Dan

toto.py (928 Bytes)

I've changed your file a little bit to give you an idea about what I meant :wink:
see if this solves your problem.
In theory it should start with the second SplitterWindow visible and in about 4 secs switch to the first SplitterWindow (red and green)

toto.py (1.63 KB)

···

On Fri, 8 Oct 2004 10:08:44 -0400, Dan Perl <dperl@rogers.com> wrote:

The above example actually works. But un-comment the 2 lines for splitter2
and you will see the problem.

So am I missing a step somewhere? Or could this actually be a bug in
SplitterWindow?

Dan

--
Peter Damoc
Hacker Wannabe

Yes, that's does what I need. I thought your first answer was to replace the SplitterWindow with a sizer (isn't that what you meant?). This solution is to put both SplitterWindow's in a sizer and 'Show' only one of them. Is this a common use for sizers?

And there is still a question left in my mind. Why is this problem happening? What changes when the second SplitterWindow gets created that changes the behavior of the whole thing?

Dan

PS: Multzumesc mult

···

----- Original Message ----- From: "Peter Damoc" <pdamoc@gmx.net>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Friday, October 08, 2004 10:36 AM
Subject: Re: [wxPython-users] newbie question: switching windows

On Fri, 8 Oct 2004 10:08:44 -0400, Dan Perl <dperl@rogers.com> wrote:

The above example actually works. But un-comment the 2 lines for
splitter2
and you will see the problem.

So am I missing a step somewhere? Or could this actually be a bug in
SplitterWindow?

Dan

I've changed your file a little bit to give you an idea about what I meant
:wink:
see if this solves your problem.
In theory it should start with the second SplitterWindow visible and in
about 4 secs switch to the first SplitterWindow (red and green)

--
Peter Damoc
Hacker Wannabe
http://www.sigmacore.net/

--------------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Yes, that's does what I need. I thought your first answer was to replace the SplitterWindow with a sizer (isn't that what you meant?). This solution is to put both SplitterWindow's in a sizer and 'Show' only one of them. Is this a common use for sizers?

well... I thought you wanna use the SplitterWindow to show or hide a certain Panel (as in a child of that splitter window)

Sizers are used for layout... think of them as some kind of Layout Managers.

And there is still a question left in my mind. Why is this problem happening? What changes when the second SplitterWindow gets created that changes the behavior of the whole thing?

Well, when there is only one element inside a window we can assume that it should occupy the entire window... so you benefit from a little magic but when there are 2 children... that magic is gone and you need to use some kind of mechanism to size and place your widgets. Most common is the use of sizers...
as a rule you should manage the layout of the widgets... don't rely on default behaviour.
Without sizers... the components are stacked one on top of the other in the upper left corner of the window...

Dan

PS: Multzumesc mult

You're wellcome :smiley:

···

On Fri, 8 Oct 2004 10:58:00 -0400, Dan Perl <dperl@rogers.com> wrote:

--
Peter Damoc
Hacker Wannabe

Dan Perl wrote:

And there is still a question left in my mind. Why is this problem happening?

When a wx.Frame has only one child window (besides menubar, toolbar, statusbar) then it will automatically size it to fill the whole client area of the frame. When there is more than one it is up to you to tell it how to manage the size and placement.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks, Robin. Peter gave pretty much the same explanation and I was already clear on it, but (no offense Peter!) it is another thing to get the explanation from the author himself!

Dan

···

----- Original Message ----- From: "Robin Dunn" <robin@alldunn.com>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Friday, October 08, 2004 3:56 PM
Subject: Re: [wxPython-users] newbie question: switching windows

Dan Perl wrote:

And there is still a question left in my mind. Why is this problem happening?

When a wx.Frame has only one child window (besides menubar, toolbar, statusbar) then it will automatically size it to fill the whole client area of the frame. When there is more than one it is up to you to tell it how to manage the size and placement.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org