phoenix_title wx.lib.agw.shapedbutton

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

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 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 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.App(0)

frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()

app.MainLoop()

The ShapedButton construction and usage is quite similar to the lib.buttons implementation.

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/ .

Window Styles

No particular window styles are available for this class.

Events Processing

This class processes the following events:

Event Name

Description

wx.EVT_BUTTON

Process a wxEVT_COMMAND_BUTTON_CLICKED event, when the button is clicked.

License And Version

ShapedButton is distributed under the wxPython license.

Latest revision: Andrea Gavana @ 16 Jul 2012, 15.00 GMT

Version 0.5

function_summary Functions Summary

opj

Convert paths to the platform-specific separator.


class_summary Classes Summary

__SToggleMixin

A mixin that allows to transform any of SButton, SBitmapButton and

SBitmapButton

Subclass of SButton which displays a bitmap, acting like a

SBitmapTextButton

Subclass of SButton which displays a bitmap and a label.

SBitmapTextToggleButton

A ShapedButton toggle bitmap button with a text label.

SBitmapToggleButton

A ShapedButton toggle bitmap button.

SButton

This is the main implementation of ShapedButton.

SButtonEvent

Event sent from the generic buttons when the button is activated.

SToggleButton

A ShapedButton toggle button.


Functions



opj(path)

Convert paths to the platform-specific separator.

Parameters

path – the path to convert.