blackmamba.uikit.keyboard¶
Keyboard shortcuts.
Key commands
Key command is kind of global shortcut in Pythonista. They’re visible if you
hold down Cmd
key for example. Black Mamba does use key commands for
shortcuts like toggle comments, etc.
Related functions:
Following example shows how to print Hallo with Cmd H
keyboard shortcut:
from blackmamba.uikit.keyboard import (
register_key_command, UIKeyModifier
)
def hallo():
print('Hallo')
register_key_command(
'h',
UIKeyModifier.COMMAND,
hallo,
'Print Hallo' # Optional discoverability title (hold down Cmd)
)
Key event handlers
Key event handler is kind of local keyboard shortcut. They’re not visible
if you hold down Cmd
key. Designed to be used in custom dialogs.
Related functions:
Following example shows how to close dialog with Cmd .
keyboard shortcut:
from blackmamba.uikit.keyboard import (
register_key_event_handler, UIEventKeyCode, UIKeyModifier,
unregister_key_event_handlers
)
class MyView(ui.View):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def close_me():
self.close()
self._handlers = [
register_key_event_handler(UIEventKeyCode.DOT, close_me, modifier=UIKeyModifier.COMMAND)
]
def will_close(self):
unregister_key_event_handlers(self._handlers)
-
blackmamba.uikit.keyboard.
is_in_hardware_keyboard_mode
() → bool[source]¶ Check if HW keyboard is connected.
Returns: True if HW keyboard is connected.
-
class
blackmamba.uikit.keyboard.
UIKeyModifier
[source]¶ Key modifiers.
Modifiers can be combined like:
UIKeyModifier.COMMAND | UIKeyModifier.SHIFT
NONE
- No modifier key.ALPHA_SHIFT
- CapsLock.SHIFT
- Shift key.CONTROL
- Control key.ALTERNATE
- Option key.COMMAND
- Command key.NUMERIC_PAD
- Key is on a numeric pad.
Note
Camel case constants deprecated in 1.4.4, will be removed in 2.0.0. Use UPPER_CASE variants.
-
class
blackmamba.uikit.keyboard.
UIEventKeyCode
[source]¶ Event key codes.
Not all key codes are listed / included here. Feel free to create pull request with more key codes if you’d like to use them.
RIGHT
- Right arrow key.LEFT
- Left arrow key.DOWN
- Down arrow key.UP
- Up arrow key.ENTER
- Enter / Return key.SPACE
- Space key.BACKSPACE
- Backspace key.ESCAPE
- Escape key.LEFT_SQUARE_BRACKET
- Left square bracket key.DOT
- Dot key.
Note
Camel case constants deprecated in 1.4.4, will be removed in 2.0.0. Use UPPER_CASE variants.
See also
-
class
blackmamba.uikit.keyboard.
UIKeyInput
[source]¶ Enumeration of special key input values.
LEFT_ARROW
- Left arrow key.RIGHT_ARROW
- Right arrow key.UP_ARROW
- Up arrow key.DOWN_ARROW
- Down arrow key.
Note
Camel case constants deprecated in 1.4.4, will be removed in 2.0.0. Use UPPER_CASE variants.
See also
-
blackmamba.uikit.keyboard.
register_key_command
(input: str, modifier_flags: blackmamba.uikit.keyboard.UIKeyModifier, function: typing.Callable[NoneType], title: str = None) → bool[source]¶ Register key command.
Note
There’s no function to unregister key commands.
Parameters: - input – String like
A
or specialUIKeyInput
value - modifier_flags – Modifier flags
- function – Function to call
- title – Discoverability title
Returns: True if key command was registered.
- input – String like
-
blackmamba.uikit.keyboard.
register_key_event_handler
(key_code: blackmamba.uikit.keyboard.UIEventKeyCode, func: typing.Callable[NoneType], *, modifier: blackmamba.uikit.keyboard.UIKeyModifier = <UIKeyModifier.NONE: 0>) → blackmamba.uikit.keyboard.KeyEventHandler[source]¶ Register key event handler.
Usable in dialogs for example. Do not forget to unregister key event handler in
will_close
function of yourui.View
.Parameters: - key_code – Key code
- func – Function to call
- modifier – Modifier flags
Returns: KeyEventHandler
to use inunregister_key_event_handler
.
-
blackmamba.uikit.keyboard.
unregister_key_event_handler
(handler: blackmamba.uikit.keyboard.KeyEventHandler)[source]¶ Unregister key event handler.
It is safe to call this function multiple times with the same handler. Handler is silently ignored if it’s not registered.
Parameters: handler – Key event handler to unregister
-
blackmamba.uikit.keyboard.
unregister_key_event_handlers
(handlers: typing.List[blackmamba.uikit.keyboard.KeyEventHandler])[source]¶ Unregister list of key event handlers.
Convenience function, it just calls
unregister_key_event_handler
for every handler.Parameters: handlers – List of handlers