I'm working on an app that features a lovingly hand-crafted GUI. I'd like to tear out a bunch of that code and replace it with an XRC file. Is there any way to do that without spending hours hand-coding? What I'd really like is a frame.DumpToXRC() method that I could insert just before the frame.Show() method.
Remember that! Make it a mantra and KNOW that violence, sooner or later, will come back to haunt you. This is from my experience and from the experience of countless other.
And to answer your question, no, there is no way to do that. Hand crafted code might have dynamically generated widgets that simply cannot be put in a XRC.
I’m working on an app that features a lovingly hand-crafted GUI. I’d like to tear out a bunch of that code and replace it with an XRC file. Is there any way to do that without spending hours hand-coding? What I’d really like is a frame.DumpToXRC() method that I could insert just before the frame.Show() method.
I'm working on an app that features a lovingly hand-crafted GUI. I'd like to tear out a bunch of that code and replace it with an XRC file. Is there any way to do that without spending hours hand-coding? What I'd really like is a frame.DumpToXRC() method that I could insert just before the frame.Show() method.
I'm curious to know why you want to do this. What do you believe you will gain? Note that I'm not judging this good or bad; I'd just like to know your thinking.
Personally, I usually work the other way around. I dabble in XRC until the UI looks the way I want, then I promptly go write the equivalent code in direct wx calls.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
I'm working on an app that features a lovingly hand-crafted GUI. I'd like to tear out a bunch of that code and replace it with an XRC file. Is there any way to do that without spending hours hand-coding? What I'd really like is a frame.DumpToXRC() method that I could insert just before the frame.Show() method.
There isn't anything like that currently, but it wouldn't be too hard to write something that does a recursive descent of the window and sizers and generates some XRC that at least comes close, as long as there is no custom classes used or you have a ability to do the right them when you encounter them. You can look at the code for the Widget Inspection Tool for an example of extracting info about the live widgets and sizers in a containment hierarchy.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
I'm working on an app that features a lovingly hand-crafted GUI. I'd like to tear out a bunch of that code and replace it with an XRC file.
I'm curious to know why you want to do this. What do you believe you will gain? Note that I'm not judging this good or bad; I'd just like to know your thinking.
Personally, I usually work the other way around. I dabble in XRC until the UI looks the way I want, then I promptly go write the equivalent code in direct wx calls.
The GUI isn't (IMHO) that well laid-out. There's a bunch of little tweaks which I'd like to do, but can't do easily if it's all a bunch of Python code. For instance, the preference dialog has a bunch of fields whose labels are all left justified and the controls are packed up against them in a very ragged fashion.
Also, while the current code base is fairly modular (having a separate file for each dialog, etc.), the code is a jumble of GUI and application logic which I'd like to try to tease apart. The good news is that it's all very vanilla; no custom widgets, nothing dynamically generated.
There isn't anything like that currently, but it wouldn't be too hard to write something that does a recursive descent of the window and sizers and generates some XRC that at least comes close, as long as there is no custom classes used or you have a ability to do the right them when you encounter them.
That was my plan if no one had any suggestions.
You can look at the code for the Widget Inspection Tool for an example of extracting info about the live widgets and sizers in a containment hierarchy.
I don't think I'd encountered that before. Thanks! I wonder how hard it would be to add an "Export" function to it?
You can look at the code for the Widget Inspection Tool for an example of extracting info about the live widgets and sizers in a containment hierarchy.
I don't think I'd encountered that before. Thanks! I wonder how hard it would be to add an "Export" function to it?
Well, after surprisingly little work, I now have a Widget Inspection Tool that has an "Export XRC" icon on its toolbar. Right now, though, it just produces dreadfully simple XML for the top-most frame, but I have big plans for it.
Does anyone have any code that turns a Python __class__ attribute into the class and subclass attributes that XRC wants? I suspect I'm going to parse the string representations, looking for leading 'wx.' to decide what's what. It looks like I'm also going to have to generate unique names for all the widgets, so I can tie the Python to them.
For some reason, the Widget Inspection Tool isn't displaying the main frame's menubar. Has anyone noted this before? This will make it more difficult to export the menus.
One last observation. Two days after installing it, I'm abandoning xwGlade for XRCed because my existing app doesn't use sizers. Interestingly, my app has icons not only on all of its wxMenuItems, it also has them on the nested wxMenus. XRCed doesn't seem to support this.
You can look at the code for the Widget Inspection Tool for an example of extracting info about the live widgets and sizers in a containment hierarchy.
I don't think I'd encountered that before. Thanks! I wonder how hard it would be to add an "Export" function to it?
Well, after surprisingly little work, I now have a Widget Inspection Tool that has an "Export XRC" icon on its toolbar. Right now, though, it just produces dreadfully simple XML for the top-most frame, but I have big plans for it.
Does anyone have any code that turns a Python __class__ attribute into the class and subclass attributes that XRC wants? I suspect I'm going to parse the string representations, looking for leading 'wx.' to decide what's what. It looks like I'm also going to have to generate unique names for all the widgets, so I can tie the Python to them.
You could look at the base classes (the __bases__ attribute) and move up the hierarchy until you find a class that is in the wx package.
For some reason, the Widget Inspection Tool isn't displaying the main frame's menubar. Has anyone noted this before? This will make it more difficult to export the menus.
Currently the WIT doesn't do any traversal of the menubars. I'll take a patch that adds it however.
One last observation. Two days after installing it, I'm abandoning xwGlade for XRCed because my existing app doesn't use sizers. Interestingly, my app has icons not only on all of its wxMenuItems, it also has them on the nested wxMenus. XRCed doesn't seem to support this.
On the item that is the nested menu, or the items on the nested menu?
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
One last observation. Two days after installing it, I'm abandoning xwGlade for XRCed because my existing app doesn't use sizers. Interestingly, my app has icons not only on all of its wxMenuItems, it also has them on the nested wxMenus. XRCed doesn't seem to support this.
On the item that is the nested menu, or the items on the nested menu?
The app (I shouldn't call it "my app", I didn't write it) does this to place an icon on the nested menu:
filerecentitem = wx.MenuItem(filemenu, wx.NewId(), _("&Recent Files"),
_(" Open a recently opened file"))
filerecentitem.SetBitmap(self.resin.getImage("filehistory"))
filerecentitem.SetSubMenu(filerecentmenu)
filemenu.AppendItem(filerecentitem)
I'm not sure how to do the equivalent using XRCed.
One last observation. Two days after installing it, I'm abandoning xwGlade for XRCed because my existing app doesn't use sizers. Interestingly, my app has icons not only on all of its wxMenuItems, it also has them on the nested wxMenus. XRCed doesn't seem to support this.
On the item that is the nested menu, or the items on the nested menu?
The app (I shouldn't call it "my app", I didn't write it) does this to place an icon on the nested menu:
filerecentitem = wx.MenuItem(filemenu, wx.NewId(), _("&Recent Files"),
_(" Open a recently opened file"))
filerecentitem.SetBitmap(self.resin.getImage("filehistory"))
filerecentitem.SetSubMenu(filerecentmenu)
filemenu.AppendItem(filerecentitem)
I'm not sure how to do the equivalent using XRCed.
XRC probably supports it, even if XRCed doesn't, so if you really need it you can at least edit the XRC file. Please file a ticket about this.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!