[wxPython-users] [ANN] PlateButton Control for wxPython
Robin Dunn
robin at alldunn.com
Thu Dec 13 13:50:34 PST 2007
Cody Precord wrote:
> For a more complete picture download the source and run the included
> demo (PlateButtonDemo.py):
>
Looks nice. Here are a few tips for custom controls in general, and
also a few things I noticed about this one:
* You should allow all the standard widget args in the __init__ method,
so people don't have to look at your code to know what parameters it
accepts, or for tools like XRCed. You're missing pos, size, and name.
Pass them all on to the base class __init__.
* For playing nice with sizers you should call SetInitialSize from the
__init__, passing the size that was given as a parameter, default to
wx.DefaultSize. This will do a couple things. 1) will set the size of
the widget either to the size passed in, or to the best size if one or
both of the size components are given as default values. 2) Will set
the widget's minsize to the size given.
* Also for playing nice with sizers, and with the previous item, you
should implement a DoGetBestSize method that calculates and returns a
wx.Size that is the optimal size of the widget based on its label, font
size, image size, style, etc. In this case your DoGetBestSize could be
just your current __CalcBestSize without the lines at the end that
actually set the size. Let the user, sizer, or things like
SetInitialSize do that part for you instead. All your calls to
__CalcBestSize could probably be removed, or if you use CacheBestSize
then they can be replaced with InvalidaeBestSize.
* You can also override AcceptsFocus, although the default in the base
class is probably good enough for this widget....
* I noticed that the text color chosen on Windows for when the button is
in the pressed state is almost unreadable.
* I would make the activation key be WXK_SPACE on all platforms, not
just windows.
* You might also want to respond to EVT_CONTEXT_MENU for the buttons
with a menu. Then on Windows at least the user can get to the menu
without using the mouse, since there is a menu key on the keyboard.
* I notice that when tabbing between widgets that the previously focused
widget loses its highlight noticeably *after* the newly focused widget
is highlighted. This looks really really weird.
* Clicking a button isn't setting the focus there.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list