wxPython problems (XRC problems)

Tim Roberts timr at probo.com
Sun Jan 26 22:41:13 EST 2003


"Andrei S." <w3c at hot.ee> wrote:
>
>I've met wxPython for GUI applications programming and just loved it. 

Welcome to the club!

>Especially for the XRC feature.
>
>I'm making a simple test application, with different controls to test, 
>especially such as buttons, text inputs, wxCalendarCtrl and others. I 
>want to have this all in the dynamically loaded XML resource file (XRC). 
>The GUI is edited through the XRCed app, shipped with the wxPython package.
>
>...
>I'm initialising the dialog with wxCalendarCtrl widget by writing the 
>following code in InitSelDate(self) function of class MyApp(wxApp):
>
>*-- python code --*
>
>self.date_dialog 	= self.res.LoadDialog(self.frame, "select_date_dialog")
>self.calendar_ctrl	= XRCCTRL(self.date_dialog, "calendar_ctrl")
>
>EVT_BUTTON(self, XRCID("sdate_button_ok"), self.OnSelectDateOK)
>EVT_BUTTON(self, XRCID("sdate_button_cancel"), self.OnSelectDateCancel)
>
>*-- python code --*
>
>Then I call this function from OnInit method and from OnSelectDate 
>method with "if not self.date_dialog" predicate.
>
>Then I get the following when running the program:
>
>self.date_value.SetValue(self.calendar_ctrl.GetDate())
>AttributeError: wxControlPtr instance has no attribute 'GetDate'
>
>So it seems like XRCCTRL(self.date_dialog, "calendar_ctrl") makes a 
>wxControlPtr object but not wxCalendarCtrlPtr... Any tips on making it 
>return wxCalendarCtrlPtr objects?

Yes.  The XRC mechanism understand SOME of the wxPython controls, but not
ALL of the possible controls.  To handle this circumstance, wxPython
provides a function to basically do a C typecast -- to tell the system that
"this object pretends to be a wxXxxGeneric but is really a wxXxxSpecific":

  self.calendar_ctrl = wxPyTypeCast(
    XRCCTRL(self.date_dialog, "calendar_ctrl"), 
    "wxCalendarCtrl"
  )

>Are there any wxPython users in here that could help me solve these 
>problems?

If you go to the wxPython web site, you'll find a link to the
wxPython-users mailing list.  This is absolutely your best bet for
answering questions like this.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.




More information about the Python-list mailing list