Splitter with notebook left, one of multiple notebooks right -- best way?

Bob Klahn wrote:

In a splitter, I have a panel on the left and a panel on the right, and each panel contains a standard notebook.

But now, I need to support a separate right-side notebook for each left-side notebook page. At any time, only the right-side notebook corresponding to the current left-side notebook page will be displayed.

Right-side notebooks will be created/destroyed only when the corresponding left-side notebook pages are created/destroyed.

I assume you mean when the left-side pages are selected, right?

What's the best way to accomplish this with standard notebooks? Could someone post a simple example?

When you get a page changed event on the left side, create your new notebook for the right side, put it in the right side panel's sizer, hide the old right-side notebook and call the sizer's Layout method. At this point you can Destroy the old notebook (or maybe do it via wx.CallAfter to make sure there are no pending events for it.)

If you don't have a special need to create and destroy the right-side notebooks all the time then I would leave them created and just ensure that the ones you don't want shown are hidden.

···

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

I’m not totally sure I follow what you want to have happen (not sure what you mean by “point to a notebook”), but in basic terms I think you could have a EVT_NOTEBOOK_PAGE_CHANGED handler
for the “master” page (or you could do it for both of them) and then under this handler use .GetSelection() to get the page selected and then use .SetSelection() to set the page in the corresponding notebook to what it is supposed to be.

I’m also wondering if your design might be more complex than is needed. If pages are in a sense locked to each other, why are there two notebooks? (which are typically thought to be independent user controls); instead, what about just having one notebook with two panels on each page?

···

On Dec 8, 2007 6:11 PM, Bob Klahn bobstones@comcast.net wrote:

Thanks, Robin. And yes, I meant when the left-side pages are
selected.

And no, I don’t want to destroy the already-opened left- or right-side
notebooks without an explicit user request to do so. I need to be
able to keep them around “as is,” i.e., with all their
current-state info, on all their various pages, intact.

A related question: The notebooks on the left and right
sides of my splitter are accessed as mainframe.nb1 and
mainframe.nb2. When the user selects a different left-side page,
I’d like mainframe.nb2 to be repointed to the right-side notebook
corresponding to that left-side page. I.e., I’d like mainframe.nb2
to always point to the currently displayed right-side notebook, as that
simplifies the code in all the other modules, classes, methods, and
functions that access the right-side notebook.

How might I accomplish that? I have yet to find a good way.
(I realize that I’m probably missing something very basic here.)

I think you've got it now, but I believe you misspoke, and that you meant to say:
"Let me try to understand what one will see on the screen again. You want a notebook on the left hand side of a splitter. Each time you select a page in that notebook, a different whole notebook (which is itself relevant to the page shown in the notebook on the left) is displayed on the right hand side of the splitter."

BTW, I have most of this in place now. What I don't have in place is the coordination between the left and right sides of the splitter. As I said late last night, I'm now thinking that the best way to handle this is to keep the right-side notebooks in a dictionary, the keys to which will be the names of the left-side-notebook pages.

Bob

···

At 12:23 AM 12/9/2007, C M wrote:

Let me try to understand what one will see on the page again. You want a notebook on the left hand side of a splitter. Each time you select a page in that notebook, a different whole notebook (which is itself relevant to the page shown in the notebook on the right) is displayed on the right hand side of the splitter. Is that it?

Thanks yet again, Robin. Yes, the notebooks will be extremely dynamic. So, because the overriding on-screen relationships are left-to-right one-to-many, I've gone ahead with a single notebook on the left, and a dictionary of notebooks on the right, one right-side notebook for every left-side notebook page.

Occasionally two left-side pages will be related, in which case the user may very well want to see both right-side notebooks simultaneously. This dictionary approach, along with a simple box sizer, will make that extremely easy to accomplish. That would have been much harder to implement using the architecture I was first considering.

Bob

···

At 01:25 PM 12/10/2007, Robin Dunn wrote:

Bob Klahn wrote:

_A related question:_ The notebooks on the left and right sides of my splitter are accessed as mainframe.nb1 and mainframe.nb2. When the user selects a different left-side page, I'd like mainframe.nb2 to be repointed to the right-side notebook corresponding to that left-side page. I.e., I'd like mainframe.nb2 to always point to the currently displayed right-side notebook, as that simplifies the code in all the other modules, classes, methods, and functions that access the right-side notebook.
How might I accomplish that? I have yet to find a good way. (I realize that I'm probably missing something very basic here.)

Just make the nb2 variable be an alias to the real notbook variable for the currently shown notebook. In Python all variables are just references to an object, and you can have as many references to the same object as needed. So for example, if your notebooks are created and assigned to mainframe.fooNB and mainframe.barNB then when one of them is shown (and the other(s) hidden) you can simply do something like mainframe.nb2 = mainframe.fooNB so set the nb2 variable to refer to the current notebook object.

OTOH, it sounds like your notebooks will be more dynamic, so perhaps a dynamic data structure would be a better way to track them instead of using fixed variable names for each of them.