我试图熟悉auiManager。我需要一个带有图表的窗格列表,这些图表可以自由调整并重新排列和任意。我使用auiPaneInfo类的Row()和Position()方法来设置新窗格的位置。那么,问题是,是否有任何方法可以使它在两个方向上重新调整?另外,有没有办法交换窗格或重新排列窗格的位置?如果没有,如何实施呢?
示例如下(按添加菜单项添加图表):
import wx
import re, math, random
import wx.lib.agw.aui as aui
from wx.lib.colourdb import getColourList
class ChartPanel(wx.Panel):
#----------------------------------------------------------------------
def __init__(self, parent,color="lightgrey"):
""""""
wx.Panel.__init__(self, parent)
self._color=color
self.SetBackgroundColour(self._color)
########################################################################
class ChartFrame(wx.Frame):
"""
Frame that holds all other widgets
"""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, wx.ID_ANY,
"Chart window: AUI manager",
size=(1200,600))
self._winmgr=aui.AuiManager(agwFlags=aui.AUI_MGR_DEFAULT | aui.AUI_MGR_LIVE_RESIZE)
self._winmgr.SetManagedWindow(self)
self._charts={}
self._n=0
self._r=-1
self._c=0
menuBar = wx.MenuBar()
chartMenu = wx.Menu()
addMenuItem = chartMenu.Append(wx.NewId(), "Add", "Add new chart")
menuBar.Append(chartMenu, "&Chart")
self.Bind(wx.EVT_MENU, self.onChartAdd, addMenuItem)
self.SetMenuBar(menuBar)
self._winmgr.Update()
self.Centre()
self.Show()
def onChartAdd(self, event):
self._n = self._n + 1
if self._r == 3:
self._r = 0
self._c = self._c + 1
else:
self._r = self._r + 1
print "r= "+str(self._r)+" c= "+str(self._c)
p = ChartPanel(self,random.choice(getColourList()))
self._charts['p%i'%self._n]=p
self._winmgr.AddPane(
self._charts['p%i'%self._n],
aui.AuiPaneInfo().Caption('Chart %i'%self._n).Center().Position(self._r).Row(self._c).\
CloseButton(True).MinimizeButton(True).MaximizeButton(True).PinButton(True).\
BestSize((345, 400))
)
self._winmgr.Update()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App()
frame = ChartFrame()
app.MainLoop()