FoldPanelBar and ScrolledPanel

I’m trying to build a frame which contains a ScrolledPanel with a vertical box sizer containing:

a horizontal sizer across the top with a few buttons and lights,

followed by a matplotlib toolbar added as a regular window,

Then, a FoldPanelBar with separate “items” (in FPB speak) for individual plots.
R.

I’d like to be able to present way more information in plots than can be viewed at a single time. With the FPB, I’d like to give the user the ability to pick which plots they’d like to see. This is for data analysis and depending on where discussion leads, it may be desirable to quickly switch between different sets of visible plots for comparisons.

  1. I’ve been having issues with simply trying to embed a FPB in a panel since it doesn’t seem to ever be sized properly. The FPB is always wx.Size(0,0). I’ve tried a bit of code I found in one of Andrea’s examples and have that issue somewhat resolved. However, when you make the panel into a ScrolledPanel, all sorts of weirdness happens. The FPB will start to expand horizontally while resizing the frame such that when you stop resizing, the horizontal virtual(proper term?) size will be bigger than the actual window size when it wasn’t before.

  2. Does anyone have an example somewhat resembling what I’ve described? It doesn’t have to be plots, of course.

  3. Should I be taking a different approach altogether?

Thank you,

R.

P.S. Thanks Robin, for the quick response before on the different Sizes and the wiki page. That has helped quite a bit.

PGP.sig (186 Bytes)

Hi , Richard ( a quick answer )

i think you could find what u search ( some pieces ) in the xw demo folder
/Developer/Examples/wxWidgets/wxPython/demo

-plum

···

I'm trying to build a frame which contains a ScrolledPanel with a vertical box sizer containing:

a horizontal sizer across the top with a few buttons and lights,

followed by a matplotlib toolbar added as a regular window,

Then, a FoldPanelBar with separate "items" (in FPB speak) for individual plots.
R.
I'd like to be able to present way more information in plots than can be viewed at a single time. With the FPB, I'd like to give the user the ability to pick which plots they'd like to see. This is for data analysis and depending on where discussion leads, it may be desirable to quickly switch between different sets of visible plots for comparisons.

1. I've been having issues with simply trying to embed a FPB in a panel since it doesn't seem to ever be sized properly. The FPB is always wx.Size(0,0). I've tried a bit of code I found in one of Andrea's examples and have that issue somewhat resolved. However, when you make the panel into a ScrolledPanel, all sorts of weirdness happens. The FPB will start to expand horizontally while resizing the frame such that when you stop resizing, the horizontal virtual(proper term?) size will be bigger than the actual window size when it wasn't before.

2. Does anyone have an example somewhat resembling what I've described? It doesn't have to be plots, of course.

3. Should I be taking a different approach altogether?

Thank you,

R.

P.S. Thanks Robin, for the quick response before on the different Sizes and the wiki page. That has helped quite a bit.

Hello Richard,

  1. I’ve been having issues with simply trying to embed a FPB in a panel

since it doesn’t seem to ever be sized properly. The FPB is always wx.Size(0,0).

I’ve tried a bit of code I found in one of Andrea’s examples and have that issue

somewhat resolved. However, when you make the panel into a ScrolledPanel, all

sorts of weirdness happens. The FPB will start to expand horizontally while

resizing the frame such that when you stop resizing, the horizontal virtual(proper

term?) size will be bigger than the actual window size when it wasn’t before.

Uhm, I have never tried to put a FPB in a scrolledpanel, but I wasn’t expecting much trouble from that.

  1. Does anyone have an example somewhat resembling what I’ve described?

It doesn’t have to be plots, of course.

Not with a scrolledpanel, every time I use it I run into troubles :smiley:

  1. Should I be taking a different approach altogether?

Well, I use the same approach for data analysis in my apps, but I set up things using PyAUI or wxAUI without ScrollingThings. However, if you have a sample code, it may help us a lot.

Andrea.

···

Andrea Gavana
(gavana@kpo.kz)

Reservoir Engineer

KPDL

4, Millbank

SW1P 3JA London

Direct Tel: +44 (0) 20 717 08936

Mobile Tel: +44 (0) 77 487 70534

Fax: +44 (0) 20 717 08900

Web:
http://xoomer.virgilio.it/infinity77

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

> 2. Does anyone have an example somewhat resembling what I've described?
> It doesn't have to be plots, of course.

Not with a scrolledpanel, every time I use it I run into troubles :smiley:

I've had pretty decent success with it for simple things like a frame with a single notebook inside a scrolled panel. That works pretty well. When I found your FoldPanelBar, I immediately thought that it would be a useful way to implement extra panels on a frame for things like ">> Advanced Options" or ">> More" buttons commonly seen.

