eye.helpers.keys module

Shortcut keys file format

The format is based on INI format (parsed by configparser). The file describes shortcuts for triggering actions or slots of objects belonging to categories (see eye.connector module for a description of categories).

The config file should contain sections, each section describing a category (named like the section). Within a section, each key is an action name, and the value is the description of the shortcut triggering the action.

Shortcut description

The shortcut description should be in a string format accepted by QKeySequence. Examples:

  • Ctrl+S: a simple keyboard shortcut where the S key is pressed while the Control key is held

  • Alt+Up: another shortcut where the up arrow key is pressed while Alt is held

  • Ctrl+G,B: a more complex shortcut, where G should be pressed while Ctrl is held, then B is pressed with no other key held

Optionally, the shortcut description can be prefixed to describe the context in which the shortcut is accepted:

  • widget: (the default): the shortcut is only recognized when the widget has focus

  • children:: the shortcut is recognized if the widget or a children widget has focus

  • window:: the shortcut is recognized when the window has focus

  • application:: the shortcut is recognized when the app has focus

File example

Here’s an example of a suitable keyboard.ini (see DEFAULT_KEYS_FILE):

# this is a comment

[editor]
# when Ctrl+S is pressed while a widget with "editor" category has focus,
# the saveFile slot of the editor is triggered
save_file = Ctrl+S

[location_list]
# when Ctrl+P is pressed in the same window as a widget with the "location_list" widget,
# the activateNext slot of the location_list is triggered
activate_next = window:Ctrl+P
activate_previous = window:Ctrl+Shift+P

[window]
# when Ctrl+N is pressed in any child or grandchild of a widget with "window" category,
# the bufferNew slot of the window is triggered
buffer_new = children:Ctrl+N
buffer_close = children:Ctrl+W

Module contents

eye.helpers.keys.DEFAULT_KEYS_FILE = 'keyboard.ini'

Default filename used by loadKeysConfig.

eye.helpers.keys.load_keys_config(path=None)[source]

Load keys config file.

If path is None, a file named DEFAULT_KEYS_FILE will be looked for in the config directory.

Parameters:

path – path of the keyboard configuration file