AGW Logo

agw_title Shortcut

Shortcut is a class containing the details for a shortcut, whether from a menu item, an accelerator or a user-defined shortcut. It behaves like a tree, with children and parents.

hierarchy Inheritance Diagram

Inheritance diagram for: Shortcut

Inheritance diagram of Shortcut


method_summary Methods Summary

__init__Default class constructor.
AppendItemAppends a Shortcut item as a last child of its parent.
CheckAcceleratorChecks if a shortcut string entered by the user has already been taken by another entry
FromMenuItemConstructs this Shortcut starting from a wx.Menu or wx.MenuItem.
GetReturns an instance of Shortcut whose label matches the input label string.
GetAcceleratorReturns the string accelerator associated with this shortcut.
GetBitmapReturns the bitmap associated with this Shortcut.
GetByIdReturns an instance of Shortcut whose ID matches the input id.
GetFirstChildReturns this Shortcut‘s first child and an integer value ‘cookie’.
GetIdReturns this Shortcut ID.
GetImageIndexReturns an integer index to be used in the ListShortcut own wx.ImageList.
GetLabelReturns the string label associated with this shortcut.
GetNextChildReturns this Shortcut‘s next child.
HasChangedReturns True if the current accelerator associated with this Shortcut is
IsTopReturns True if this Shortcut is associated with a top-level wx.Menu,
MatchMatches this Shortcut label string against the filter input variable.
ResetVisibilitySet the status of this Shortcut and its parent as hidden in the
RestoreDefaultsRestore the original shortcut string for this Shortcut.
SetAcceleratorSets the string accelerator associated with this shortcut.
SetBitmapSets the bitmap associated with this Shortcut.
ShowHierarchySet the status of this Shortcut ans its parent as shown in the
ToAcceleratorItemDumps this Shortcut into a tuple of 3 elements:
ToMenuItemDumps this Shortcut into a wx.Menu or wx.MenuItem.

API Class API

class Shortcut(object)[source]

Shortcut is a class containing the details for a shortcut, whether from a menu item, an accelerator or a user-defined shortcut. It behaves like a tree, with children and parents.



__init__(label='', accelerator='', bitmap=wx.NullBitmap, help='', menuItem=None, accelId=None)[source]

Default class constructor.

Parameters:
  • label (string) – the shortcut label string;
  • accelerator (string) – the shortcut accelerator string;
  • bitmap – an instance of wx.Bitmap, to display along the shortcut label in the interface tree;
  • help (string) – the help string for this shortcut, to display in the interface tree;
  • menuItem – if this Shortcut is derived from a wx.MenuItem, the wx.MenuItem to which it should be associated;

  • accelId (integer) – if this Shortcut is derived from an accelerator in a wx.AcceleratorTable or from a custom, developer-defined shortcut, it represents the ID it is associated with.


AppendItem(item)[source]

Appends a Shortcut item as a last child of its parent.

Parameters:item – an instance of Shortcut.


CheckAccelerator(item, shortcut, accelerator)[source]

Checks if a shortcut string entered by the user has already been taken by another entry in the Shortcut hierarchy.

Parameters:
  • item – an instance of Shortcut;
  • shortcut – another instance of Shortcut, to compare with the previous item;
  • accelerator (string) – the user-edited accelerator string to check.
Returns:

An instance of Shortcut if the shortcut string entered by the user conflicts with an existing one, None otherwise.



FromMenuItem()[source]

Constructs this Shortcut starting from a wx.Menu or wx.MenuItem.

The attributes needed to properly construct a Shortcut are the label, the accelerator string, the help string (optional) and the bitmap associated with it (optional).



Get(label, item=None)[source]

Returns an instance of Shortcut whose label matches the input label string.

Parameters:
  • label (string) – the string label to compare against this Shortcut label;
  • item – an instance of Shortcut, used only to make this function reentrant (i.e. allow more than one enumeration on one and the same object simultaneously).
Returns:

An instance of Shortcut or None if no match was found.



GetAccelerator()[source]

Returns the string accelerator associated with this shortcut.



GetBitmap()[source]

Returns the bitmap associated with this Shortcut.

Note

You should always check if the returned bitmap is a valid one or not:

