AGW Logo

svn SVN Revision 68881 For shapedbutton

This file contains the SVN revision history for shapedbutton, at revision 68881.

Available information include commit date, the name of the committer, the file size, the SVN log messages and a diff from the previous version (if available).


file_info File Information

  • Commit Date: 17-Oct-2008 20:51:43 UTC
  • Committer: AG
  • File Size: 68352 byte(s)

svn_log Log Messages

The following log message was entered by the committer:

  • AGW: General overhaul of the documentation, much improved. All the widgets have their own sample usage in the docs as well;

  • FlatNotebook: Added the FNB_NAV_BUTTONS_WHEN_NEEDED style, which hides the navigation left/right arrows if all tabs fit;

  • RibbonBar: - Added the EVT_RIBBONBAR_TAB_LEFT_DCLICK event, which generates a special event

    when a ribbon bar tab is double-clicked;

    • Added support for toggle buttons;
    • Improved support for ribbon panel sizers: panels with sizers should now automatically minimise at small sizes, and behave properly when popping up from a minimised state;
    • Added tooltips via SetToolTip for those buttons which have the help_string attribute set.
  • XLSGrid: a new widget was added to AGW, termed XLSGrid. It’s based on wx.grid.Grid and can be used to faithfully reproduce the appearance of a Microsoft Excel spreadsheets.


svn_diff Diff To Previous Version (68362)

Version SVN diff:

--- wxPython/3rdParty/AGW/agw/shapedbutton.py       2011/07/24 21:36:47     68362
+++ wxPython/3rdParty/AGW/agw/shapedbutton.py       2011/08/25 16:40:17     68881
@@ -3,7 +3,7 @@
# Python Code By:
#
# Andrea Gavana, @ 18 Oct 2005
-# Latest Revision: 15 Aug 2010, 15.00 GMT
+# Latest Revision: 17 Aug 2011, 15.00 GMT
#
#
# TODO List/Caveats
@@ -40,14 +40,14 @@


"""
-ShapedButton tries to fill the lack of "custom shaped" controls in wxPython
+`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
===========

-ShapedButton tries to fill the lack of "custom shaped" controls in wxPython
+`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.

@@ -57,55 +57,72 @@
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
+`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.
+`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
=====

-The ShapedButton constructions, excluding wxPython parameter are, for the
-6 Classes::
+Usage example::

-    MyShapedButton = SButton(parent, label)
+    import wx
+    import wx.lib.agw.shapedbutton as SB

-    MyShapedButton = SBitmapButton(parent, bitmap)
+    class MyFrame(wx.Frame):

-    MyShapedButton = SBitmapTextButton(parent, bitmap, label)
+        def __init__(self, parent):
+
+            wx.Frame.__init__(self, parent, -1, "ShapedButton Demo")
+
+            panel = wx.Panel(self)

-    MyShapedButton = SToggleButton(parent, label)
+            # 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

-    MyShapedButton = SBitmapToggleButton(parent, bitmap)
+    app = wx.PySimpleApp()

-    MyShapedButton = SBitmapTextToggleButton(parent, bitmap, label)
+    frame = MyFrame(None)
+    app.SetTopWindow(frame)
+    frame.Show()

+    app.MainLoop()

-The ShapedButton construction and usage is quite similar to the `wx.lib.buttons`
+
+The `ShapedButton` construction and usage is quite similar to the `wx.lib.buttons`
implementation.


Methods and Settings
====================

-With ShapedButton you can:
+With `ShapedButton` you can:

-- create rounded/elliptical buttons/togglebuttons;
+- 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.
+- 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,
+:note: `ShapedButton` **requires** PIL (Python Imaging Library) library to be installed,
which can be downloaded from http://www.pythonware.com/products/pil/ .


@@ -130,9 +147,9 @@
License And Version
===================

-ShapedButton is distributed under the wxPython license.
+`ShapedButton` is distributed under the wxPython license.

-Latest revision: Andrea Gavana @ 15 Aug 2010, 15.00 GMT
+Latest revision: Andrea Gavana @ 17 Aug 2011, 15.00 GMT

Version 0.4

@@ -144,7 +161,6 @@
#----------------------------------------------------------------------

import wx
-from wx.lib import imageutils

# First Check If PIL Is Installed Properly
try:
@@ -252,7 +268,7 @@
#----------------------------------------------------------------------

class SButton(wx.Window):
-    """ This is the main implementation of ShapedButton. """
+    """ This is the main implementation of `ShapedButton`. """

_labeldelta = 1

@@ -394,6 +410,8 @@
"""
Overridden base class virtual. Determines the best size of the button
based on the label size.
+
+        :note: Overridden from `wx.Window`.
"""

w, h, usemin = self._GetLabelSize()
@@ -906,7 +924,7 @@

if alpha:
image = apply(wx.EmptyImage, pil.size)
-            image.SetData( pil.convert("RGB").tostring() )
+            image.SetData(pil.convert("RGB").tostring())
image.SetAlphaData(pil.convert("RGBA").tostring()[3::4])
else:
image = wx.EmptyImage(pil.size[0], pil.size[1])
@@ -1065,9 +1083,8 @@
self._bmplabel = bitmap

if bitmap is not None and createothers:
-            image = wx.ImageFromBitmap(bitmap)
-            imageutils.grayOut(image)
-            self.SetBitmapDisabled(wx.BitmapFromImage(image))
+            dis_bitmap = wx.BitmapFromImage(bitmap.ConvertToImage().ConvertToGreyscale())
+            self.SetBitmapDisabled(dis_bitmap)


def _GetLabelSize(self):
@@ -1368,7 +1385,7 @@
#----------------------------------------------------------------------

class SToggleButton(__SToggleMixin, SButton):
-    """ A ShapedButton toggle button. """
+    """ A `ShapedButton` toggle button. """
pass


@@ -1377,7 +1394,7 @@
#----------------------------------------------------------------------

class SBitmapToggleButton(__SToggleMixin, SBitmapButton):
-    """ A ShapedButton toggle bitmap button. """
+    """ A `ShapedButton` toggle bitmap button. """
pass


@@ -1386,7 +1403,7 @@
#----------------------------------------------------------------------

class SBitmapTextToggleButton(__SToggleMixin, SBitmapTextButton):
-    """ A ShapedButton toggle bitmap button with a text label. """
+    """ A `ShapedButton` toggle bitmap button with a text label. """
pass
Tree