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:
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.
Class Hierarchy¶
Control Appearance¶
Known Superclasses¶
Methods Summary¶
Default class constructor. |
|
Binds a few events we will need to process |
|
Creates all the widgets needed to populate the interface, such as buttons, |
|
Lays out the widgets using sizers in a platform-independent way. |
|
Builds the entire shortcut hierarchy starting from a modified version of a |
|
Builds the entire shortcut hierarchy starting from a |
|
Returns the root |
|
Common initialization procedures. |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Does some more common initialization before showing |
|
Sets the |
|
Sets a new HTML help file (a valid html file) to be loaded when the user seeks |
|
Hides or shows the |
|
Shows the |
|
Dumps the entire shortcut hierarchy (for shortcuts associated with a |
|
Dumps the entire shortcut hierarchy (for shortcuts associated with a |
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 editwx.MenuItem
shortcuts or accelerators defined in aAcceleratorTable
.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.
Methods¶
- __init__(self, parent)¶
Default class constructor.
- Parameters:
parent – an instance of
wx.Window
, it can also beNone
.
- 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 thewx.MenuBar
we wish to scan.
- Init(self)¶
Common initialization procedures.
- OnClearFilter(self, event)¶
Handles the
wx.EVT_BUTTON
event forShortcutEditor
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 forShortcutEditor
when the user presses theHelp
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 callSetHTMLHelpFile
with another input HTML file.
- OnRestoreDefaults(self, event)¶
Handles the
wx.EVT_BUTTON
event forShortcutEditor
when the user restores the original shortcuts.- Parameters:
event – an instance of
CommandEvent
.
- OnSetFilter(self, event=None)¶
Handles the
wx.EVT_TEXT
event forShortcutEditor
.- Parameters:
event – if not
None
, an instance ofKeyEvent
.
- 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. IfFalse
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 withShow
, this allows to make an existing modeless dialog modal. HoweverShowModal
can’t be called twice without interveningEndModal
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 toAppConsole.ProcessPendingEvents
().
- ToAcceleratorTable(self, window)¶
Dumps the entire shortcut hierarchy (for shortcuts associated with a
AcceleratorTable
), into aAcceleratorTable
. This method does rebuild theAcceleratorTable
and sets it back to the input window.- Parameters:
window – an instance of
wx.Window
, to which the newAcceleratorTable
should be set.
- ToMenuBar(self, topWindow)¶
Dumps the entire shortcut hierarchy (for shortcuts associated with a
wx.MenuItem
), into awx.MenuBar
, changing only thewx.Menu
/wx.MenuItem
labels (it does not rebuild thewx.MenuBar
).- Parameters:
topWindow – an instance of
TopLevelWindow
, containing thewx.MenuBar
we wish to repopulate.