> 3. Should I be taking a different approach altogether?

Well, I use the same approach for data analysis in my apps, but I set up things using PyAUI or wxAUI without ScrollingThings. However, if you have a sample code, it may help us a lot.

I'll post it up today. I didn't have my code in a stripped down form for uploading when I wrote the first e-mail. I'll strip it down to some sin(x) plots. :slight_smile:

BTW Is there a trick to embedding a FPB in a panel? I couldn't get it to work at first until I copied some code from one of your demos and then it seems to work after that. Here's the bit I snagged (marked in comments). This is an early test just trying to place two plots in a FPB and then into a scrolled window. There are no extra sizers or toolbars.

class AnalysisPlotFrame(wx.Frame):
     def __init__(self, title=None):
         title = 'Untitled Plot Analysis'

         # Initialize the Frame base class
         wx.Frame.__init__(self,parent,-1,title,size=(550,350),name='plot'+str(FrameCount))

         # bind the close event
         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

         # Keep track of the ACTIVATE event for printing purposes
         self.Bind(wx.EVT_ACTIVATE, self.OnActivate)

  #this indentation is a product of bad cut & paste into Mail
             panel = scrolled.ScrolledPanel(self, -1)
             self.CreateFPB(panel) #uses panel as the parent
             sizer = wx.BoxSizer(wx.VERTICAL)
             # This was experimental and so I just grabbed the variable this way
             sizer.Add(self._pnl, 1, wx.ALL | wx.GROW | wx.EXPAND)
             panel.SetSizerAndFit(sizer)
             panel.SetupScrolling()

             # The snagged (and modified to fit here) code from FoldTestPanel although that panel
             # is in reverse of what I want (a FPB in a panel)
             sizer.Fit(panel)
             sizer.SetSizeHints(panel)
             panel.Centre()
             sizer.Layout()

     def CreateFPB(self, parent=None):
         if not parent:
             parent = self

         # recreate the foldpanelbar
         fpb_flags=0
         self._pnl = fpb.FoldPanelBar(parent, -1, wx.DefaultPosition, wx.DefaultSize,
                                      fpb.FPB_DEFAULT_STYLE | fpb.FPB_VERTICAL, fpb_flags)

         Images = wx.ImageList(16,16)
         Images.Add(GetExpandedIconBitmap())
         Images.Add(GetCollapsedIconBitmap())

         item = self._pnl.AddFoldPanel("Data Plot", collapsed=False,
                                       foldIcons=Images)

         # Create the main plot
         # This just creates a matplotlib.figure(), puts a sin wave in it, and creates a FigureCanvasWxAgg
         # using it. "item" is used as the parent for FigureCanvas()
         self.canvas = self.GetDataFigureCanvas(item)

         # Add it to item
         self._pnl.AddFoldPanelWindow(item, self.canvas,
                                      fpb.FPB_ALIGN_WIDTH, 0, 0)

         item2 = self._pnl.AddFoldPanel("Secondary Data Plot", collapsed=True,
                                       foldIcons=Images)
         # Create the secondary plot
         canvas2 = self.GetDataFigureCanvas(item2)

         # Add it to item2
         self._pnl.AddFoldPanelWindow(item2, canvas2,
                                      fpb.FPB_ALIGN_WIDTH, 0, 0)

Thanks for the help,

R.

PGP.sig (186 Bytes)

On a related note, how do I add a key event to this frame. I've tried various combinations of the following, but the event handler, OnKeyPressed, is never called.

             self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed, self)
             self.Bind(wx.EVT_CHAR, self.OnKeyPressed, self)
             self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed, self.canvas)
             self.Bind(wx.EVT_CHAR, self.OnKeyPressed, self.canvas)
             self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed, panel)
             self.Bind(wx.EVT_CHAR, self.OnKeyPressed, panel)

             # The frame itself
             self.SetFocus()
             # The figure canvas
             self.canvas.SetFocus()
             # the root-most panel that everything sits on.
             panel.SetFocus()

PGP.sig (186 Bytes)

···

On Sep 14, 2006, at 10:36 AM, Richard Harvey Chapman wrote:

> 2. Does anyone have an example somewhat resembling what I've described?
> It doesn't have to be plots, of course.

Not with a scrolledpanel, every time I use it I run into troubles :smiley:

I've had pretty decent success with it for simple things like a frame with a single notebook inside a scrolled panel. That works pretty well. When I found your FoldPanelBar, I immediately thought that it would be a useful way to implement extra panels on a frame for things like ">> Advanced Options" or ">> More" buttons commonly seen.

