上部にタブがあり、下部に一般的なパネルがあるwx.Notebookを使用してプロジェクトツールを作成しようとしています。下部のパネルはノートブックから独立している必要があり、タブが変更されても変更されません。ノートブックを追加するだけではノートブック自体は正常に機能しますが、下部パネル(拡張wx.Panel)も追加すると、ノートブックは次の画像に示すように圧縮されます。
ウィンドウ用のパネルが1つあり、ノートブックと下部パネル(BottomGroupと呼ばれ、wx.Panelを拡張)を別々のパネルに追加します。誰かが問題を見つけることができますか?多分サイザーで何か?私のウィンドウは次のようになります(タブが間違っていることに注意してください):
class Window(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, None, wx.ID_ANY, title)
self.InitUI()
def InitUI(self):
menuBar = wx.MenuBar()
menu = wx.Menu()
menu_load = menu.Append(wx.ID_OPEN, 'Open', 'Open project')
menu_save = menu.Append(wx.ID_SAVE, 'Save', 'Save project')
menu_save_as = menu.Append(wx.ID_SAVEAS, 'Save as', 'Save project as')
menu_exit = menu.Append(wx.ID_EXIT, 'Quit', 'Quit application')
menuBar.Append(menu, '&File')
self.SetMenuBar(menuBar)
mainPanel = wx.Panel(self)
self.noteBookPanel = wx.Panel(mainPanel)
self.notebook = wx.Notebook(self.noteBookPanel)
self.bottomPanel = wx.Panel(mainPanel)
self.bottomGroup = BottomGroup(self.bottomPanel)
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.pageNodePathsTables = PageNodesPathsTables(self.notebook)
self.pageEscapeCriteria = PageEscapeCriteria(self.notebook)
self.pageFileHandling = PageFileHandling(self.notebook)
self.notebook.AddPage(self.pageNodePathsTables, "Define Paths and Nodes")
self.notebook.AddPage(self.pageEscapeCriteria, "Define Escape Criteria")
self.notebook.AddPage(self.pageFileHandling, "File Handling")
mainSizer.Add(self.noteBookPanel,1,wx.TOP)
mainSizer.Add(self.bottomGroup,1,wx.BOTTOM)
self.Bind(wx.EVT_MENU, self.onSave, menu_save)
self.Bind(wx.EVT_MENU, self.onLoad, menu_load)
self.Bind(wx.EVT_MENU, self.OnQuit, menu_exit)
self.SetDimensions(WindowOpenX,WindowOpenY,WindowWidth,WindowHeight)
self.Show(True)
アップデート:
私は自分のコードをこれにリファクタリングしました(リファクタリングされた部分のみが示されています):
self.notebook = wx.Notebook(self)
self.bottomGroup = BottomGroup(self)
self.setupMenu()
#frameSizer = wx.GridBagSizer(rowGap,columnGap)
#frameSizer.Add(self.notebook,pos=(0,0), span=(1,1),
# flag=wx.LEFT|wx.TOP|wx.EXPAND, border = 5)
#frameSizer.Add(self.bottomGroup,pos=(1,0), span=(1,1),
# flag=wx.LEFT|wx.BOTTOM|wx.EXPAND, border = 5)
frameSizer = wx.BoxSizer(wx.VERTICAL)
frameSizer.Add(self.notebook, 2, wx.EXPAND)
frameSizer.Add(self.bottomGroup,0)
self.SetSizer(frameSizer)
ここで、self.setupMenu()
は次のように定義されます。
def setupMenu(self):
self.pageNodePathsTables = PageNodesPathsTables(self.notebook)
self.pageEscapeCriteria = PageEscapeCriteria(self.notebook)
self.pageFileHandling = PageFileHandling(self.notebook)
self.pagePlotHistoryData = PagePlotHistoryData(self.notebook)
self.pageCalculateEscape = PageCalculateEscape(self.notebook)
self.notebook.AddPage(self.pageNodePathsTables, "Define Paths and Nodes")
self.notebook.AddPage(self.pageEscapeCriteria, "Define Escape Criteria")
self.notebook.AddPage(self.pageFileHandling, "File Handling")
self.notebook.AddPage(self.pagePlotHistoryData, "Plot History Data")
self.notebook.AddPage(self.pageCalculateEscape, "Calculate Escape")
これは、上記のコードよりもはるかに明確で簡単です。bottomGroup
がスタックされていることを除いて、正常に機能しますnotebook
(つまり、両方の要素がwx.Frameの左上隅から始まります)。私はとの両方を試しましwx.BoxSizer
たwx.GridBagLayout
(上記でコメントしたように)。この問題について何か提案はありますか?
私のBottomGroupは次のように定義されています:
class BottomGroup(wx.Panel):
def __init__(self,parent):
wx.Panel.__init__(self,parent)
panelSizer = wx.GridBagSizer(rowGap,columnGap)
btnSaveProject = wx.Button(parent, label="Save project", size=(100,50))
btnLoadProject = wx.Button(parent, label="Open project", size=(100,50))
panelSizer.Add(btnSaveProject, pos=(0,0), span=(1,1),
flag=wx.EXPAND|wx.LEFT, border = borderWidth)
panelSizer.Add(btnLoadProject, pos=(0,1), span=(1,1),
flag=wx.EXPAND|wx.LEFT, border = borderWidth)
self.SetSizer(panelSizer)
私の主な方法は次のようなものです。
if __name__ == '__main__':
app = wx.App()
Window(None, WindowHeader)
app.MainLoop()