Phoenix Logo

phoenix_title wx.lib.agw.shapedbutton.SButton

This is the main implementation of ShapedButton.


class_hierarchy Class Hierarchy

Inheritance diagram for class SButton:


super_classes Known Superclasses

wx.Window


method_summary Methods Summary

__init__ Default class constructor.
AcceptsFocus Can this window be given focus by mouse click?
ConvertPILToWX Converts a PIL image into a wx.Image.
ConvertWXToPIL Converts a wx.Image into a PIL image.
DoGetBestSize Overridden base class virtual. Determines the best size of the button
DrawFocusIndicator Draws the focus indicator. This is a circle/ellipse inside the button
DrawLabel Draws the label on the button.
DrawMainButton Draws the main button, in whichever state it is.
Enable Enables/disables the button.
GetAngleOfRotation Returns angle of button label rotation, in degrees.
GetButtonColour Returns the button colour.
GetEllipseAxis Returns the ellipse axes.
GetLabel Returns the button label.
GetLabelColour Returns the button label colour.
GetUseFocusIndicator Returns focus indicator flag.
InitColours Calculates a new set of focus indicator colour and indicator pen
IsEnabled Returns wheter the button is enabled or not.
IsOutside Checks if a mouse events occurred inside the circle/ellipse or not.
MakePalette Creates a palette to be applied on an image based on input colour.
Notify Notifies an event and let it be processed.
OnGainFocus Handles the wx.EVT_SET_FOCUS event for SButton.
OnKeyDown Handles the wx.EVT_KEY_DOWN event for SButton.
OnKeyUp Handles the wx.EVT_KEY_UP event for SButton.
OnLeftDown Handles the wx.EVT_LEFT_DOWN event for SButton.
OnLeftUp Handles the wx.EVT_LEFT_UP event for SButton.
OnLoseFocus Handles the wx.EVT_KILL_FOCUS event for SButton.
OnMotion Handles the wx.EVT_MOTION event for SButton.
OnPaint Handles the wx.EVT_PAINT event for SButton.
OnSize Handles the wx.EVT_SIZE event for SButton.
SetAngleOfRotation Sets angle of button label rotation.
SetBestSize Given the current font settings, calculate and set a good size.
SetButtonColour Sets the button colour, for all button states.
SetDefault Sets the button as default item.
SetEllipseAxis Sets the ellipse axis. What it is important is not their absolute values
SetLabel Sets the button label.
SetLabelColour Sets the button label colour.
SetUseFocusIndicator Specifies if a focus indicator (dotted line) should be used.
ShouldInheritColours Overridden base class virtual. Buttons usually do not inherit

api Class API



class SButton(wx.Window)

This is the main implementation of ShapedButton.


Methods



__init__(self, parent, id=wx.ID_ANY, label="", pos=wx.DefaultPosition, size=wx.DefaultSize)

Default class constructor.

Parameters:
  • parent – the SButton parent. Must not be None;
  • id – window identifier. A value of -1 indicates a default value;
  • label – the button text label;
  • pos – the control position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxPython, depending on platform;
  • size – the control size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxPython, depending on platform.


AcceptsFocus(self)

Can this window be given focus by mouse click?

Note

Overridden from wx.Window.



ConvertPILToWX(self, pil, alpha=True)

Converts a PIL image into a wx.Image.

Parameters:
  • pil – a PIL image;
  • alphaTrue if the image contains alpha transparency, False otherwise.


ConvertWXToPIL(self, bmp)

Converts a wx.Image into a PIL image.

Parameters:bmp – an instance of wx.Image.


DoGetBestSize(self)

Overridden base class virtual. Determines the best size of the button based on the label size.

Note

Overridden from wx.Window.



DrawFocusIndicator(self, dc, width, height)

Draws the focus indicator. This is a circle/ellipse inside the button drawn with a dotted-style pen, to let the user know which button has the focus.

Parameters:
  • dc – an instance of wx.DC;
  • width – the button width;
  • height – the button height.


DrawLabel(self, dc, width, height, dw=0, dh=0)

Draws the label on the button.

