Need sample code on wxXMLResource.AttachUnknownControl

Hi!
Sorry for my bad english.

  Doing some GUI development with wxPython.
  wxXMLResource did not support all wxPython controls.
  But XRCed is pretty good for GUI layout and sizers.
  So i've create .xrc file wich describes
  my panel.
Pretended panel view for example:

···

____________________________________
! wxPanel !
! !
! Static text wxTextCtrl !
! Static text1 unknown ctrl !
! !
! ___________________________________!_

         what i need is to bind custom control
         with 'unknown ctrl' LATER.
         (for the sake of simplicity it's wxTextCtrl,really it's wxPopupCtrl )

Problem :

        It did not showing on my Panel.
        Can someone enlighten me on that tricky matter?
        Simple complete example would suffice.

Here is the code:
------start of code------------------------------------
from wxPython.wx import *
from wxPython.xrc import *
import os, sys

class TestPanel(wxPanel):
    def __init__(self, parent):
        wxPanel.__init__(self, parent, -1)
        self.res = wxXmlResource('')
        self.res.InitAllHandlers()
        self.res.Load(os.path.join(basePath, 'test.xrc'))
        self.NewJobPanel=self.res.LoadPanel(self,"NewJobPanel")

        # Here is the trouble !
        self.res.AttachUnknownControl("Date1",wxTextCtrl(self.NewJobPanel, -1, "Test it out and see", size=(125, -1)))

        box=wxBoxSizer(wxVERTICAL)
        box.Add(self.NewJobPanel,1,wxEXPAND)
        self.SetSizer(box)
        self.SetAutoLayout(true)

#----------------------------------------------------------------------
class MyApp(wxApp):
    def OnInit(self):
        frame = wxFrame(NULL, -1, 'Sample wxFrame')
        win = TestPanel(frame)
        frame.Show(true)
        return true
if __name__=='__main__':
    basePath = os.path.dirname(sys.argv[0])
    myapp = MyApp(0)
    myapp.MainLoop()
------end of code--------------------
file test.xrc:

<?xml version="1.0" ?>
<resource>
  <object class="wxPanel" name="NewJobPanel">
    <object class="wxStaticBoxSizer">
      <label>Enter new Job</label>
      <orient>wxVERTICAL</orient>
      <object class="sizeritem">
        <object class="wxFlexGridSizer">
          <cols>2</cols>
          <rows>2</rows>
          <object class="sizeritem">
            <object class="wxStaticText">
              <label>Enter Job Description</label>
            </object>
          </object>
          <object class="sizeritem">
            <object class="wxTextCtrl" name="JobDescription">
              <style>wxTE_MULTILINE</style>
            </object>
            <flag>wxRIGHT|wxEXPAND</flag>
          </object>
          <object class="sizeritem">
            <object class="wxStaticText">
              <label>File name</label>
            </object>
          </object>
          <object class="sizeritem">
            <object class="wxBoxSizer">
              <orient>wxHORIZONTAL</orient>
              <object class="sizeritem">
                <object class="wxTextCtrl" name="UploadFile"/>
                <option>1</option>
                <flag>wxRIGHT|wxEXPAND</flag>
                <border>5</border>
              </object>
              <object class="sizeritem">
                <object class="wxButton" name="BUTTON_BROWSE">
                  <label>Browse...</label>
                  <size>30,-1d</size>
                </object>
              </object>
            </object>
            <flag>wxRIGHT|wxEXPAND</flag>
            <border>5</border>
          </object>
          <vgap>8</vgap>
          <growablecols>1</growablecols>
          <object class="sizeritem">
            <object class="wxStaticText">
              <label>date 1</label>
            </object>
          </object>
          <object class="sizeritem">
            <object class="unknown" name="Date1"/>
          </object>
        </object>
        <flag>wxEXPAND</flag>
      </object>
    </object>
  </object>
</resource>
------------------end file test.xrc ------------
Thanks in advance.
                  Igor.

Hi,

        Simple complete example would suffice.

You can look at the attached files to see what I did. Basically class
"unknown" ends up instantiating a control based on the XML ID given the
object in the xml file. Maybe not elegant but I couldn't think of another
way to do it.

In addition to these files my main app instantiates a class xmlResourceMgr:

    :
    self.Resources = xmlResourceMgr( self )
    :

and then I use self.Resources to interface to the xml resources, like this:

    self.dlg = self.Resources.LoadDialog( self.Parent, 'Dlg_EditChecklist' )

You can then use self.dlg.ShowModal(). I wrapped the whole thing in another
class xrcEditChecklistDlg and then set up event handlers in there and used
it like this:

    xrc = xrcEditChecklistDlg( self, checklist )
    rc = xrc.dlg.ShowModal()

and so on.

I hope this helps.
-Rick King

dialogs.xrc (3.42 KB)

xmlResourceMgr.py (2.18 KB)

ChecklistEdit.py (3.45 KB)

Igor Prischepoff wrote:

         what i need is to bind custom control with 'unknown ctrl' LATER.
         (for the sake of simplicity it's wxTextCtrl,really it's wxPopupCtrl )

Problem :

        It did not showing on my Panel.
        Can someone enlighten me on that tricky matter?
        Simple complete example would suffice.

          <object class="sizeritem">
            <object class="unknown" name="Date1"/>
          </object>

It is working, but since you don't give it a size in the XRC then it is being created *very small*.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!