1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2018 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. module:: wx.lib.agw.shapedbutton
.. currentmodule:: wx.lib.agw.shapedbutton
.. highlight:: python
.. _wx.lib.agw.shapedbutton:
==========================================================================================================================================
|phoenix_title| **wx.lib.agw.shapedbutton**
==========================================================================================================================================
:class:`~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 :mod:`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 :class:`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 :mod:`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
====================================
================================================================================ ================================================================================
:func:`~wx.lib.agw.shapedbutton.opj` Convert paths to the platform-specific separator.
================================================================================ ================================================================================
|
|class_summary| Classes Summary
===============================
================================================================================ ================================================================================
:ref:`~wx.lib.agw.shapedbutton.__SToggleMixin` A mixin that allows to transform any of :class:`SButton`, :class:`SBitmapButton` and
:ref:`~wx.lib.agw.shapedbutton.SBitmapButton` Subclass of :class:`SButton` which displays a bitmap, acting like a
:ref:`~wx.lib.agw.shapedbutton.SBitmapTextButton` Subclass of :class:`SButton` which displays a bitmap and a label.
:ref:`~wx.lib.agw.shapedbutton.SBitmapTextToggleButton` A `ShapedButton` toggle bitmap button with a text label.
:ref:`~wx.lib.agw.shapedbutton.SBitmapToggleButton` A `ShapedButton` toggle bitmap button.
:ref:`~wx.lib.agw.shapedbutton.SButton` This is the main implementation of `ShapedButton`.
:ref:`~wx.lib.agw.shapedbutton.SButtonEvent` Event sent from the generic buttons when the button is activated.
:ref:`~wx.lib.agw.shapedbutton.SToggleButton` A `ShapedButton` toggle button.
================================================================================ ================================================================================
|
.. toctree::
:maxdepth: 1
:hidden:
wx.lib.agw.shapedbutton.__SToggleMixin
wx.lib.agw.shapedbutton.SBitmapButton
wx.lib.agw.shapedbutton.SBitmapTextButton
wx.lib.agw.shapedbutton.SBitmapTextToggleButton
wx.lib.agw.shapedbutton.SBitmapToggleButton
wx.lib.agw.shapedbutton.SButton
wx.lib.agw.shapedbutton.SButtonEvent
wx.lib.agw.shapedbutton.SToggleButton
Functions
------------
.. function:: opj(path)
Convert paths to the platform-specific separator.
:param `path`: the path to convert.
|