3

I'm having an issue with a GUI that I'm currently building. My app is currently structured with two notebooks side by side, with a terminal/log textCtrl below. The left notebook contains various input and output panels, and the right notebook contains one or more matplotlib figures.

The issue, is that in the left side notebook, I have a page which consists of 3 panels stacked vertically. The first two have standard controls (checkboxes, textctrls, and comboboxes). Below these "settings," is a wx.grid.Grid which contains I/O for some parameters used for plotting in the mpl figure on the right. This grid can get quite large, so I put it into a scrolled panel. Everything works fine in windows, but on linux I'm getting that the y_scroll bar is taller than the height of the visible panel (such that the lower half of the scroll bar is not shown) - if that makes sense.

I put together a small code that has similar issues - the scroll bars are not the same height as the actual panel. What am I doing wrong?

import wx
import wx.grid as grd
import wx.lib.scrolledpanel as scrolled



# A sample panel with some check box controls to take up space, within a
# static box sizer
class SamplePanel(wx.Panel):
    def __init__(self,parent):
        wx.Panel.__init__(self,parent)

        grid = wx.GridBagSizer()
        for i in (0,1):
            grid.Add(wx.StaticText(self,label="Blah Blah: "),pos=(i,0))
            grid.Add(wx.CheckBox(self),pos=(i,1))

        box = wx.StaticBox(self, -1, "Some Settings: ")
        box_sizer = wx.StaticBoxSizer(box,wx.VERTICAL)
        box_sizer.Add(grid, 0, wx.ALL)
        self.SetSizer(box_sizer)
        self.Layout()


# A sample "table" of some parameters, let's say
class SampleGrid(grd.Grid):
    def __init__(self,parent):
        grd.Grid.__init__(self,parent)

        self.CreateGrid(20,4)
        self.SetColLabelValue(0,"Value")
        self.SetColLabelValue(1,"Lo-Bound")
        self.SetColLabelValue(2,"Hi-Bound")
        self.SetColLabelValue(3,"Fit")



# The main panel:        
class AnotherPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self,parent)

        # main sizer for everything:
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        # Add a few "sample panels":
        mainSizer.Add(SamplePanel(self),0,wx.CENTER)
        mainSizer.Add(SamplePanel(self),0,wx.CENTER)
        mainSizer.Add(SamplePanel(self),0,wx.CENTER)

        # Create the grid which will be scrollable:
        scrolledPanel = scrolled.ScrolledPanel(self, size=(425,400))
        table = SampleGrid(scrolledPanel)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(table,1,wx.ALL|wx.EXPAND,5)
        scrolledPanel.SetSizer(sizer)
        scrolledPanel.Layout()
        scrolledPanel.SetupScrolling(scroll_x=False)

        # Put the scrolled panel into a static box:
        box = wx.StaticBox(self,-1,"Parameters: ")
        sizer2 = wx.StaticBoxSizer(box,wx.VERTICAL)
        sizer2.Add(scrolledPanel,1,wx.EXPAND)

        mainSizer.Add(sizer2,1,wx.EXPAND)
        self.SetSizer(mainSizer)
        self.Fit()


# The main frame:
class MainFrame(wx.Frame):
    def __init__(self,parent,title):
        wx.Frame.__init__(self,parent,-1,title=title, size=(850,500))

        # Put 2 panels side by side:        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(AnotherPanel(self),1,wx.EXPAND)
        sizer.Add(AnotherPanel(self),1,wx.EXPAND)

        self.SetSizer(sizer)
        self.SetAutoLayout(1)


# And, the app and mainloop:
app = wx.App(False)
frame = MainFrame(None, "Scroll Test")
frame.Show(True)
app.MainLoop()

Thanks in advance for any help! This is also my first posting, so I apologize in advance for any faux-pas - I tried to avoid any!!! ;)

edit some typos in code, should run fine now

edit 2 on both windows and linux I have Python 2.7.3 (Enthough Canopy distribution), and wxPython 2.8.10.1.

1 Answer 1

1

Just remove the hard coded size of your scrolledPanel instance:

scrolledPanel = scrolled.ScrolledPanel(self)

That worked for me on CentOS with wxPython 2.8.12 and Python 2.6.6

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks - yes this does work in this tester. However, in my actual application when I remove that, I get a scrolled panel that is shorter than the height of one cell in the grid - so effectively nothing is able to show. How can I set the size of the scrolled panel, without running into the issue with the scrollbars?
Are you adding the scrolled panel to a sizer the same way you are in this example? Because it sounds like it's not expanding or the proportion isn't set to 1. Does it snap to the right size if you resize the frame?
Yeah I'm doing almost exactly the same thing - unfortnately there are a few more "layers" involved, so the example I posted was considerably simplified. Resizing does not affect it. :(
Still have not found a really good solution to this, but one way to make it work somewhat is to remove the scrolled panel all together. The grid has scrolling functionality itself, and can be placed directly into the panel. This somewhat fixed the problem in my 'full scale' implementation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.