Parameters:
  • dc – an instance of wx.DC;
  • width – the button width;
  • height – the button height;
  • dw – width differential, to show a 3D effect;
  • dh – height differential, to show a 3D effect.


DrawMainButton(self, dc, width, height)

Draws the main button, in whichever state it is.

Parameters:
  • dc – an instance of wx.DC;
  • width – the button width;
  • height – the button height.


Enable(self, enable=True)

Enables/disables the button.

Parameters:enableTrue to enable the button, False to disable it.

Note

Overridden from wx.Window.



GetAngleOfRotation(self)

Returns angle of button label rotation, in degrees.



GetButtonColour(self)

Returns the button colour.



GetEllipseAxis(self)

Returns the ellipse axes.



GetLabel(self)

Returns the button label.



GetLabelColour(self)

Returns the button label colour.



GetUseFocusIndicator(self)

Returns focus indicator flag.



InitColours(self)

Calculates a new set of focus indicator colour and indicator pen based on button colour and label colour.



IsEnabled(self)

Returns wheter the button is enabled or not.



IsOutside(self, x, y)

Checks if a mouse events occurred inside the circle/ellipse or not.

Parameters:
  • x – the mouse x position;
  • y – the mouse y position.


MakePalette(self, tr, tg, tb)

Creates a palette to be applied on an image based on input colour.

Parameters:
  • tr – the red intensity of the input colour;
  • tg – the green intensity of the input colour;
  • tb – the blue intensity of the input colour.


Notify(self)

Notifies an event and let it be processed.



OnGainFocus(self, event)

Handles the wx.EVT_SET_FOCUS event for SButton.

Parameters:event – a FocusEvent event to be processed.


OnKeyDown(self, event)

Handles the wx.EVT_KEY_DOWN event for SButton.

Parameters:event – a KeyEvent event to be processed.


OnKeyUp(self, event)

Handles the wx.EVT_KEY_UP event for SButton.

Parameters:event – a KeyEvent event to be processed.


OnLeftDown(self, event)

Handles the wx.EVT_LEFT_DOWN event for SButton.

Parameters:event – a MouseEvent event to be processed.


OnLeftUp(self, event)

Handles the wx.EVT_LEFT_UP event for SButton.

Parameters:event – a MouseEvent event to be processed.


OnLoseFocus(self, event)

Handles the wx.EVT_KILL_FOCUS event for SButton.

Parameters:event – a FocusEvent event to be processed.


OnMotion(self, event)

Handles the wx.EVT_MOTION event for SButton.

Parameters:event – a MouseEvent event to be processed.


OnPaint(self, event)

Handles the wx.EVT_PAINT event for SButton.

Parameters:event – a PaintEvent event to be processed.


OnSize(self, event)

Handles the wx.EVT_SIZE event for SButton.

Parameters:event – a wx.SizeEvent event to be processed.


SetAngleOfRotation(self, angle=None)

Sets angle of button label rotation.

Parameters:angle – the label rotation, in degrees.


SetBestSize(self, size=None)

Given the current font settings, calculate and set a good size.

Parameters:size – if not None, an instance of wx.Size to pass to SetInitialSize.


SetButtonColour(self, colour=None)

Sets the button colour, for all button states.

Parameters:colour – an instance of wx.Colour.

Note

The original button images are greyscale with a lot of pixels with different colours. Changing smoothly the button colour in order to give the same 3D effect can be efficiently done only with PIL.



SetDefault(self)

Sets the button as default item.



SetEllipseAxis(self, main=None, secondary=None)

Sets the ellipse axis. What it is important is not their absolute values but their ratio.

Parameters:
  • main – a floating point number representing the absolute dimension of the main ellipse axis;
  • secondary – a floating point number representing the absolute dimension of the secondary ellipse axis.


SetLabel(self, label=None)

Sets the button label.

Parameters:label – the new button label.


SetLabelColour(self, colour=None)

Sets the button label colour.

Parameters:colour – an instance of wx.Colour.


SetUseFocusIndicator(self, flag)

Specifies if a focus indicator (dotted line) should be used.

Parameters:flagTrue to use the focus indicator, False otherwise.


ShouldInheritColours(self)

Overridden base class virtual. Buttons usually do not inherit parent’s colours.