ShapedButton tries to fill the lack of “custom shaped” controls in wxPython and it can be used to build round or elliptic-shaped buttons.
ShapedButton tries to fill the lack of “custom shaped” controls in wxPython (that depends on the same lack in wxWidgets). It can be used to build round buttons or elliptic buttons.
I have stolen some code from wx.lib.buttons in order to recreate the same classes (GenButton, GenBitmapButton, GenBitmapTextButton, GenToggleButton, GenBitmapToggleButton, GenBitmapTextToggleButton). Here you have the same classes (with “Gen” replaced by “S”), with the same event handling, but they are rounded/elliptical buttons.
ShapedButton is based on a wx.Window, in which 2 images are drawn depending on the button state (pressed or not pressed). The 2 images have been stolen from Audacity (written with wxWidgets) and rearranged/reshaped/restyled using adobe PhotoShop. Changing the button colour in runtime was more difficult, but using some intelligent instruction from the PIL library it can be done.
ShapedButton reacts on mouse events only if the mouse event occurred inside the circle/ellipse, even if ShapedButton is built on a rectangular window. This behavior is a lot different with respect to Audacity round buttons.
Usage example:
import wx
import wx.lib.agw.shapedbutton as SB
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "ShapedButton Demo")
panel = wx.Panel(self)
# Create 2 bitmaps for the button
upbmp = wx.Bitmap("play.png", wx.BITMAP_TYPE_PNG)
disbmp = wx.Bitmap("playdisabled.png", wx.BITMAP_TYPE_PNG)
play = SB.SBitmapToggleButton(panel, -1, upbmp, (100, 50))
play.SetUseFocusIndicator(False)
play.SetBitmapDisabled(disbmp)
# our normal wxApp-derived class, as usual
app = wx.PySimpleApp()
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
This code snippet can be downloaded, see this example script.
Note
Some of the AGW snippets of code in the documentation use images and external files (to create bitmaps or access external data). As these files are not provided in these snippets, you should make the approriate modifications to the code to actually run it.
The ShapedButton construction and usage is quite similar to the wx.lib.buttons implementation.
With ShapedButton you can:
Note
ShapedButton requires PIL (Python Imaging Library) library to be installed, which can be downloaded from http://www.pythonware.com/products/pil/ .
This class processes the following events:
Event Name | Description |
---|---|
wx.EVT_BUTTON | Process a wx.wxEVT_COMMAND_BUTTON_CLICKED event, when the button is clicked. |
ShapedButton is distributed under the wxPython license.
Latest revision: Andrea Gavana @ 16 Jan 2012, 20.00 GMT
Version 0.4
Module author: Andrea Gavana <andrea.gavana@gmail.com>
A graphical representation of the SVN commits in the last year.
Click on any date in the picture to jump to that particular revision page, containing information about committers, log messages and SVN diffs.
Revision Graph For shapedbutton