# wx.lib.agw.shortcuteditor.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 AcceleratorTable.

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

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

## Class Hierarchy¶

Inheritance diagram for class ShortcutEditor:

wxMSW

wxMAC

wxGTK

## Known Superclasses¶

wx.Dialog

## Methods Summary¶

 __init__ Default class constructor. BindEvents Binds a few events we will need to process CreateWidgets Creates all the widgets needed to populate the interface, such as buttons, DoLayout Lays out the widgets using sizers in a platform-independent way. FromAcceleratorTable Builds the entire shortcut hierarchy starting from a modified version of a AcceleratorTable. FromMenuBar Builds the entire shortcut hierarchy starting from a wx.MenuBar. GetShortcutManager Returns the root Shortcut containing the whole shortcut hierarchy. Init Common initialization procedures. OnClearFilter Handles the wx.EVT_BUTTON event for ShortcutEditor when the user clears the OnHTMLHelp Handles the wx.EVT_BUTTON event for ShortcutEditor when the user presses the Help OnRestoreDefaults Handles the wx.EVT_BUTTON event for ShortcutEditor when the user restores the OnSetFilter Handles the wx.EVT_TEXT event for ShortcutEditor. PreShow Does some more common initialization before showing ShortcutEditor. SetColumnWidths Sets the ListShortcut columns widths to acceptable and eye-pleasing SetHTMLHelpFile Sets a new HTML help file (a valid html file) to be loaded when the user seeks Show Hides or shows the ShortcutEditor dialog. ShowModal Shows the ShortcutEditor dialog in an application-modal way. ToAcceleratorTable Dumps the entire shortcut hierarchy (for shortcuts associated with a AcceleratorTable), into ToMenuBar Dumps the entire shortcut hierarchy (for shortcuts associated with a wx.MenuItem), into

## Class API¶

class ShortcutEditor(wx.Dialog)

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 AcceleratorTable.

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

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

### Methods¶

__init__(self, parent)

Default class constructor.

Parameters

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

BindEvents(self)

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(self)

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

DoLayout(self)

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

FromAcceleratorTable(self, accelTable)

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

Parameters

accelTable

a modified version of 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(self, topWindow)

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

Parameters

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

GetShortcutManager(self)

Returns the root Shortcut containing the whole shortcut hierarchy.

Init(self)

Common initialization procedures.

OnClearFilter(self, event)

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 CommandEvent.

OnHTMLHelp(self, event)

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

Parameters

event – an instance of CommandEvent.

Note

By default, this method launches a 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(self, event)

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

Parameters

event – an instance of CommandEvent.

OnSetFilter(self, event=None)

Handles the wx.EVT_TEXT event for ShortcutEditor.

Parameters

event – if not None, an instance of KeyEvent.

PreShow(self)

Does some more common initialization before showing ShortcutEditor.

SetColumnWidths(self)

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

SetHTMLHelpFile(self, htmlFile)

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(self, show=True)

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(self)

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 EventLoopBase) and which is destroyed when the dialog is dismissed. This also results in a call to AppConsole.ProcessPendingEvents ().

ToAcceleratorTable(self, window)

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

Parameters

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

ToMenuBar(self, topWindow)

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 TopLevelWindow, containing the wx.MenuBar we wish to repopulate.