-->-----Original Message-----
-->From: Sandip Bhattacharya [mailto:sandip@lug-delhi.org]
-->Sent: Monday, July 18, 2005 7:50 AM
-->To: wxPython-users@lists.wxwidgets.org
-->Subject: Re: [wxPython-users] Which RAD? Boa, or Glade, or Card, or...
-->
[ snip! ]
-->
-->Another way to work with wxglade is to store the UI in its native
-->wxglade format only and to generate python code using it.
-->
-->Now here is something different from what the wxglade tutorials tell
-->you. Do *not* work on this generated python code at all. Instead
-->subclass them in separate files, and add event handlers in *them*. That
-->way, you will have pure python sources for everything, and UI still in
-->separate files. The idea of storing wxglade native files is to
-->regenerate/modify the GUI code when required.
-->
-->Somehow generating python sources for GUI seems better for two reasons -
-->one, it "seems" faster to load. Two, when you package it in, say
-->Windows, the UI is seamlessly inside your exe files rather than a
-->separate user-muckable resource.
I used to use wxGlade to generate class files like you recommend. However,
I typically break my app into various packages; one for dialogs, another for
panels, etc.
I found these steps faster than my wxGlade development cycle:
1) Edit xrc resource with xrced
2) Run app - see changes
Because wxGlade would require me to copy files around to the correct
directories, I'd have an additional step ->
1) Edit gui with wxGlade
2) Run script to copy files to correct place
3) Run app - see changes
Not to mention I'd have to edit the "copy script" each time I added a new
dialog / panel / etc.
I also find xrced to be more stable than wxGlade. Not that wxGlade would
blow up, but it would sometimes have issues laying out items. XRC seems to
be really stable in regards to laying out widgets.
I *do* like that wxGlade gives you access to widgets by the name you gave
them. For instance -> mypanel.my_text_ctrl.SetValue("Woohoo!").
I have to go around the world to make my controls accessible as member
variables. (If anyone has a better way, please let me know). What I do is
name my controls appropriately via their XML ID. For instance I may name a
wxTextCtrl username_txt.
After naming each of the controls, I load the panel from the xml resource.
I pass the panel to the function below. The docstring ought to explain
what's going on. I have another function I use for attaching "unknown"
controls.
def attach_controls(window, instance):
"""Finds all child windows that are derived from wx.Control and makes
them a property of `instance' based on their name.
For instance, if a choice is named 'my_choice' in XRCed, then that same
choice will become a property of `obj' after calling
attach_controls(window, obj)
"""
for w in window.GetChildren():
if isinstance(w, wx.Control):
name = w.GetName()
# XRCED gives unnamed controls a default name of `-1'
if name == "-1":
continue
exec "instance.%s = xrc.XRCCTRL(window, '%s')" % (name ,name)
just my .02.
jw