Working with generated source code
As a simple rule; Don't modify the code in generated _init_* methods unless you know what you are doing.
Boa currently generates / maintains the source code for:
- The wxApp class / modules
- The modules dictionary
- References, importing and the creation of the main frame
- Frame classes / modules (Frames, Dialogs and MDI frames)
- Importing of needed wxPython modules
- Window identifiers: wxID_* Each method has it's own window id list
- Special methods: _init_*
- _init_ctrls: Create and setup visual controls
- _init_utils: Create and setup non visible objects
- _init_coll_*: Create and setup of collections
- Event method declarations: On*
Note: Boa only defines the methods,
it does not maintain their code bodies, this is your responsibility
Unsupported controls
If you want to add controls or objects not available on the Palette, simply
add your code to the __init__ method below the call to _init_ctrls().
Don't add it in the Special methods listed above. Your code will be lost.
Also, don't add your own window identifier to the list Boa maintains.
Define your own window ids in a seperate list.
Note: Boa now has Custom Classes, see below.
Generated code policy
Although is is possible to change the generated code by hand, it is not advised,
and under normal circumstances, not necessary.
If you really need to modify generated code, keep the following in mind:
- Only controls defined on the Palette may be used.
- Constructors need all parameters passed, and in keyword argument form
- Only methods defined or idenfified as property setter methods may be used
- Whitespace (blank lines) is significant for collection methods.
They are in the form:
Initialiser (optional)
blank line
Item definitions (1 or more lines)
blank line
Finaliser (optional)
In summary, if Boa can't generate the code, it will also not be able to parse it.
Renaming event methods (On*)
Something that Boa does not support yet is to rename event methods. You have to
do this by hand. Remember to also change the EVT_* binding to the method in the
_init_* methods when you rename the method. Mind your spelling, Boa is not
forgiving ;) This will be automated in the future.
Special frame attributes
NEW
You may define special attributes that the designer will respect and preserve
in the generated source.
All instance attributes defined between the top of the __init__ method
and the _init_ctrls() method call will be available to the Designer
as valid names bound to properties.
For an attribute to qualify, it has to have a simple deduceable type;
Python builtin or wxPython objects.
If for example the attribute is bound to a variable passed in as a
parameter, you have to first initialise it to a literal of the same
type. This value will be used at design time.
e.g.
def __init__(self, parent, myFrameCaption):
self.frameCaption = 'Design time frame caption'
self.frameCaption = myFrameCaption
self._init_ctrls(parent)
Now you may add this attribute as a parameter or property value
in the source by hand.
e.g. (actually on one line)
wxFrame.__init__(self, size = (-1, -1), id = wxID_WXFRAME1, pos = (-1, -1),
title = self.frameCaption, parent = prnt, name = '', style = wxDEFAULT_FRAME_STYLE)
In the Inspector property values recognised as special attributes
will display as bold values and cannot be edited in the property editor (yet).
Defining custom classes
NEW
You may now define classes equivalent to standard wxPython classes which need
not be defined on the palette in order to use in the Designer.
Custom Classes can be defined as a class attribute named _custom_classes
containing a dictionary defining wxPython classes and their custom
equivalents.
e.g.
class wxFrame1(wxFrame):
_custom_classes = {'wxTreeCtrl': ['MyTreeCtrl', 'AdvancedTreeCtrl']}
def _init_utils(self):
pass
These custom classes will then be available to the Designer
and will act as equivalent to the corresponding wxPython class,
but will generate source for the custom definition.
One implication is that you loose the constructor. Because Boa
will generate the creation code for the object the constructor
signature has to be the same as the wxPython class.