|
Boa currently generates / maintains the source code for:
If you really need to modify generated code, keep the following in mind:
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).
See Examples/advanced/SpecialAttributes/wxFrame1.py
The AttrMixin class must end with the postfix _AttrMixin, must be imported in the form from module import class and it's module must be in the same directory as the frame module.
Your frame should multiply-inherit from wxFrame and the mixin class and the
call to the inherited mixin constructor must be placed before the
_init_ctrls call.
e.g.
class AttrMixinFrame(wxFrame, Test_AttrMixin):
...
def __init__(self, parent):
Test_AttrMixin.__init__(self)
self._init_ctrls(parent)
See Examples/advanced/AttrMixins
Custom Classes can be defined as a class attribute named _custom_classes containing a dictionary defining wxPython classes and their custom equivalents. Note that this class attribute must be set at the top of the class definition before the first method.
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.
See Examples/advanced/CustomClasses/wxFrame1.py
Note that it's a simple implementation with the same limitations as custom
classes.
e.g. When adding your custom panel to the frame as a custom class, it will
display in the designer as a blank wxPanel (because that is it's equivalent class.
See Custom classes above).
To use, create a new custom panel from the Palette, name, design and save it.
Next go to the frame module where you want to use it, add an import statement
for it and add the _custom_classes attribute for it.
e.g.
from wxMyPanel1 import wxMyPanel1
from wxMyPanel2 import wxMyPanel2
...
class wxFrame1(wxFrame):
_custom_classes = {'wxPanel': ['wxMyPanel1', 'wxMyPanel2']}
def _init_utils(self):
pass
See Examples/advanced/FramePanels
|