読者です 読者をやめる 読者になる 読者になる

XmlResourceHandler


wxFormBuilderのメニューにはwxCollapsiblePaneが無いので、
xrc.XmlResourceHandlerを自分で書く必要があります。

from __future__ import with_statement, division, print_function
import wx
import wx.xrc as xrc

Res = xrc.EmptyXmlResource()

class CustomPanelXmlHandler(xrc.XmlResourceHandler):
    def CanHandle(self, node):
        return self.IsOfClass(node, "PlayerPane")
    
    def DoCreateResource(self):
        collpane = wx.CollapsiblePane(self.GetParentAsWindow())
        win = collpane.GetPane()
        
        panel = Res.LoadPanel(win, "Player")
        sz = wx.BoxSizer()
        sz.Add(panel, 1, wx.EXPAND)
        win.SetSizer(sz)
        sz.SetSizeHints(win)
        win.SetInitialSize()
        
        return collpane

def main():
    app = wx.PySimpleApp()
    Res.Load('noname.xrc')
    Res.InsertHandler(CustomPanelXmlHandler())
    
    f = Res.LoadFrame(None, "Spam")
    f.Show()
    app.MainLoop()
    
if __name__ == "__main__":
    main()


以下はxrcファイル

<?xml version&#061;"1.0" encoding&#061;"UTF-8" standalone&#061;"yes" ?>
<resource xmlns&#061;"http://www.wxwindows.org/wxxrc" version&#061;"2.3.0.1">
 <object class&#061;"wxFrame" name&#061;"Spam">
  <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
  <size>500,300</size>
  <title></title>
  <object class&#061;"wxPanel" name&#061;"m_panel1">
   <style>wxTAB_TRAVERSAL</style>
   <object class&#061;"wxBoxSizer">
    <orient>wxVERTICAL</orient>
    <object class&#061;"sizeritem">
     <option>0</option>
     <flag>wxALL</flag>
     <border>5</border>
     <object class&#061;"PlayerPane" name&#061;"PlayerPane" />
    </object>
   </object>
  </object>
 </object>
 <object class&#061;"wxPanel" name&#061;"Player">
  <style>wxTAB_TRAVERSAL</style>
  <size>500,300</size>
  <object class&#061;"wxBoxSizer">
   <orient>wxHORIZONTAL</orient>
   <object class&#061;"sizeritem">
    <option>0</option>
    <flag>wxALL</flag>
    <border>5</border>
    <object class&#061;"wxStaticText" name&#061;"m_staticText7">
     <label>MyLabel</label>
    </object>
   </object>
   <object class&#061;"sizeritem">
    <option>0</option>
    <flag>wxALL</flag>
    <border>5</border>
    <object class&#061;"wxCheckBox" name&#061;"m_checkBox10">
     <label>Check Me!</label>
     <checked>0</checked>
    </object>
   </object>
   <object class&#061;"sizeritem">
    <option>0</option>
    <flag>wxALL</flag>
    <border>5</border>
    <object class&#061;"wxButton" name&#061;"m_button3">
     <label>MyButton</label>
     <default>0</default>
    </object>
   </object>
  </object>
 </object>
</resource>