Package muntjac :: Package event :: Module shortcut_action :: Class ShortcutAction
[hide private]
[frames] | no frames]

Class ShortcutAction

source code

   object --+    
            |    
action.Action --+
                |
               ShortcutAction
Known Subclasses:

Shortcuts are a special type of Actions used to create keyboard shortcuts.

The ShortcutAction is triggered when the user presses a given key in combination with the (optional) given modifier keys.

ShortcutActions can be global (by attaching to the Window), or attached to different parts of the UI so that a specific shortcut is only valid in part of the UI. For instance, one can attach shortcuts to a specific Panel - look for ComponentContainers implementing IHandler or INotifier.

ShortcutActions have a caption that may be used to display the shortcut visually. This allows the ShortcutAction to be used as a plain Action while still reacting to a keyboard shortcut. Note that this functionality is not very well supported yet, but it might still be a good idea to give a caption to the shortcut.


Authors:
Vaadin Ltd., Richard Lincoln
Instance Methods [hide private]
 
__init__(self, *args)
Creates a shortcut either using a shorthand notation to encode the keycode a in the caption or one that reacts to the given KeyCode and (optionally) ModifierKeys.
source code
 
getKeyCode(self)
Get the KeyCode that this shortcut reacts to (in combination with the ModifierKeys).
source code
 
getModifiers(self)
Get the ModifierKeys required for the shortcut to react.
source code

Inherited from action.Action: __eq__, getCaption, getIcon, setCaption, setIcon

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  SHORTHAND_CHAR_ALT = '&'
  SHORTHAND_CHAR_CTRL = '^'
  SHORTHAND_CHAR_SHIFT = '_'
  _SHORTHANDS = re.compile(r'([&_\^])(?!\1)(?:([&_\^])(?!\1|\2))...
  _SHORTHAND_ALT = '\\&'
  _SHORTHAND_CTRL = '\\^'
  _SHORTHAND_ESCAPE = re.compile(r'(&?)&|(_?)_|(\^?)\^')
  _SHORTHAND_REMOVE = re.compile(r'([&\|_\|\^])\1')
  _SHORTHAND_SHIFT = '\\_'
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args)
(Constructor)

source code 

Creates a shortcut either using a shorthand notation to encode the keycode a in the caption or one that reacts to the given KeyCode and (optionally) ModifierKeys.

The shortcut might be shown in the UI (e.g context menu), in which case the caption will be used.

Insert one or more modifier characters before the character to use as keycode. E.g "&Save" will make a shortcut responding to ALT-S, "E^xit" will respond to CTRL-X.<br/> Multiple modifiers can be used, e.g "&^Delete" will respond to CTRL-ALT-D (the order of the modifier characters is not important).

The modifier characters will be removed from the caption. The modifier character is be escaped by itself: two consecutive characters are turned into the original character w/o the special meaning. E.g "Save&&&close" will respond to ALT-C, and the caption will say "Save&close".

Parameters:
  • args - tuple of the form
    • (caption, kc, m)
      1. used when displaying the shortcut visually
      2. KeyCode that the shortcut reacts to
      3. optional modifier keys
    • (caption, icon, kc, m)
      1. used when displaying the shortcut visually
      2. used when displaying the shortcut visually
      3. KeyCode that the shortcut reacts to
      4. optional modifier keys
    • (shorthandCaption)
      1. the caption in modifier shorthand
    • (shorthandCaption, modifierKeys)
      1. the caption in modifier shorthand
      2. modifier keys
Overrides: object.__init__

getKeyCode(self)

source code 

Get the KeyCode that this shortcut reacts to (in combination with the ModifierKeys).

Returns:
keycode for this shortcut

getModifiers(self)

source code 

Get the ModifierKeys required for the shortcut to react.

Returns:
modifier keys for this shortcut

Class Variable Details [hide private]

_SHORTHANDS

Value:
re.compile(r'([&_\^])(?!\1)(?:([&_\^])(?!\1|\2))?(?:([&_\^])(?!\1|\2|\\
3))?.')