How can I put a wx.ScrolledWindow inside a wx.SplitterWindow?

I wouldn't have thought this would be so tricky. I'm trying to get
something like this:

X | X

Where both Xs are ScrolledWindows that will ultimately contain lots of
text and '|' is a "splitter" dividing the two. I want something about
like most visual diffs give you. I can't seem to get this to work,
though. My big problem now is that I'm violating some assertions. When
I run it in straight up python, it actually draws approximately what
I'd expect, minus some refinement of the appropriate sizes despite the
constraint violations. My project uses pybliographer, though, which
exits on the constraint violations. Am I doing this wrong? Is there an
easier way to do this?

I've included a simple modification of the splitterwindow example code
(http://zetcode.com/wxpython/widgets/#splitterwindow) to use
scrolledwindows. I first fit the panels inside the scrolledwindows and
then use that to set the scrollbars as in the second example in the
wxpython wiki(http://wiki.wxpython.org/ScrolledWindows).

import wx

class Splitterwindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(350, 300))
        quote = '''Whether you think that you can, or that you can't,
you are usually right'''
        splitter = wx.SplitterWindow(self, -1)
        scroll1 = wx.ScrolledWindow(splitter,-1)
        panel1 = wx.Panel(scroll1, -1)
        wx.StaticText(panel1, -1, quote, (100, 100),
style=wx.ALIGN_CENTRE)
        panel1.SetBackgroundColour(wx.LIGHT_GREY)
        panel1.SetAutoLayout(True)
        panel1.Layout()
        panel1.Fit()
        scroll_unit = 50
        width,height = panel1.GetSizeTuple()
        scroll1.SetScrollbars(scroll_unit,scroll_unit,width/
scroll_unit,height/scroll_unit)
        scroll2 = wx.ScrolledWindow(splitter,-1)
        panel2 = wx.Panel(scroll2, -1)
        wx.StaticText(panel2, -1, quote, (100, 100),
style=wx.ALIGN_CENTRE)
        panel2.SetBackgroundColour(wx.WHITE)
        panel2.SetAutoLayout(True)
        panel2.Layout()
        panel2.Fit()
        scroll_unit = 50
        width,height = panel2.GetSizeTuple()
        scroll2.SetScrollbars(scroll_unit,scroll_unit,width/
scroll_unit,height/scroll_unit)
        splitter.SplitVertically(scroll1, scroll2)
        self.Centre()
        self.Show(True)

app = wx.App()
tmp = Splitterwindow(None, -1, 'splitterwindow.py')
app.MainLoop()

Your example code seems to run fine, and you even said it would. It's
hard to debug a perfectly running program. Without more details, we
can't possibly help you figure out what's going on. What was the
assertion failure? What constraints were violated?

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

There is no need for the extra panels as wx.ScrolledWindow derives from wx.Panel and so it provides everything that wx.Panel does plus scrolling.

Doing SetAutoLayout without a setting a sizer or using layout constraints will have no effect. The same with Layout() and in most cases Fit().

A more intuitive way to set up the scrolling for wx.ScrolledWindow is to just set the virtual size and the scroll rate. Use of the SetScrollbars method is no longer encouraged.

splittertest.py (1.08 KB)

···

On 10/6/10 10:08 AM, Jamie Olson wrote:

I wouldn't have thought this would be so tricky. I'm trying to get
something like this:

X | X

Where both Xs are ScrolledWindows that will ultimately contain lots of
text and '|' is a "splitter" dividing the two. I want something about
like most visual diffs give you. I can't seem to get this to work,
though. My big problem now is that I'm violating some assertions. When
I run it in straight up python, it actually draws approximately what
I'd expect, minus some refinement of the appropriate sizes despite the
constraint violations. My project uses pybliographer, though, which
exits on the constraint violations. Am I doing this wrong? Is there an
easier way to do this?

--
Robin Dunn
Software Craftsman