1

我正在尝试在 notebookPage 面板的垂直布局 sizer 内嵌套一个水平布局的 sizer。

我从wxPython 中获得了一些灵感:Resizing a notebook within a notebook but cannot make it normal work。

而不是得到这个布局

吨位限制(以吨为单位):[3000]
[x] 启用匹配类别过滤器

面板中的所有内容都在一行中被破坏

我在 Win7、python 2.6.6、wx 2.8.12.1 上运行它

以下是相关代码:

import sys
import os


import wx

class MainWindow(wx.Frame):
    def __init__(self,parent,title):
        self.ID_LOAD=101
        self.ID_SAVE=102

        # based on a frame, so set up the frame
        wx.Frame.__init__(self,parent,wx.ID_ANY, title, size=(640,480))

        self.CreateStatusBar()

        self.tab = wx.Notebook(self, -1, style=(wx.NB_TOP))
        self.globPanel = wx.NotebookPage(self.tab, -1)
        self.orderPanel = wx.NotebookPage(self.tab, -1)
        self.slabsPanel = wx.NotebookPage(self.tab, -1)
        self.tab.AddPage(self.globPanel, "Global filter")
        self.tab.AddPage(self.orderPanel, "Orders filter")
        self.tab.AddPage(self.slabsPanel, "Slabs filter")

        self.toolbar = wx.ToolBar(self, wx.ID_ANY, style=wx.TB_HORIZONTAL)
        self.toolbar.SetToolBitmapSize((20,20))
        load_ico = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, (20,20))
        self.toolbar.AddLabelTool(self.ID_LOAD, "Load", load_ico, bmpDisabled=wx.NullBitmap, shortHelp='Load', longHelp="Loads a text file to the filter editor")
        save_ico = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, (20,20))
        self.toolbar.AddLabelTool(self.ID_SAVE, "Save", save_ico, bmpDisabled=wx.NullBitmap, shortHelp='Save', longHelp="Saves the contents of the filter editor")
        self.toolbar.AddSeparator()

        self.tonnageStatic = wx.StaticText(self.globPanel, wx.ID_ANY, "Tonnage limit (in tons): ")
        self.tonnageEdit = wx.TextCtrl(self.globPanel, wx.ID_ANY, '30000') 
        self.tonnageSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.tonnageSizer.Add(self.tonnageStatic, flag=wx.EXPAND | wx.RIGHT | wx.LEFT | wx.TOP | wx.BOTTOM, border=10)
        self.tonnageSizer.Add(self.tonnageEdit, flag=wx.EXPAND | wx.RIGHT | wx.LEFT | wx.TOP | wx.BOTTOM, border=10)

        self.filterCheck = wx.CheckBox(self.globPanel, wx.ID_ANY, "Enable filter on matchings categories")

        self.globSizer = wx.BoxSizer(wx.VERTICAL)
        self.globSizer.Add(self.tonnageSizer)
        self.globSizer.Add(wx.StaticLine(self), 0, wx.EXPAND)
        self.globSizer.Add(self.filterCheck, 0, wx.EXPAND)
        self.globPanel.SetSizer(self.globSizer)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.toolbar,0,wx.EXPAND)
        self.sizer.Add(wx.StaticLine(self), 0, wx.EXPAND)
        self.sizer.Add(self.tab, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.Layout()
        self.toolbar.Realize()

        # Show it !!!
        self.Show(1)            

def main():
    app = wx.PySimpleApp()
    view = MainWindow(None, "Input filter")
    app.MainLoop()

if __name__ == "__main__":
    main()

像这样稍微好一点,但我没有得到静态行,只显示 checkox 标签的第一个字符

self.tonnageStatic = wx.StaticText(self.globPanel, wx.ID_ANY, "Tonnage limit (in tons): ")
self.tonnageEdit = wx.TextCtrl(self.globPanel, wx.ID_ANY, '30000') 
self.tonnageSizer = wx.BoxSizer(wx.HORIZONTAL)
self.tonnageSizer.Add(self.tonnageStatic, 0, flag=wx.EXPAND|wx.ALL)
self.tonnageSizer.Add(self.tonnageEdit, 0, flag=wx.EXPAND|wx.ALL)

self.filterCheck = wx.CheckBox(self.globPanel, wx.ID_ANY, "Enable filter on matchings categories")

self.globSizer = wx.BoxSizer(wx.VERTICAL)
self.globSizer.Add(self.tonnageSizer)
self.globSizer.Add(wx.StaticLine(self.globPanel), 0, wx.EXPAND)
self.globSizer.Add(self.filterCheck, 0, wx.EXPAND)
self.globPanel.SetSizer(self.globSizer)

self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.toolbar,0,wx.EXPAND)
self.sizer.Add(wx.StaticLine(self), 0, wx.EXPAND)
self.sizer.Add(self.tab, 1, wx.EXPAND)
self.SetSizer(self.sizer)
self.globPanel.Layout()
self.Layout()
self.toolbar.Realize()

# Show it !!!
self.Show(1) 
4

1 回答 1

1

我只是在windows上运行它,如果你.Layout()在行后调用globPanel,self.Layout()它应该把sizer踢成形状:)

您也可以使用wx.ALL与右、左、上和下相同的

编辑:我很好奇为什么会出现这种奇怪的行为,并进行了更多调查。我查看了使用笔记本的地方,并且总是使用面板作为页面。如果您将 NotebookPages 更改为 Panels,您可以取消Layout调用,它可以按预期工作。

于 2012-06-08T12:34:57.517 回答