AUI(Advanced User Interface)模塊使得我們可以方便地開(kāi)發(fā)出美觀、易用的用戶界面。 面板管理 如下所示的界面包含了3個(gè)面板,面板實(shí)現(xiàn)了關(guān)閉、拖動(dòng)、Dock、最大化等功能,這可以通過(guò)很少的代碼方便地實(shí)現(xiàn): 代碼如下所示: 1: #!/usr/bin/env python 2: 3: import wx 4: import wx.aui 5: 6: class MyFrame(wx.Frame): 7: 8: def __init__(self, parent, id=-1, title='wx.aui Test', 9: pos=wx.DefaultPosition, size=(800, 600), 10: style=wx.DEFAULT_FRAME_STYLE): 11: wx.Frame.__init__(self, parent, id, title, pos, size, style) 12: 13: self._mgr = wx.aui.AuiManager(self) 14: 15: # create several text controls 16: text1 = wx.TextCtrl(self, -1, 'Pane 1 - sample text', 17: wx.DefaultPosition, wx.Size(200,150), 18: wx.NO_BORDER | wx.TE_MULTILINE) 19: 20: text2 = wx.TextCtrl(self, -1, 'Pane 2 - sample text', 21: wx.DefaultPosition, wx.Size(200,150), 22: wx.NO_BORDER | wx.TE_MULTILINE) 23: 24: text3 = wx.TextCtrl(self, -1, 'Main content window', 25: wx.DefaultPosition, wx.Size(200,150), 26: wx.NO_BORDER | wx.TE_MULTILINE) 27: 28: # add the panes to the manager 29: self._mgr.AddPane(window=text1, info=wx.aui.AuiPaneInfo().Left().MaximizeButton(True)) 30: self._mgr.AddPane(window=text2, info=wx.aui.AuiPaneInfo().Bottom().MaximizeButton(True)) 31: self._mgr.AddPane(window=text3, info=wx.aui.AuiPaneInfo().Center()) 32: 33: # tell the manager to 'commit' all the changes just made 34: self._mgr.Update() 35: 36: self.Bind(wx.EVT_CLOSE, self.OnClose) 37: 38: def OnClose(self, event): 39: # deinitialize the frame manager 40: self._mgr.UnInit() 41: # delete the frame 42: self.Destroy() 43: 44: app = wx.App() 45: frame = MyFrame(None) 46: frame.Show() 47: app.MainLoop() 如上代碼所示,AUI簡(jiǎn)單易用,其使用方法總結(jié)如下:
工具欄 工具欄也可以作為面板添加在AuiManager中,實(shí)現(xiàn)工具欄的浮動(dòng)等功能;如下圖所示: 需要在面板管理中的代碼中添加兩段代碼:生成和添加工具欄。 生成工具欄 1: # Create toolbar 2: toolbar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, 3: wx.TB_FLAT | wx.TB_NODIVIDER | wx.TB_HORZ_TEXT) 4: 5: toolbar.SetToolBitmapSize(wx.Size(16,16)) 6: toolbar_bmp1 = wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)) 7: toolbar.AddLabelTool(101, "Item 1", toolbar_bmp1) 8: toolbar.AddLabelTool(101, "Item 2", toolbar_bmp1) 9: toolbar.AddLabelTool(101, "Item 3", toolbar_bmp1) 10: toolbar.AddLabelTool(101, "Item 4", toolbar_bmp1) 11: toolbar.AddSeparator() 12: toolbar.AddLabelTool(101, "Item 5", toolbar_bmp1) 13: toolbar.AddLabelTool(101, "Item 6", toolbar_bmp1) 14: toolbar.AddLabelTool(101, "Item 7", toolbar_bmp1) 15: toolbar.AddLabelTool(101, "Item 8", toolbar_bmp1) 16: toolbar.Realize() 添加工具欄 1: self._mgr.AddPane(toolbar, wx.aui.AuiPaneInfo(). 2: Name("toolbar").Caption("Toolbar Demo"). 3: ToolbarPane().Top(). 4: LeftDockable(False).RightDockable(False))
參考資源 |
|