> 3. Should I be taking a different approach altogether?

Well, I use the same approach for data analysis in my apps, but I set up things using PyAUI or wxAUI without ScrollingThings. However, if you have a sample code, it may help us a lot.

I'll post it up today. I didn't have my code in a stripped down form for uploading when I wrote the first e-mail. I'll strip it down to some sin(x) plots. :slight_smile:

BTW Is there a trick to embedding a FPB in a panel? I couldn't get it to work at first until I copied some code from one of your demos and then it seems to work after that. Here's the bit I snagged (marked in comments). This is an early test just trying to place two plots in a FPB and then into a scrolled window. There are no extra sizers or toolbars.

class AnalysisPlotFrame(wx.Frame):
    def __init__(self, title=None):
        title = 'Untitled Plot Analysis'

        # Initialize the Frame base class
        wx.Frame.__init__(self,parent,-1,title,size=(550,350),name='plot'+str(FrameCount))

        # bind the close event
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        # Keep track of the ACTIVATE event for printing purposes
        self.Bind(wx.EVT_ACTIVATE, self.OnActivate)

  #this indentation is a product of bad cut & paste into Mail
            panel = scrolled.ScrolledPanel(self, -1)
            self.CreateFPB(panel) #uses panel as the parent
            sizer = wx.BoxSizer(wx.VERTICAL)
            # This was experimental and so I just grabbed the variable this way
            sizer.Add(self._pnl, 1, wx.ALL | wx.GROW | wx.EXPAND)
            panel.SetSizerAndFit(sizer)
            panel.SetupScrolling()

            # The snagged (and modified to fit here) code from FoldTestPanel although that panel
            # is in reverse of what I want (a FPB in a panel)
            sizer.Fit(panel)
            sizer.SetSizeHints(panel)
            panel.Centre()
            sizer.Layout()

    def CreateFPB(self, parent=None):
        if not parent:
            parent = self

        # recreate the foldpanelbar
        fpb_flags=0
        self._pnl = fpb.FoldPanelBar(parent, -1, wx.DefaultPosition, wx.DefaultSize,
                                     fpb.FPB_DEFAULT_STYLE | fpb.FPB_VERTICAL, fpb_flags)

        Images = wx.ImageList(16,16)
        Images.Add(GetExpandedIconBitmap())
        Images.Add(GetCollapsedIconBitmap())

        item = self._pnl.AddFoldPanel("Data Plot", collapsed=False,
                                      foldIcons=Images)

        # Create the main plot
        # This just creates a matplotlib.figure(), puts a sin wave in it, and creates a FigureCanvasWxAgg
        # using it. "item" is used as the parent for FigureCanvas()
        self.canvas = self.GetDataFigureCanvas(item)

        # Add it to item
        self._pnl.AddFoldPanelWindow(item, self.canvas,
                                     fpb.FPB_ALIGN_WIDTH, 0, 0)

        item2 = self._pnl.AddFoldPanel("Secondary Data Plot", collapsed=True,
                                      foldIcons=Images)
        # Create the secondary plot
        canvas2 = self.GetDataFigureCanvas(item2)

        # Add it to item2
        self._pnl.AddFoldPanelWindow(item2, canvas2,
                                     fpb.FPB_ALIGN_WIDTH, 0, 0)

Thanks for the help,

R.

R.

Gavana, Andrea:

Hello Richard,

1. I've been having issues with simply trying to embed a FPB in a panel
since it doesn't seem to ever be sized properly. The FPB is always

wx.Size(0,0).

I've tried a bit of code I found in one of Andrea's examples and have

that issue

somewhat resolved. However, when you make the panel into a

ScrolledPanel, all

sorts of weirdness happens. The FPB will start to expand horizontally

while

resizing the frame such that when you stop resizing, the horizontal

virtual(proper

term?) size will be bigger than the actual window size when it wasn't

before.
Uhm, I have never tried to put a FPB in a scrolledpanel, but I wasn't expecting much trouble from that.

Hi Andrea,

For Task Coach, I used your excellent widget to implement a filtering side bar. Like Richard, I tried to put the FPB in a scrolledpanel so that when all panels are expanded users can scroll the FPB up and down. I have seen the exact same behavior as Richard describes. I put the issue aside hoping to solve it later, but now it seems it is not just my stupidity I can't get it to work I dare to ask: please give us an example of a FPB in a scrolledpanel?

Thanks in advance, Frank

Richard Harvey Chapman wrote:

