KKeySequenceWidget Class Reference
from PyKDE4.kdeui import *
Detailed Description
A widget to input a QKeySequence.
This widget lets the user choose a QKeySequence, which is usually used as a shortcut key. The recording is initiated by calling captureKeySequence() or the user clicking into the widget.
The widgets provides support for conflict handling. See setCheckForConflictsAgainst() for more information.
"KDE Key Sequence Widget"
- Internal:
Signal Documentation
keySequenceChanged | ( | QKeySequence | seq | |
) |
This signal is emitted when the current key sequence has changed, be it by user input or programmatically.
- Signal syntax:
QObject.connect(source, SIGNAL("keySequenceChanged(const QKeySequence&)"), target_slot)
stealShortcut | ( | QKeySequence | seq, | |
KAction | action | |||
) |
This signal is emitted after the user agreed to steal a shortcut from an action. This is only done for local shortcuts. So you can be sure \a action is one of the actions you provided with setCheckActionList() or setCheckActionCollections().
If you listen to that signal and don't call applyStealShortcut() you are supposed to steal the shortcut and save this change.
- Signal syntax:
QObject.connect(source, SIGNAL("stealShortcut(const QKeySequence&, KAction*)"), target_slot)
Method Documentation
__init__ | ( | self, | ||
QWidget | parent=0 | |||
) |
Constructor.
__init__ | ( | self, | ||
KKeySequenceWidget | a0 | |||
) |
applyStealShortcut | ( | self ) |
Actually remove the shortcut that the user wanted to steal, from the action that was using it. This only applies to actions provided to us by setCheckActionCollections() and setCheckActionList().
Global and Standard Shortcuts have to be stolen immediately when the user gives his consent (technical reasons). That means those changes will be active even if you never call applyStealShortcut().
To be called before you apply your changes. No local shortcuts are stolen until this function is called.
captureKeySequence | ( | self ) |
Capture a shortcut from the keyboard. This call will only return once a key sequence has been captured or input was aborted. If a key sequence was input, keySequenceChanged() will be emitted.
- See also:
- setModifierlessAllowed()
KKeySequenceWidget.ShortcutTypes checkForConflictsAgainst | ( | self ) |
The shortcut types we check for conflicts.
- See also:
- setCheckForConflictsAgainst()
- Since:
- 4.2
clearKeySequence | ( | self ) |
Clear the key sequence.
bool isKeySequenceAvailable | ( | self, | ||
QKeySequence | seq | |||
) |
Checks whether the key sequence seq is available to grab.
The sequence is checked under the same rules as if it has been typed by the user. This method is useful if you get key sequences from another input source and want to check if it is save to set them.
- Since:
- 4.2
bool isModifierlessAllowed | ( | self ) |
- See also:
- setModifierlessAllowed()
QKeySequence keySequence | ( | self ) |
Return the currently selected key sequence.
bool multiKeyShortcutsAllowed | ( | self ) |
setCheckActionCollections | ( | self, | ||
[KActionCollection] | actionCollections | |||
) |
Set a list of action collections to check against for conflictuous shortcut.
- See also:
- setCheckForConflictsAgainst()
If a KAction with a conflicting shortcut is found inside this list and its shortcut can be configured (KAction.isShortcutConfigurable() returns true) the user will be prompted whether to steal the shortcut from this action.
- Since:
- 4.1
setCheckActionList | ( | self, | ||
[QAction] | checkList | |||
) |
- Deprecated:
- since 4.1 use setCheckActionCollections so that KKeySequenceWidget knows in which action collection to call the writeSettings method after stealing a shortcut from an action.
setCheckForConflictsAgainst | ( | self, | ||
KKeySequenceWidget.ShortcutTypes | types | |||
) |
Configure if the widget should check for conflicts with existing shortcuts.
When capturing a key sequence for local shortcuts you should check against GlobalShortcuts and your other local shortcuts. This is the default.
You have to provide the local actions to check against with setCheckActionCollections().
When capturing a key sequence for a global shortcut you should check against StandardShortcuts, GlobalShortcuts and your local shortcuts.
There are two ways to react to a user agreeing to steal a shortcut:
1. Listen to the stealShortcut() signal and steal the shortcuts manually. It's your responsibility to save that change later when you think it is appropriate.
2. Call applyStealShortcut and KKeySequenceWidget will steal the shortcut. This will save the actionCollections the shortcut is part of so make sure it doesn't inadvertly save some unwanted changes too. Read its documentation for some limitation when handling global shortcuts.
If you want to do the conflict checking yourself here are some code snippets for global ...
QStringList conflicting = KGlobalAccel.findActionNameSystemwide(keySequence); if (!conflicting.isEmpty()) { // Inform and ask the user about the conflict and reassigning // the keys sequence if (!KGlobalAccel.promptStealShortcutSystemwide(q, conflicting, keySequence)) { return true; } KGlobalAccel.stealShortcutSystemwide(keySequence); }
... and standard shortcuts
KStandardShortcut.StandardShortcut ssc = KStandardShortcut.find(keySequence); if (ssc != KStandardShortcut.AccelNone) { // We have a conflict }
- Since:
- 4.2
setClearButtonShown | ( | self, | ||
bool | show | |||
) |
Set whether a small button to set an empty key sequence should be displayed next to the main input widget. The default is to show the clear button.
setComponentName | ( | self, | ||
QString | componentName | |||
) |
If the component using this widget supports shortcuts contexts, it has to set its component name so we can check conflicts correctly.
setKeySequence | ( | self, | ||
QKeySequence | seq, | |||
KKeySequenceWidget.Validation | val=KKeySequenceWidget.NoValidate | |||
) |
Set the key sequence.
If val == Validate, and the call is actually changing the key sequence, conflictuous shortcut will be checked.
setModifierlessAllowed | ( | self, | ||
bool | allow | |||
) |
This only applies to user input, not to setShortcut(). Set whether to accept "plain" keys without modifiers (like Ctrl, Alt, Meta). Plain keys by our definition include letter and symbol keys and text editing keys (Return, Space, Tab, Backspace, Delete). "Special" keys like F1, Cursor keys, Insert, PageDown will always work.
setMultiKeyShortcutsAllowed | ( | self, | ||
bool | a0 | |||
) |
Allow multikey shortcuts?
Enumeration Documentation
ShortcutType |
Configuration
Configuration options for the widget.
- Enumerator:
-
None = 0x00 LocalShortcuts = 0x01 StandardShortcuts = 0x02 GlobalShortcuts = 0x03
Validation |
- Enumerator:
-
Validate = 0 NoValidate = 1