wxPython CollapsiblePane 奇怪的剪切问题 [英] wxPython CollapsiblePane strange clipping issue

查看:26
本文介绍了wxPython CollapsiblePane 奇怪的剪切问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 以正常工作.它不起作用的原因是您忘记绑定 wx.EVT_COLLAPSIBLEPANE_CHANGED.这是一个对我有用的代码 -

import wx类 SampleCollapsiblePane(wx.CollapsiblePane):def __init__(self, *args, **kwargs):wx.CollapsiblePane.__init__(self,*args,**kwargs)sizer = wx.BoxSizer(wx.VERTICAL)对于范围内的 x(5):sizer.Add(wx.Button(self.GetPane(), label = str(x)))self.GetPane().SetSizer(sizer)self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.on_change)def on_change(self, event):self.GetParent().Layout()类 Main_Frame(wx.Frame):def __init__(self, *args, **kwargs):wx.Frame.__init__(self, *args, **kwargs)self.main_panel = wx.Panel(self)sizer = wx.BoxSizer(wx.VERTICAL)对于范围内的 x(5):sizer.Add(SampleCollapsiblePane(self.main_panel, label = str(x)), 0)self.main_panel.SetSizer(sizer)类 SampleApp(wx.App):def OnInit(self):frame = Main_Frame(None, title = "示例应用程序")frame.Show(真)框架.中心()返回真定义主():app = SampleApp(0)app.MainLoop()如果 __name__ == "__main__":主要的()

看起来它可能是在 Windows 上运行的 wxPython 中的一个错误.下面是在 Ubuntu 上运行的 Windows 上有问题的完全相同代码的屏幕截图,没有问题.

This is a follow up from allocating more size in sizer to wx.CollapsiblePane when expanded.

EDIT: The answer to that question solved my original problem, which was that nothing moved when I expanded or collapsed a pane, but now I've encountered another bug. While things do move properly, the buttons seem to smear out over each other as shown in the image below. Mousing over a button seems to force it to redraw properly over the rest of the mess, but it leaves a bunch of random button pieces drawn behind and around it.

I've done my absolute best to replicate this bug in a sample app, but I can't. I'm just looking for leads here. Does anyone have any idea what might cause the kind of issue shown below? It only happens after expanding and collapsing some of the upper panes.

For what it's worth, code below is for a sample app that looks very similar, but for some reason doesn't cause the same problems. EDIT Also for what it's worth, here's a link to the full source code for the GUI of my project which generated the screenshot below. http://code.google.com/p/dicom-sr-qi/source/browse/gui/main.py?r=8a876f7b4a034df9747a2c1f2791258f671e44b1

import wx

class SampleSubPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, 1, "A label"))
        sizer.Add(wx.SpinCtrl(self))
        self.SetSizer(sizer)

class SampleCollapsiblePane(wx.CollapsiblePane):
    def __init__(self, *args, **kwargs):
        wx.CollapsiblePane.__init__(self,*args,**kwargs)
        sizer = wx.BoxSizer(wx.VERTICAL)
        for x in range(2):
            sizer.Add(wx.CheckBox(self.GetPane(), label = str(x)))
            sizer.Add(SampleSubPanel(self.GetPane()))
        self.GetPane().SetSizer(sizer)
        self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.on_change)

    def on_change(self, event):
        self.GetParent().Layout()

class SampleSubPanel2(wx.Panel):

    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)
        sizer = wx.BoxSizer(wx.VERTICAL)
        for x in range(2):
            sizer.Add(SampleCollapsiblePane(self, label = str(x)), 0)
        self.SetSizer(sizer)


class Main_Frame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.main_panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(wx.Panel(self.main_panel, style=wx.RAISED_BORDER),1, wx.EXPAND)
        sizer.Add(SampleSubPanel2(self.main_panel, style = wx.RAISED_BORDER),2, wx.EXPAND )
        sizer.Add(wx.Button(self.main_panel,label= "a button"),0,wx.ALIGN_CENTER)
        self.main_panel.SetSizer(sizer)


class SampleApp(wx.App):
    def OnInit(self):
        frame = Main_Frame(None, title = "Sample App")
        frame.Show(True)
        frame.Centre()
        return True

def main():
    app = SampleApp(0)
    app.MainLoop()

if __name__ == "__main__":
    main()

解决方案

If I am getting you right, you want the code here - allocating more size in sizer to wx.CollapsiblePane when expanded to work properly. The reason it did not work was you forgot to bind the wx.EVT_COLLAPSIBLEPANE_CHANGED. Here is a code which worked for me -

import wx

class SampleCollapsiblePane(wx.CollapsiblePane):
    def __init__(self, *args, **kwargs):
        wx.CollapsiblePane.__init__(self,*args,**kwargs)
        sizer = wx.BoxSizer(wx.VERTICAL)

        for x in range(5):
            sizer.Add(wx.Button(self.GetPane(), label = str(x)))

        self.GetPane().SetSizer(sizer)
        self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.on_change)

    def on_change(self, event):
        self.GetParent().Layout()

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

        self.main_panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)

        for x in range(5):
            sizer.Add(SampleCollapsiblePane(self.main_panel, label = str(x)), 0)

        self.main_panel.SetSizer(sizer)


class SampleApp(wx.App):
    def OnInit(self):
        frame = Main_Frame(None, title = "Sample App")
        frame.Show(True)
        frame.Centre()
        return True

def main():
    app = SampleApp(0)
    app.MainLoop()

if __name__ == "__main__":
    main()

EDIT: Looks like it may be a bug in wxPython running on windows. Below is screen shot of the the exact same code that has problems on Windows running on Ubuntu with no problems.

这篇关于wxPython CollapsiblePane 奇怪的剪切问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