On a related note, how do I add a key event to this frame. I've tried various combinations of the following, but the event handler, OnKeyPressed, is never called.

            self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed, self)
            self.Bind(wx.EVT_CHAR, self.OnKeyPressed, self)
            self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed, self.canvas)
            self.Bind(wx.EVT_CHAR, self.OnKeyPressed, self.canvas)
            self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed, panel)
            self.Bind(wx.EVT_CHAR, self.OnKeyPressed, panel)

            # The frame itself
            self.SetFocus()
            # The figure canvas
            self.canvas.SetFocus()
            # the root-most panel that everything sits on.
            panel.SetFocus()

Key and char events are only sent to the widget that currently has the keyboard focus, and Frames can't have it, and if a panel has focusable children then a panel won't have it either. If you are wanting to have a way to respond to a particular key from anywhere in the app then using a menu accelerator is the way to do it. You can either add "\tkeyname" to the text for a menu item and the accelerator will automatically be created, or you can use a wx.AcceleratorTable and attach it to your frame.

···

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

Richard Harvey Chapman wrote:

1. I've been having issues with simply trying to embed a FPB in a panel since it doesn't seem to ever be sized properly. The FPB is always wx.Size(0,0). I've tried a bit of code I found in one of Andrea's examples and have that issue somewhat resolved. However, when you make the panel into a ScrolledPanel, all sorts of weirdness happens. The FPB will start to expand horizontally while resizing the frame such that when you stop resizing, the horizontal virtual(proper term?) size will be bigger than the actual window size when it wasn't before.

I'm not sure I completely follow your description of the window hierarchy, but this sounds like what happens when a container window without children is put in a sizer with proportion or expand flags set. Since its best size will always be its current size, the sizer will always let it grow but won't let it shrink. The workaround is to explicitly give it a min size.

···

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

Hi all,

    well, I did come up with a solution similar to what Robin
proposed. Here is the implementation. I know it's not perfect, but
feel free to report any problems and/or improvements, they are always
welcome :smiley:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.virgilio.it/infinity77/

fpbprova.py (6.17 KB)

Andrea Gavana:

Hi all,

   well, I did come up with a solution similar to what Robin
proposed. Here is the implementation. I know it's not perfect, but
feel free to report any problems and/or improvements, they are always
welcome :smiley:

Hi Andrea, thanks a lot. I played a bit with your demo and noticed that the height of the scrolledpanel keeps growing when one resizes the panel. To try it out: grab the separator with your mouse and drag it left and right a couple of times. Notice (look at the scrollbar) how the height of the scrolledpanel keeps increasing...

Cheers, Frank

Hello Frank,

Hi Andrea, thanks a lot. I played a bit with your demo and noticed that
the height of the scrolledpanel keeps growing when one resizes the
panel. To try it out: grab the separator with your mouse and drag it
left and right a couple of times. Notice (look at the scrollbar) how the
height of the scrolledpanel keeps increasing...

I don't see such continuous increase. I can grab it left and right 20
times, and the only thing I can notice is that every time the
*horizontal* scrolled bar appears (I am shrinking the panel) the
height of the scrolledpanel seems to be slightly bigger. But once I
drag right and make the horizontal scrollbar disappear, everything is
restored as before. I don't have a continuous increase.
At this point, I would say that either it is a platform issue (I don't
know on which platform you tested it) or a wxPython version issue.

Here is Windows XP, Python 2.4.3, wxPython latest pre-release.

Ah, completely off-topic: regarding the latest pre-release: it seems
to me that wx.lib.plot is broken, ostly because numpy and Numeric are
now perfectly *incompatible*. Numeric still has attributes like
Float64, Int32 and so on, while numpy does not recognize them anymore.
I wonder if we should fix it right now or wait that the numpy guys
*finally* decide which attributes they will keep and which they will
delete.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

Andrea Gavana:

I don't see such continuous increase. I can grab it left and right 20
times, and the only thing I can notice is that every time the
*horizontal* scrolled bar appears (I am shrinking the panel) the
height of the scrolledpanel seems to be slightly bigger. But once I
drag right and make the horizontal scrollbar disappear, everything is
restored as before. I don't have a continuous increase.
At this point, I would say that either it is a platform issue (I don't
know on which platform you tested it) or a wxPython version issue.

Here is Windows XP, Python 2.4.3, wxPython latest pre-release.

It seems to be wxPython version issue. My platform: Windows XP, Python 2.4.1, wxPython 2.6.3.2 and wxPython 2.7 latest prerelease.
With 2.6 I see the behaviour described, with 2.7 not. The only issue with 2.7 is that the initial height of the scrolledpanel is about twice the height actually needed to fit all expanded foldpanels.

Cheers, Frank