| 1 |
from typing import TYPE_CHECKING, Optional |
| 2 |
|
| 3 |
from qtpy.QtWidgets import QKeySequenceEdit |
| 4 |
|
| 5 |
from ._qkeymap import qkeysequence2modelkeybinding |
| 6 |
|
| 7 |
if TYPE_CHECKING: |
| 8 |
from app_model.types import KeyBinding |
| 9 |
|
| 10 |
|
| 11 |
class QModelKeyBindingEdit(QKeySequenceEdit): |
| 12 |
"""Editor for a KeyBinding instance. |
| 13 |
|
| 14 |
This is a QKeySequenceEdit with a method that converts the current |
| 15 |
keySequence to an app_model KeyBinding instance. |
| 16 |
""" |
| 17 |
|
| 18 |
def keyBinding(self) -> Optional["KeyBinding"]: |
| 19 |
"""Return app_model KeyBinding instance for the current keySequence.""" |
| 20 |
if self.keySequence().isEmpty(): |
| 21 |
return None |
| 22 |
return qkeysequence2modelkeybinding(self.keySequence()) |