Same widget instance in multiple locations

Dear all,

I have a wx.Notebook where I’d like to show the same information on all pages (that is, part of the information would be the same on all pages).

The information is shown in a wx.FoldPanelBar to enable saving space.

It would make sense to share the state (collapsed, expanded) of the panels across the notebook pages.

IMHO the best solution would be to create the FoldPanelBar instance once and add it to all pages.

The alternative is to have multiple instances and sync them i.e. using pubsub.

I gave using the same instance at multiple locations a try, but it does not seem to work - it looks as if it was not added to the sizer.

My question is: is it possible to have the same instance at multiple locations?

Thanks in advance for any insight!

Gabor

No, the UI objects can only be on one parent at a time. However, you could separate the UI from the state and data values, and then share the data/state with multiple UI object instances. Look up info for the MVC and MVP design patterns for ideas.

···

On Sunday, June 2, 2019 at 11:33:12 PM UTC-7, Jakab Gábor wrote:

Dear all,

I have a wx.Notebook where I’d like to show the same information on all pages (that is, part of the information would be the same on all pages).

The information is shown in a wx.FoldPanelBar to enable saving space.

It would make sense to share the state (collapsed, expanded) of the panels across the notebook pages.

IMHO the best solution would be to create the FoldPanelBar instance once and add it to all pages.

The alternative is to have multiple instances and sync them i.e. using pubsub.

I gave using the same instance at multiple locations a try, but it does not seem to work - it looks as if it was not added to the sizer.

My question is: is it possible to have the same instance at multiple locations?

Robin

Thank you Mr. Dunn.

I ended up solving the problem by using the method bound to the CaptionBar event to report the page and panel index activated to the parent notebook (that holds multiple pages, each with a foldbar). This then determines if collapsing or opening is needed and iterates the pages to sync them. Not necessarily a design pattern but is simple and works well.

···

On Monday, June 3, 2019 at 5:34:07 PM UTC+2, Robin Dunn wrote:

On Sunday, June 2, 2019 at 11:33:12 PM UTC-7, Jakab Gábor wrote:

Dear all,

I have a wx.Notebook where I’d like to show the same information on all pages (that is, part of the information would be the same on all pages).

The information is shown in a wx.FoldPanelBar to enable saving space.

It would make sense to share the state (collapsed, expanded) of the panels across the notebook pages.

IMHO the best solution would be to create the FoldPanelBar instance once and add it to all pages.

The alternative is to have multiple instances and sync them i.e. using pubsub.

I gave using the same instance at multiple locations a try, but it does not seem to work - it looks as if it was not added to the sizer.

My question is: is it possible to have the same instance at multiple locations?

No, the UI objects can only be on one parent at a time. However, you could separate the UI from the state and data values, and then share the data/state with multiple UI object instances. Look up info for the MVC and MVP design patterns for ideas.

Robin