|
|
/ Hathaway Weblog / XRCed |
Most GUI builders make you place components in fixed positions with fixed sizes, which is fine until somebody displays your dialog with a large font or your dialog needs to be translated to another language. GUI toolkits include "sizers" or "layout managers" which place components automatically, but most GUI builders either don't provide access to those features or integrate them badly. Not XRCed!
XRCed, included with wxPython, encourages the use of sizers by providing no WYSIWYG interface at all. Instead, you edit a tree of windows, containers, sizers, and controls. There is a preview window, but all editing happens in the tree control and a property window. Unlike editing XML in a text editor, this method informs you of your options as you're editing, and unlike WYSIWYG GUI building, this method makes you specify constraints rather than constants.
I sat down with XRCed two days ago. I found it difficult to use at first, but I learned that XRCed only reflects the quirks in wxWidgets. For instance, if you want a margin between the edges of the dialog and the controls inside, you have to put all the controls in a panel, set a border width for the panel, and enable the flag wxALL (which means "all edges should use the border width".) If you want the large panel to expand with the dialog, you have to put it inside a FlexGridSizer and tell the grid to auto-expand the single column and row. If you want to specify the color of the dialog, it seems that you have to put your main sizer in a FlexGridSizer in a Panel in a FlexGridSizer, then set up the border on your main sizer rather than the panel. And if you want a panel that inherits the color of its parent, you actually want a sizer instead of a panel.
I have used wxPython occasionally over the past three years, and until now I could not figure out how to convince the sizers to behave the way I want them to. Now I finally understand that the simple sizer model is quite far behind CSS. A "StyleSheetSizer" could be very cool: just put all your components in a tree then specify layout constraints in a text file with CSS syntax.
But for now, anyone who uses wxPython or wxWidgets should definitely try XRCed. Once I understood the wxWidgets quirks, it became quite easy to achieve the layouts I wanted. It cleaned up my Python code a lot.
