我尝试在AUI框架中加载使用XRCed创建的面板。面板有时比窗格大,需要滚动条,因此我将内容包含在滚动窗口中。该面板已创建,但我无法使滚动条工作。随着scroled窗口被封装在sizer中,我希望这可以像文档中所述的那样工作。 我使用XRCed生成的Python代码加载面板。 我在Windows 7,XRCed版本0.2.0-8和Python 2.7上使用wxPython版本2.8.12.1。
import wx
from wx import aui
from example_xrc import xrcexample
class TopWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self._mgr = aui.AuiManager()
self._mgr.SetManagedWindow(self)
self._mgr.AddPane(self.create_panel_from_xrc(), aui.AuiPaneInfo().
Name("name1").Caption("caption1").CenterPane())
self._mgr.AddPane(self.create_textctrl(), aui.AuiPaneInfo().
Name("name2").Caption("caption2").Bottom())
self._mgr.GetPane("nam1").Show().Center().Layer(0).Row(0).Position(0)
self._mgr.GetPane("name2").Show().Bottom().Layer(0).Row(0).Position(0)
self._mgr.Update()
def create_textctrl(self):
text = "This is text box"
return wx.TextCtrl(self, -1, text, wx.Point(0, 0), wx.Size(150, 90),
wx.NO_BORDER | wx.TE_MULTILINE)
def create_panel_from_xrc(self):
return xrcexample(self)
if __name__ == "__main__":
app = wx.App(0)
wx.InitAllImageHandlers()
top_window = TopWindow(None, -1, "")
top_window.Show()
app.MainLoop()
以下代码是XRCed生成的精简代码。 XRC是嵌入式的。
import wx
import wx.xrc as xrc
__res = None
def get_resources():
global __res
if __res == None:
__init_resources()
return __res
class xrcexample(wx.Panel):
def PreCreate(self, pre):
pass
def __init__(self, parent):
pre = wx.PrePanel()
self.PreCreate(pre)
get_resources().LoadOnPanel(pre, parent, "example")
self.PostCreate(pre)
# ------------------------ Resource data ----------------------
def __init_resources():
global __res
__res = xrc.EmptyXmlResource()
wx.FileSystem.AddHandler(wx.MemoryFSHandler())
example_xrc = '''\
<?xml version="1.0" ?><resource>
<object class="wxPanel" name="example">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxScrolledWindow" name="scrolled_window">
<object class="wxFlexGridSizer">
<rows>0</rows>
<cols>2</cols>
<object class="sizeritem">
<object class="wxStaticText">
<label>LABEL</label>
</object>
</object>
<object class="sizeritem">
<object class="wxTextCtrl"/>
</object>
... # repeat label / textctrl many times ...
</object>
</object>
</object>
</object>
</object>
</resource>'''
wx.MemoryFSHandler.AddFile('XRC/example/example_xrc', example_xrc)
__res.Load('memory:XRC/example/example_xrc')