bitmap = shortcut.GetBitmap()
if bitmap.IsOk():
    DoSomething()

as the default bitmap associated with a Shortcut is wx.NullBitmap.



GetById(id, item=None)[source]

Returns an instance of Shortcut whose ID matches the input id.

Parameters:
  • id (integer) – an integer ID to compare against this Shortcut id;
  • item – an instance of Shortcut, used only to make this function reentrant (i.e. allow more than one enumeration on one and the same object simultaneously).
Returns:

An instance of Shortcut or None if no match was found.



GetFirstChild(item)[source]

Returns this Shortcut‘s first child and an integer value ‘cookie’. Call GetNextChild for the next child using this very ‘cookie’ return value as an input.

Parameters:item – an instance of Shortcut.
Returns:A tuple with the first value being an instance of Shortcut or None if there are no further children, and as second value an integer parameter ‘cookie’.

Note

This method returns None if there are no further children.



GetId()[source]

Returns this Shortcut ID.



GetImageIndex()[source]

Returns an integer index to be used in the ListShortcut own wx.ImageList.



GetLabel()[source]

Returns the string label associated with this shortcut.



GetNextChild(item, cookie)[source]

Returns this Shortcut‘s next child.

Parameters:
  • item – an instance of Shortcut;
  • cookie (integer) – a parameter which is opaque for the application but is necessary for the library to make this function reentrant (i.e. allow more than one enumeration on one and the same object simultaneously).
Returns:

A tuple with the first value being an instance of Shortcut or None if there are no further children, and as second value an integer parameter ‘cookie’.

Note

This method returns None if there are no further children.



HasChanged()[source]

Returns True if the current accelerator associated with this Shortcut is different from the original one, False otherwise.



IsTop()[source]

Returns True if this Shortcut is associated with a top-level wx.Menu, (i.e., in the top wx.MenuBar level), False otherwise.



Match(filter=u'', item=None)[source]

Matches this Shortcut label string against the filter input variable.

Parameters:
  • filter (string) – a string to match;
  • item – an instance of Shortcut: its label string is compared with the filter string to look for a match.
Returns:

An instance of Shortcut if the filter string is contained in the item lable, None otherwise.

Note

The string-matching is case-insensitive.



ResetVisibility(item=None)[source]

Set the status of this Shortcut and its parent as hidden in the ListShortcut tree hierarchy.

Parameters:item – an instance of Shortcut, used only to make this function reentrant (i.e. allow more than one enumeration on one and the same object simultaneously).


RestoreDefaults(item=None)[source]

Restore the original shortcut string for this Shortcut.

Parameters:item – an instance of Shortcut, used only to make this function reentrant (i.e. allow more than one enumeration on one and the same object simultaneously).


SetAccelerator(accelerator)[source]

Sets the string accelerator associated with this shortcut.

Parameters:accelerator (string) – a string representing the shortcut string (accelerator).


SetBitmap(bitmap)[source]

Sets the bitmap associated with this Shortcut.

Parameters:bitmap – an instance of wx.Bitmap (can be invalid, i.e., wx.NullBitmap).



ShowHierarchy(item)[source]

Set the status of this Shortcut ans its parent as shown in the ListShortcut tree hierarchy.

Parameters:item – an instance of Shortcut.


ToAcceleratorItem(table)[source]

Dumps this Shortcut into a tuple of 3 elements:

  • flags: a bitmask of wx.ACCEL_ALT, wx.ACCEL_SHIFT, wx.ACCEL_CTRL, wx.ACCEL_CMD or wx.ACCEL_NORMAL used to specify which modifier keys are held down;
  • keyCode: the keycode to be detected (i.e., ord(‘b’), wx.WXK_F10, etc...);
  • cmdID: the menu or control command ID to use for the accelerator event.
Parameters:table – a list of tuples, with the above specifications.


ToMenuItem(menuBar)[source]

Dumps this Shortcut into a wx.Menu or wx.MenuItem.

The attributes needed to properly dump a Shortcut into a wx.Menu or wx.MenuBar are the label and the accelerator string.

Parameters:menuBar – an instance of wx.MenuBar.

Tree

Table Of Contents

Previous topic

ListShortcut

Next topic

ShortcutEditor