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 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/开发者_如何学PythonScrolledWindows, sorry new user can't make two hyperlinks).
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()
What's wrong with the example? For me it works as expected.
精彩评论