types #
App-model types.
Action #
Bases: CommandRule, Generic[P, R]
An Action is a callable object with menu placement, keybindings, and metadata.
This is the "complete" representation of a command. Including a pointer to the
actual callable object, as well as any additional menu and keybinding rules.
Most commands and menu items will be represented by Actions, and registered using
register_action.
CommandRule #
Bases: _BaseModel
Data representing a command and its presentation.
Presentation of contributed commands depends on the containing menu. The Command Palette, for instance, prefixes commands with their category, allowing for easy grouping. However, the Command Palette doesn't show icons nor disabled commands. Menus, on the other hand, shows disabled items as grayed out, but don't show the category label.
Icon #
Bases: _BaseModel
Icons used to represent commands, or submenus.
May provide both a light and dark variant. If only one is provided, it is used in all theme types.
KeyBinding #
KeyBinding(*, parts: list[SimpleKeyBinding])
KeyBinding. May be a multi-part "Chord" (e.g. 'Ctrl+K Ctrl+C').
This is the primary representation of a fully resolved keybinding. For consistency
in the downstream API, it should be preferred to
SimpleKeyBinding, even
when there is only a single part in the keybinding (i.e. when it is not a chord.)
Chords (two separate keypress actions) are expressed as a string by separating the two keypress codes with a space. For example, 'Ctrl+K Ctrl+C'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts |
List[SimpleKeyBinding]
|
The parts of the keybinding. There must be at least one part. |
required |
Source code in src/app_model/types/_keys/_keybindings.py
194 195 | |
part0
property
#
part0: SimpleKeyBinding
Return the first part of this keybinding.
All keybindings have at least one part.
from_int
classmethod
#
from_int(key_int: int, os: OperatingSystem | None = None) -> KeyBinding
Create a KeyBinding from an integer.
Source code in src/app_model/types/_keys/_keybindings.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
from_str
classmethod
#
from_str(key_str: str) -> KeyBinding
Parse a string into a SimpleKeyBinding.
Source code in src/app_model/types/_keys/_keybindings.py
220 221 222 223 224 | |
to_int #
to_int(os: OperatingSystem | None = None) -> int
Convert this KeyBinding to an integer representation.
Source code in src/app_model/types/_keys/_keybindings.py
243 244 245 246 247 248 249 250 251 252 253 | |
to_text #
to_text(os: OperatingSystem | None = None, use_symbols: bool = False, joinchar: str = '+') -> str
Get a text representation of this KeyBinding.
Optionally, the string representation can be constructed with symbols
like ↵ for Enter or OS specific ones like ⌘ for Meta on MacOS. If no symbols
should be used, the string representation will use the OS specific names
for the keys like Cmd for Meta or Option for Ctrl on MacOS.
Also, a join character can be defined. By default + is used.
Source code in src/app_model/types/_keys/_keybindings.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
validate
classmethod
#
validate(v: Any) -> KeyBinding
Validate a SimpleKeyBinding.
Source code in src/app_model/types/_keys/_keybindings.py
291 292 293 294 295 296 297 298 299 300 301 302 | |
KeyBindingRule #
Bases: _BaseModel
Data representing a keybinding and when it should be active.
This model lacks a corresponding command. That gets linked up elsewhere,
such as below in Action.
Values can be expressed as either a string (e.g. "Ctrl+O") or an integer, using
combinations of KeyMod and
KeyCode, (e.g. KeyMod.CtrlCmd | KeyCode.KeyO).
KeyChord #
KeyChord(first_part: int, second_part: int)
Bases: int
KeyChord is an integer combination of two key combos.
It could be two KeyCombo
KeyCode, or int.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first_part |
KeyCombo | int
|
The first part of the chord. |
required |
second_part |
KeyCombo | int
|
The second part of the chord. |
required |
Source code in src/app_model/types/_keys/_key_codes.py
801 802 803 | |
KeyCode #
Bases: IntEnum
Virtual Key Codes, the integer value does not hold any inherent meaning.
This is the primary internal representation of a key.
from_event_code
classmethod
#
from_event_code(event_code: int) -> KeyCode
Return the KeyCode associated with the given event code.
Returns KeyCode.UNKNOWN if no KeyCode is associated with the event code.
Source code in src/app_model/types/_keys/_key_codes.py
194 195 196 197 198 199 200 | |
from_string
classmethod
#
from_string(string: str) -> KeyCode
Return the KeyCode associated with the given string.
Returns KeyCode.UNKNOWN if no KeyCode is associated with the string.
Source code in src/app_model/types/_keys/_key_codes.py
186 187 188 189 190 191 192 | |
os_name #
os_name(os: Optional[OperatingSystem] = None) -> str
Get a string representation of this KeyCode using the OS specific naming for the key.
This differs from __str__ since with it a normalized representation (constant to all OSes) is given.
Sometimes these representations coincide but not always! Some examples:
* KeyCode.Enter is represented by Enter (__str__ represents it as Enter)
* KeyCode.Meta is represented by Win on Windows, Super on Linux and Cmd on MacOS
(__str__ represents it as Meta)
If no OS is given, the current detected one is used.
Source code in src/app_model/types/_keys/_key_codes.py
172 173 174 175 176 177 178 179 180 181 182 183 184 | |
os_symbol #
os_symbol(os: Optional[OperatingSystem] = None) -> str
Get a string representation of this KeyCode using a symbol/OS specific symbol.
Some examples:
* KeyCode.Enter is represented by ↵
* KeyCode.Meta is represented by ⊞ on Windows, Super on Linux and ⌘ on MacOS
If no OS is given, the current detected one is used.
Source code in src/app_model/types/_keys/_key_codes.py
160 161 162 163 164 165 166 167 168 169 170 | |
KeyCombo #
KeyCombo(modifiers: KeyMod, key: KeyCode = KeyCode.UNKNOWN)
MenuItem #
Bases: MenuItemBase
Combination of a Command and conditions for menu presentation.
This object is mostly constructed by register_action right before menu item
registration.
MenuItemBase #
Bases: _BaseModel
Data representing where and when a menu item should be shown.
MenuRule #
Bases: MenuItemBase
A MenuRule defines a menu location and conditions for presentation.
It does not define an actual command. That is done in either MenuItem or Action.
OperatingSystem #
Bases: Enum
Operating system enum.
current
staticmethod
#
current() -> OperatingSystem
Return the current operating system as enum.
Source code in src/app_model/types/_constants.py
22 23 24 25 | |
ScanCode #
Bases: IntEnum
Scan codes for the keyboard.
https://en.wikipedia.org/wiki/Scancode
These are the scan codes required to conform to the W3C specification for KeyboardEvent.code
A scan code is a hardware-specific code that is generated by the keyboard when a key is pressed or released. It represents the physical location of a key on the keyboard and is unique to each key. A key code, on the other hand, is a higher-level representation of a keypress or key release event. They are associated with characters, functions, or actions rather than hardware locations. As an example, the left and right control keys have the same key code (KeyCode.Ctrl) but different scan codes (LeftControl and RightControl).
https://w3c.github.io/uievents-code/
commented out lines represent keys that are optional and may be used by implementations to support special keyboards (such as multimedia or legacy keyboards).
from_string
classmethod
#
from_string(string: str) -> ScanCode
Return the KeyCode associated with the given string.
Returns ScanCode.UNIDENTIFIED if no match is found.
Source code in src/app_model/types/_keys/_key_codes.py
441 442 443 444 445 446 447 | |
SimpleKeyBinding #
Bases: BaseModel
Represent a simple combination modifier(s) and a key, e.g. Ctrl+A.
from_int
classmethod
#
from_int(key_int: int, os: OperatingSystem | None = None) -> SimpleKeyBinding
Create a SimpleKeyBinding from an integer.
Source code in src/app_model/types/_keys/_keybindings.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
from_str
classmethod
#
from_str(key_str: str) -> SimpleKeyBinding
Parse a string into a SimpleKeyBinding.
Source code in src/app_model/types/_keys/_keybindings.py
72 73 74 75 76 77 | |
is_modifier_key #
is_modifier_key() -> bool
Return true if this is a modifier key.
Source code in src/app_model/types/_keys/_keybindings.py
29 30 31 32 33 34 35 36 37 | |
to_int #
to_int(os: OperatingSystem | None = None) -> int
Convert this SimpleKeyBinding to an integer representation.
Source code in src/app_model/types/_keys/_keybindings.py
102 103 104 105 106 107 108 109 110 111 112 113 114 | |
to_text #
to_text(os: OperatingSystem | None = None, use_symbols: bool = False, joinchar: str = '+') -> str
Get a user-facing string representation of this SimpleKeyBinding.
Optionally, the string representation can be constructed with symbols
like ↵ for Enter or OS specific ones like ⌘ for Meta on MacOS. If no symbols
should be used, the string representation will use the OS specific names
for the keys like Cmd for Meta or Option for Ctrl on MacOS.
Also, a join character can be defined. By default + is used.
Source code in src/app_model/types/_keys/_keybindings.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
StandardKeyBinding #
Bases: Enum
to_keybinding_rule #
to_keybinding_rule() -> KeyBindingRule
Return KeyBindingRule for this StandardKeyBinding.
Source code in src/app_model/types/_keys/_standard_bindings.py
78 79 80 81 82 | |
SubmenuItem #
ToggleRule #
Bases: _BaseModel
More detailed description of a toggle rule.