AGW Logo

agw_title shapedbutton

ShapedButton tries to fill the lack of “custom shaped” controls in wxPython and it can be used to build round or elliptic-shaped buttons.


description Description

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 Usage

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.


settings Methods and Settings

With ShapedButton you can:

  • Create rounded/elliptical buttons/togglebuttons;
  • Set images for the enabled/disabled/focused/selected state of the button;
  • Draw the focus indicator (or disable it);
  • Set label colour and font;
  • Apply a rotation to the ShapedButton label;
  • Change ShapedButton shape and text orientation in runtime.

Note

ShapedButton requires PIL (Python Imaging Library) library to be installed, which can be downloaded from http://www.pythonware.com/products/pil/ .


styles Window Styles

No particular window styles are available for this class.


events Events Processing

This class processes the following events:


Events processing for shapedbutton
Event Name Description
wx.EVT_BUTTON Process a wx.wxEVT_COMMAND_BUTTON_CLICKED event, when the button is clicked.

license License And Version

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>


hierarchy Inheritance Diagram

Inheritance diagram for module: shapedbutton

Inheritance diagram of shapedbutton.SBitmapButton, shapedbutton.SBitmapTextButton, shapedbutton.SBitmapTextToggleButton, shapedbutton.SBitmapToggleButton, shapedbutton.SButton, shapedbutton.SButtonEvent, shapedbutton.SToggleButton, shapedbutton.__SToggleMixin


svn_main SVN Revisions

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.

shapedbutton

Revision Graph For shapedbutton


2to3 Python 3 Issues (via 2to3)

No issues have been detected by 2to3.py.


method_summary Function Summary