Code for XRC

XRC is very cool, but everytime I use it I need to write code like this :

        self.deleteButton = XRCCTRL(self.panel, "DeleteButton")
        self.keepButton = XRCCTRL(self.panel, "KeepButton")
        self.shareButton = XRCCTRL(self.panel, "ShareButton")

to get the objects that represent the various controls. I thought it
might be nice to do that automatically, e.i. to add all the controls
to my class (derived from wxFrame). There's a way to do that for C++
with wxrc, but I have found no way to do that with Python. I thought
maybe enumerating the controls in the XmlResource and creating a
variable for each one on the fly, or maybe map it to a dictionary. But
I can't find a way to enumerate the controls in XmlResource.

Any ideas?

Eli.

P.S. I am a bit new to both Python and wxPython so bear with me if
what I'm saying makes no sense at all..

Eli Golovinsky wrote:

XRC is very cool, but everytime I use it I need to write code like this :

        self.deleteButton = XRCCTRL(self.panel, "DeleteButton")
        self.keepButton = XRCCTRL(self.panel, "KeepButton")
        self.shareButton = XRCCTRL(self.panel, "ShareButton")

to get the objects that represent the various controls. I thought it
might be nice to do that automatically, e.i. to add all the controls
to my class (derived from wxFrame). There's a way to do that for C++
with wxrc, but I have found no way to do that with Python. I thought
maybe enumerating the controls in the XmlResource and creating a
variable for each one on the fly, or maybe map it to a dictionary. But
I can't find a way to enumerate the controls in XmlResource.

Any ideas?

Probably the only way to do it right now is to write some code to parse the .xrc code and to generate from that some Python code that does what you need. If you or somebody comes up with something that is generally useful I wouldn't mind adding it to the wx.tools package and scripts.

···

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

Doesn't sound overly complicated. I'll give it a go and report back.
Thanks.

···

----- Original Message ----- From: "Robin Dunn" <robin@alldunn.com>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Thursday, February 16, 2006 11:58 PM
Subject: Re: [wxPython-users] Code for XRC

Eli Golovinsky wrote:

XRC is very cool, but everytime I use it I need to write code like this :

        self.deleteButton = XRCCTRL(self.panel, "DeleteButton")
        self.keepButton = XRCCTRL(self.panel, "KeepButton")
        self.shareButton = XRCCTRL(self.panel, "ShareButton")

to get the objects that represent the various controls. I thought it
might be nice to do that automatically, e.i. to add all the controls
to my class (derived from wxFrame). There's a way to do that for C++
with wxrc, but I have found no way to do that with Python. I thought
maybe enumerating the controls in the XmlResource and creating a
variable for each one on the fly, or maybe map it to a dictionary. But
I can't find a way to enumerate the controls in XmlResource.

Any ideas?

Probably the only way to do it right now is to write some code to parse the .xrc code and to generate from that some Python code that does what you need. If you or somebody comes up with something that is generally useful I wouldn't mind adding it to the wx.tools package and scripts.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org