AGW Logo

agw_title ShortcutEditor

ShortcutEditor is a widget that allows the user to customize and change keyboard shortcuts via a dialog. It can be used to edit wx.MenuItem shortcuts or accelerators defined in a wx.AcceleratorTable.

The interface itself is very much inpired by the GIMP shortcut editor:

http://graphicssoft.about.com/od/gimptutorials/tp/keyboard-shortcut-editor.htm

There are very few minor UI differences between ShortcutEditor and the GIMP one, although the behaviour should be pretty much equivalent.

hierarchy Inheritance Diagram

Inheritance diagram for: ShortcutEditor

Inheritance diagram of ShortcutEditor


appearance Control Appearance


ShortcutEditor

ShortcutEditor


method_summary Methods Summary

__init__Default class constructor.
BindEventsBinds a few events we will need to process:
CreateWidgetsCreates all the widgets needed to populate the interface, such as buttons,
DoLayoutLays out the widgets using sizers in a platform-independent way.
FromAcceleratorTableBuilds the entire shortcut hierarchy starting from a modified version of a wx.AcceleratorTable.
FromMenuBarBuilds the entire shortcut hierarchy starting from a wx.MenuBar.
GetShortcutManagerReturns the root Shortcut containing the whole shortcut hierarchy.
InitCommon initialization procedures.
OnClearFilterHandles the wx.EVT_BUTTON event for ShortcutEditor when the user clears the
OnHTMLHelpHandles the wx.EVT_BUTTON event for ShortcutEditor when the user presses the Help
OnRestoreDefaultsHandles the wx.EVT_BUTTON event for ShortcutEditor when the user restores the
OnSetFilterHandles the wx.EVT_TEXT event for ShortcutEditor.
PreShowDoes some more common initialization before showing ShortcutEditor.
SetColumnWidthsSets the ListShortcut columns widths to acceptable and eye-pleasing
SetHTMLHelpFileSets a new HTML help file (a valid html file) to be loaded when the user seeks
ShowHides or shows the ShortcutEditor dialog.
ShowModalShows the ShortcutEditor dialog in an application-modal way.
ToAcceleratorTableDumps the entire shortcut hierarchy (for shortcuts associated with a wx.AcceleratorTable), into
ToMenuBarDumps the entire shortcut hierarchy (for shortcuts associated with a wx.MenuItem), into

API Class API

class ShortcutEditor(wx.Dialog)[source]

ShortcutEditor is a widget that allows the user to customize and change keyboard shortcuts via a dialog. It can be used to edit wx.MenuItem shortcuts or accelerators defined in a wx.AcceleratorTable.

The interface itself is very much inpired by the GIMP shortcut editor:

http://graphicssoft.about.com/od/gimptutorials/tp/keyboard-shortcut-editor.htm

There are very few minor UI differences between ShortcutEditor and the GIMP one, although the behaviour should be pretty much equivalent.



__init__(parent)[source]

Default class constructor.

Parameters:parent – an instance of wx.Window, it can also be None.


BindEvents()[source]

Binds a few events we will need to process:

  • wx.EVT_TEXT for the label filtering;
  • wx.EVT_BUTTON for clearing the filtering, for the HTML help window and to reset all the shortcuts to their defaults.


CreateWidgets()[source]

Creates all the widgets needed to populate the interface, such as buttons, texts and, most importantly, ListShortcut.



DoLayout()[source]

Lays out the widgets using sizers in a platform-independent way.



FromAcceleratorTable(accelTable)[source]

Builds the entire shortcut hierarchy starting from a modified version of a wx.AcceleratorTable.

Parameters:accelTable – a modified version of wx.AcceleratorTable, is a list of tuples (4 elements per tuple), populated like this:

accelTable = []

# Every tuple is defined in this way:

for label, flags, keyCode, cmdID in my_accelerators:
    # label:   the string used to show the accelerator into the ShortcutEditor dialog
    # 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.

    accel_tuple = (label, flags, keyCode, cmdID)
    accelTable.append(accel_tuple)


FromMenuBar(topWindow)[source]

Builds the entire shortcut hierarchy starting from a wx.MenuBar.

Parameters:topWindow – an instance of wx.TopLevelWindow, containing the wx.MenuBar we wish to scan.



GetShortcutManager()[source]

Returns the root Shortcut containing the whole shortcut hierarchy.



Init()[source]

Common initialization procedures.



OnClearFilter(event)[source]

Handles the wx.EVT_BUTTON event for ShortcutEditor when the user clears the label filter at the top of the user interface.

Parameters:event – an instance of wx.CommandEvent.


OnHTMLHelp(event)[source]

Handles the wx.EVT_BUTTON event for ShortcutEditor when the user presses the Help button.

Parameters:event – an instance of wx.CommandEvent.

Note

By default, this method launches a wx.html.HtmlWindow containing the default HTML help file. If you wish to load another help file, you should call SetHTMLHelpFile with another input HTML file.



OnRestoreDefaults(event)[source]

Handles the wx.EVT_BUTTON event for ShortcutEditor when the user restores the original shortcuts.

Parameters:event – an instance of wx.CommandEvent.



OnSetFilter(event=None)[source]

Handles the wx.EVT_TEXT event for ShortcutEditor.

Parameters:event – if not None, an instance of wx.KeyEvent.


PreShow()[source]

Does some more common initialization before showing ShortcutEditor.



SetColumnWidths()[source]

Sets the ListShortcut columns widths to acceptable and eye-pleasing numbers (in pixels).



SetHTMLHelpFile(htmlFile)[source]

Sets a new HTML help file (a valid html file) to be loaded when the user seeks for an explanation on how the UI works.

Parameters:htmlFile (string) – a valid HTML file.


Show(show=True)[source]

Hides or shows the ShortcutEditor dialog.

The preferred way of dismissing a modal dialog is to use EndModal.

Parameters:show (bool) – if True, the dialog box is shown and brought to the front, otherwise the box is hidden. If False and the dialog is modal, control is returned to the calling program.

Note

Reimplemented from wx.Window.



ShowModal()[source]

Shows the ShortcutEditor dialog in an application-modal way.

Program flow does not return until the dialog has been dismissed with EndModal.

Returns:The value set with SetReturnCode.

Note

Notice that it is possible to call ShowModal for a dialog which had been previously shown with Show, this allows to make an existing modeless dialog modal. However ShowModal can’t be called twice without intervening EndModal calls.

Note

Note that this function creates a temporary event loop which takes precedence over the application’s main event loop (see wx.EventLoopBase) and which is destroyed when the dialog is dismissed. This also results in a call to wx.App.ProcessPendingEvents().



ToAcceleratorTable(window)[source]

Dumps the entire shortcut hierarchy (for shortcuts associated with a wx.AcceleratorTable), into a wx.AcceleratorTable. This method does rebuild the wx.AcceleratorTable and sets it back to the input window.

Parameters:window – an instance of wx.Window, to which the new wx.AcceleratorTable should be set.



ToMenuBar(topWindow)[source]

Dumps the entire shortcut hierarchy (for shortcuts associated with a wx.MenuItem), into a wx.MenuBar, changing only the wx.Menu / wx.MenuItem labels (it does not rebuild the wx.MenuBar).

Parameters:topWindow – an instance of wx.TopLevelWindow, containing the wx.MenuBar we wish to repopulate.

Tree

Table Of Contents

Previous topic

Shortcut

Next topic

ShortcutEvent