August 2008


Wizard building, cont’d

Mark Côté, 12 August 2008

Not being content with merely complaining, I decided to create a wizard class in pure Python to replace the default, less extensible wizard class. Head over to my post on Tungle’s blog to read it and download the code.

Wizard building

Mark Côté, 4 August 2008

Some lessons learned after painful GUI work:

The Python version of wxWidgets is unfortunately less easily extensible than the C++ version. I noticed this while using the useful Wizard classes, which simplify the creation of standard Back/Next/Cancel-based wizards. The C++ version has overrideable functions like wxWizard::DoCreateControls(), in case you want to create your own buttons or layout, but the Python version exports neither these nor the button member variables themselves. You can always use FindWindowById() (with wx.ID_FORWARD or wx.ID_CANCEL or the like), but you can’t actually create them yourself, so, for example, buttons with static bitmaps are out, since they are a different object from standard buttons.

Don’t try to make your WizardPages too small unless you want to edit the C++ wxWizard class. As the documentation explains (in the second half of the page on wxWizard, tucked in the explanation for wxWizard::GetPageAreaSizer()—there may or may not have been a leopard guarding it as well), “wizards are never smaller than some built-in minimal size to avoid wizards that are too small”—whatever “too small” means. But thanks for making that decision for me…

wxGlade is an okay tool for small work but doesn’t support any controls past the basics (i.e. no wizard, no gauge, no fancy list classes). Boa Constructor is a far superior tool and supports all the wx controls I’ve heard of and a pile more. Well, “sort of supports” is a better phrase. Two annoyances I found while creating a wizard in Boa Constructor:

  • The GUI editor (the GUI for making GUIs) emulates too much of the class it’s editing. For example, a WizardPage is a panel, since it fits into the Wizard dialog, and, since a user can’t resize panels directly (only by resizing its frame, if the panel is resizable), the developer can’t simply resize the WizardPage window (representing the panel). Rather, you have to uncheck the BestFittingSize property and manually enter pixel values. The Wizard class (as generated by Boa Constructor) will size itself according to the maximum BestFittingSize of any of its pages when it is run, but while editing it’s nice to have a bigger area when playing with layout. But make sure you click BestFittingSize before saving, since…
  • Boa Constructor also has a very strange bug, in which manually setting the size in the “Props” tab (after deselecting BestFittingSize) will generate broken code—specifically something like self.deprecatedWrapper(wx.Size(400, 300)). Setting the size in the “Constr” tab works fine for the classes in which this is supported, but I’m not sure what the difference is supposed to be between setting the size in the constructor versus setting the size as a property after the object has been created. Regardless, this is a pretty annoying bug when the GUI builder forces you to set the height and width of WizardPages just to edit them properly.

All in all, Boa Constructor is fairly useful for people who can’t visualize GUIs very well (meaning, I suppose, people who don’t work on them very often), but expect to fight with it occasionally if you’re doing anything beyond simple controls.