Wxpython 简明教程

wxPython - Dockable Windows

wxAui 是 wxWidgets API 中包含的高级用户界面库。Wx.aui.AuiManager 是 AUI 框架中的中央类。

wxAui is an Advanced User Interface library incorporated in wxWidgets API. Wx.aui.AuiManager the central class in AUI framework.

AuiManager 使用 wx.aui.AuiPanelInfo 对象中的每个面板信息来管理与特定框架相关联的面板。让我们了解该 PanelInfo 对象控件停靠和浮动行为的各种属性。

AuiManager manages the panes associated with a particular frame using each panel’s information in wx.aui.AuiPanelInfo object. Let us learn about various properties of PanelInfo object control docking and floating behavior.

将可停靠窗口放入顶级框架中包括以下步骤:

Putting dockable windows in the top level frame involves the following steps −

首先,创建一个 AuiManager 对象。

First, create an AuiManager object.

self.mgr = wx.aui.AuiManager(self)

然后,设计具有所需控件的面板。

Then, a panel with required controls is designed.

pnl = wx.Panel(self)
pbox = wx.BoxSizer(wx.HORIZONTAL)
text1 = wx.TextCtrl(pnl, -1, "Dockable", style = wx.NO_BORDER | wx.TE_MULTILINE)
pbox.Add(text1, 1, flag = wx.EXPAND)
pnl.SetSizer(pbox)

设置 AuiPanelInfo 的以下参数:

The following parameters of AuiPanelInfo are set.

  1. Direction − Top, Bottom, Left, Right, or Center

  2. Position − More than one pane can be placed inside a dockable region. Each is given a position number.

  3. Row − More than one pane appears in one row. Just like more than one toolbar appearing in the same row.

  4. Layer − Panes can be placed in layers.

使用此 PanelInfo,将设计的面板添加到管理器对象中。

Using this PanelInfo, the designed panel is added into the manager object.

info1 = wx.aui.AuiPaneInfo().Bottom()
self.mgr.AddPane(pnl,info1)

顶级窗口的其余部分通常可以包含其他控件。

Rest of the top level window may have other controls as usual.

完整代码如下所示:

The complete code is as follows −

import wx
import wx.aui

class Mywin(wx.Frame):

   def __init__(self, parent, title):
      super(Mywin, self).__init__(parent, title = title, size = (300,300))

      self.mgr = wx.aui.AuiManager(self)

      pnl = wx.Panel(self)
      pbox = wx.BoxSizer(wx.HORIZONTAL)
      text1 = wx.TextCtrl(pnl, -1, "Dockable", style = wx.NO_BORDER | wx.TE_MULTILINE)
      pbox.Add(text1, 1, flag = wx.EXPAND)
      pnl.SetSizer(pbox)

      info1 = wx.aui.AuiPaneInfo().Bottom()
      self.mgr.AddPane(pnl, info1)
      panel = wx.Panel(self)
      text2 = wx.TextCtrl(panel, size = (300,200), style =  wx.NO_BORDER | wx.TE_MULTILINE)
      box = wx.BoxSizer(wx.HORIZONTAL)
      box.Add(text2, 1, flag = wx.EXPAND)

      panel.SetSizerAndFit(box)
      self.mgr.Update()

      self.Bind(wx.EVT_CLOSE, self.OnClose)
      self.Centre()
      self.Show(True)

   def OnClose(self, event):
      self.mgr.UnInit()
      self.Destroy()

app = wx.App()
Mywin(None,"Dock Demo")
app.MainLoop()

上述代码生成以下输出 -

The above code produces the following output −

dock demo