Hello NG,
I apologise in advance for the somewhat long email I am writing. A
while back Robin asked me to implement some more functionalities, and
here we are with the improved latest version of ButtonPanel.
To say something in advance (please read it!), the docstrings needs to
be improved (i will look at it quite soon), right now support for
shortHelp in tooltip and longHelp in statusbar fields is being
implemented. And I am thinking about implementing chevron button
support for ButtonPanel and/or multirow/multicolumn layout for items
(ButtonPanel is essentially a wx.Toolbar, almost).
But before going on with this (complex, I would say) work, I would
really appreciate some inputs from this kind NG (bugs, misbehavior and
so on); moreover, there are a couple of issues (marked as #WEIRD and
#NOTE inside the source and the demo): noting that the vast majority
of people here is far smarter than me in wxPython coding, I would like
to ask wxPython-gurus for suggestions on how to improve the general
Layout strategy (faster? Nicer? Better?).
Ok, talked enough. How it works:
ButtonPanel is similar to a wx.ToolBar, with the ability to draw
gradient shading background and the possibility to add custom controls
(see below) behind which the gradient shading is kept.
Improvements:
- Existing Things:
1) Buttons: buttons now can have text associated with them. The text
and the image in the button can be drawn stacked (i.e. the text is
below the image) or the text can be drawn to the right of the button
(similar to wx.ToolBar);
2) Gradient shading: gradient can now be horizontal or vertical;
3) Rendering: the drawing of ButtonPanel background and of its custom
control has been moved to a separate manager class;
- New implementations:
1) ButtonPanel now supports the 4 alignment: left, right, top, bottom,
which have a different meaning and behavior wrt wx.Toolbar. The
easiest thing is to try the demo to understand, but I'll try to
explain how it works.
CASE 1: ButtonPanel has a main caption text
Left alignment means ButtonPanel is horizontal, with the text aligned
to the left. When you shrink the demo frame, if there is not enough
room for all the controls to be shown, the controls closest to the
text are hidden;
Right alignment means ButtonPanel is horizontal, with the text aligned
to the right. Item layout as above;
Top alignment means ButtonPanel is vertical, with the text aligned to
the top. Item layout as above;
Bottom alignment means ButtonPanel is vertical, with the text aligned
to the bottom. Item layout as above.
CASE 2: ButtonPanel has *no* main caption text
In this case, left and right alignment are the same (as top and bottom
are the same), but the layout strategy changes: now if there is not
enough room for all the controls to be shown, the last added items are
hidden ("last" means on the far right for horizontal ButtonPanels and
far bottom for vertical ButtonPanels).
I hope I made myself clear. Trying the demo is the easiest thing to do
2) Possibility to add separators (as in wx.Toolbars) and specify their size;
3) Possibility to add spacers (flexible or fixed-space) at the
beginning, at the end or between the ButtonPanel items;
4) Possibility to add wxPython controls to ButtonPanel: be aware
however that controls that do not have transparent background (i.e.
wx.CheckBox) will paint horribly on a gradient shading ButtonPanel.
5) Buttons support wx.ITEM_NORMAL (for normal buttons) and
wx.ITEM_CHECK (for toggle buttons). I am in the process of adding
wx.ITEM_RADIO support;
6) Buttons have 5 "states" by default:
a) Normal
b) Disabled
c) Hover
d) Pressed
e) Toggled
Any of these states can have a bitmap associated with it. Moreover,
you can add as many states as you want to a particular bitmap (just
name them, such like "Custom" state) and associate a custom bitmap to
that state;
7) ButtonPanel margins (i.e. space at the beginning and at the end of
ButtonPanel), padding (inter-tool spacing), border size, and separator
spacing can be customized;
8) For colours, main caption, gradients, static background, border,
hovering/pressing brush/pen selection, text in buttons colours can be
customized;
9) Fonts for main caption text and text in buttons can be customized.
Ok, I re-apologize for this fantastically long and boring e-mail. You
can find the source and the demo in the usual places:
http://xoomer.alice.it/infinity77/eng/ButtonPanel.html
http://xoomer.alice.it/infinity77/ita/ButtonPanel.html
If you have any suggestion (and maybe something to fix the #WEIRD and
#NOTE problems in the source), please let me know.
Happy wxPythoning
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/