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.
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 |
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:
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__
(self, parent)¶Default class constructor.
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
.
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
.
topWindow – an instance of TopLevelWindow
, containing the wx.MenuBar
we wish to scan.
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.
event – an instance of CommandEvent
.
OnHTMLHelp
(self, event)¶Handles the wx.EVT_BUTTON
event for ShortcutEditor
when the user presses the Help
button.
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.
event – an instance of CommandEvent
.
OnSetFilter
(self, event=None)¶Handles the wx.EVT_TEXT
event for ShortcutEditor
.
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.
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
.
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
.
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.
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
).
topWindow – an instance of TopLevelWindow
, containing the wx.MenuBar
we wish to repopulate.