简体   繁体   English

当您将框架捕捉到Microsoft Windows中的屏幕一侧时,wx.ScrolledWindow中的wxpython GridBagSizer无法正确调整大小

[英]wxpython GridBagSizer inside a wx.ScrolledWindow not resizing correctly when you snap the Frame to a side of the screen in Microsoft Windows

EDIT: This seems to only happen in MS Windows 7 Pro and MS Windows 7 Home. 编辑:这似乎仅在MS Windows 7 Pro和MS Windows 7 Home中发生。 It doesn't happen in Ubuntu 10.04. 在Ubuntu 10.04中不会发生这种情况。

Here's some example code of the problem I'm having: 这是我遇到的问题的一些示例代码:

import wx as wx

class MainFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        #Panel that holds all the other panels
        self.mainPanel = wx.ScrolledWindow(self, -1)
        self.mainPanel.SetScrollbars(1, 1, 1, 1)
        self.mainPanel.SetBackgroundColour("LIGHT GREY")

        #Panels in mainPanel
        self.lefttopPanel = wx.Panel(self.mainPanel, -1)
        self.lefttopPanel.SetBackgroundColour("WHITE")        
        self.sizewidgets(self.panelwidgets(
                         text='Left Top Panel', 
                         num=12,
                         parent=self.lefttopPanel),
                         parent=self.lefttopPanel)        

        self.leftmiddlePanel = wx.Panel(self.mainPanel, -1)
        self.leftmiddlePanel.SetBackgroundColour("WHITE")        
        self.sizewidgets(self.panelwidgets(
                         text='Left Middle Panel',
                         num=6,
                         parent=self.leftmiddlePanel),
                         parent=self.leftmiddlePanel)

        self.leftbottomPanel = wx.Panel(self.mainPanel, -1)
        self.leftbottomPanel.SetBackgroundColour("WHITE")
        self.sizewidgets(self.panelwidgets(
                         text='Left Bottom Panel',
                         num=8,
                         parent=self.leftbottomPanel),
                         parent=self.leftbottomPanel)

        self.righttopPanel = wx.Panel(self.mainPanel, -1)
        self.righttopPanel.SetBackgroundColour("WHITE")        
        self.sizewidgets(self.panelwidgets(
                         text='Right Top Panel',
                         num=8,
                         parent=self.righttopPanel),
                         parent=self.righttopPanel)

        self.rightbottomPanel = wx.Panel(self.mainPanel, -1)
        self.rightbottomPanel.SetBackgroundColour("WHITE")
        self.sizewidgets(self.panelwidgets(
                         text='Right Bottom Panel',
                         num=8,
                         parent=self.rightbottomPanel),
                         parent=self.rightbottomPanel)


        mpsizer = wx.GridBagSizer(vgap=4, hgap=4)
        mpsizer.Add(self.lefttopPanel, pos=(0,0), span=(1,1), flag=wx.EXPAND)
        mpsizer.Add(self.leftmiddlePanel, pos=(1,0), span=(1,1), flag=wx.EXPAND)
        mpsizer.Add(self.leftbottomPanel, pos=(2,0), span=(1,2), flag=wx.EXPAND)
        mpsizer.Add(self.righttopPanel, pos=(0,1), span=(2,2), flag=wx.EXPAND)
        mpsizer.Add(self.rightbottomPanel, pos=(2,2), span=(1,1), flag=wx.EXPAND)
        mpsizer.AddGrowableCol(1)
        mpsizer.AddGrowableRow(1)
        self.mainPanel.SetSizer(mpsizer)

        #Adding a refresh to resize event
        self.Bind(wx.EVT_SIZE, self.OnResize)

        self.Show()

    def OnResize(self, event):
        self.Refresh()
        event.Skip()

    def sizewidgets(self, widgetlist , parent):
        psizer = wx.GridSizer(cols=2, vgap=5,hgap=5)
        for widget in widgetlist:
            psizer.Add(widget)
        parent.SetSizer(psizer)



    def panelwidgets(self, text, num, parent):
        widgets = []
        for i in range(num):
            widgets += [wx.StaticText(parent, label=text)]
        return widgets

if __name__ == "__main__":
    app = wx.App()
    MainFrame(None, size=(800, 800), title="GridBagSizer Problem")
    app.MainLoop()

Without the refresh on EVT_SIZE it causes some of the widgets to be drawn incorrectly. 如果没有刷新EVT_SIZE,它会导致某些窗口小部件无法正确绘制。 Here's an example of what it looks like ( http://i.stack.imgur.com/tYEF4.png ). 这是一个外观示例( http://i.stack.imgur.com/tYEF4.png )。

If you add a refresh to EVT_SIZE it fixes most of the sizing issues except when you snap the Frame to half of the screen in MS Windows. 如果将刷新添加到EVT_SIZE,则可以解决大多数调整大小的问题,除非在Microsoft Windows中将Frame捕捉到屏幕的一半时。 Here's an example of what that looks like ( http://i.stack.imgur.com/UKTPi.png ). 这是一个看起来像这样的示例( http://i.stack.imgur.com/UKTPi.png )。

What I can't figure out is why it keeps drawing the bottomrightPanel incorrectly. 我不知道的是为什么它会不断错误地绘制bottomrightPanel。 It looks like it draws it from the bottom of that panel instead of from the top. 看起来它是从该面板的底部而不是顶部绘制的。 If you resize the frame at all it redraws it correctly and give you the behavior you'd expect. 如果您完全调整框架的大小,它将正确地重新绘制它,并为您提供预期的行为。

It seems like the growablecolumn is causing the issue but I can't seem to fix it and keep the behavior I want. 似乎growablecolumn引起了问题,但我似乎无法修复它并保持我想要的行为。 I've tried calling self.bottomrightPanel.Layout() on resize but that seems to do nothing. 我试图在调整大小时调用self.bottomrightPanel.Layout(),但这似乎无济于事。 I also tried calling self.bottomrightPanel.Fit() on resize which fixes the issue when you snap the Frame to half of the screen but it screws up the look of the mainPanel (which causes it to look really bad). 我还尝试了在调整大小时调用self.bottomrightPanel.Fit(),从而解决了将Frame捕捉到屏幕一半时出现的问题,但它弄乱了mainPanel的外观(这使它看起来确实很糟糕)。 If anyone out there knows how to fix the problem (without changing the type of sizer which I've already done in my current app) I'd be very appreciative. 如果那里有人知道如何解决该问题(无需更改我在当前应用中已经完成的sizer类型),我将非常感激。

I have a similar problem right now. 我现在有一个类似的问题。 I've narrowed it down to the wx.ScrolledWindow. 我将其范围缩小到wx.ScrolledWindow。 If you can change this to a wx.Panel it may clear up the problem. 如果您可以将其更改为wx.Panel,则可能会解决此问题。 I'm still looking into fixing the scrolled window issue. 我仍在寻找解决滚动窗口问题的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM