mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #962 from Textualize/binding-tuple-fix
Fix bindings as tuples
This commit is contained in:
@@ -45,27 +45,28 @@ class Bindings:
|
|||||||
def __init__(self, bindings: Iterable[BindingType] | None = None) -> None:
|
def __init__(self, bindings: Iterable[BindingType] | None = None) -> None:
|
||||||
def make_bindings(bindings: Iterable[BindingType]) -> Iterable[Binding]:
|
def make_bindings(bindings: Iterable[BindingType]) -> Iterable[Binding]:
|
||||||
for binding in bindings:
|
for binding in bindings:
|
||||||
if isinstance(binding, Binding):
|
# If it's a tuple of length 3, convert into a Binding first
|
||||||
binding_keys = binding.key.split(",")
|
if isinstance(binding, tuple):
|
||||||
if len(binding_keys) > 1:
|
|
||||||
for key in binding_keys:
|
|
||||||
new_binding = Binding(
|
|
||||||
key=key,
|
|
||||||
action=binding.action,
|
|
||||||
description=binding.description,
|
|
||||||
show=binding.show,
|
|
||||||
key_display=binding.key_display,
|
|
||||||
universal=binding.universal,
|
|
||||||
)
|
|
||||||
yield new_binding
|
|
||||||
else:
|
|
||||||
yield binding
|
|
||||||
else:
|
|
||||||
if len(binding) != 3:
|
if len(binding) != 3:
|
||||||
raise BindingError(
|
raise BindingError(
|
||||||
f"BINDINGS must contain a tuple of three strings, not {binding!r}"
|
f"BINDINGS must contain a tuple of three strings, not {binding!r}"
|
||||||
)
|
)
|
||||||
yield Binding(*binding)
|
binding = Binding(*binding)
|
||||||
|
|
||||||
|
binding_keys = binding.key.split(",")
|
||||||
|
if len(binding_keys) > 1:
|
||||||
|
for key in binding_keys:
|
||||||
|
new_binding = Binding(
|
||||||
|
key=key,
|
||||||
|
action=binding.action,
|
||||||
|
description=binding.description,
|
||||||
|
show=binding.show,
|
||||||
|
key_display=binding.key_display,
|
||||||
|
universal=binding.universal,
|
||||||
|
)
|
||||||
|
yield new_binding
|
||||||
|
else:
|
||||||
|
yield binding
|
||||||
|
|
||||||
self.keys: MutableMapping[str, Binding] = (
|
self.keys: MutableMapping[str, Binding] = (
|
||||||
{binding.key: binding for binding in make_bindings(bindings)}
|
{binding.key: binding for binding in make_bindings(bindings)}
|
||||||
|
|||||||
Reference in New Issue
Block a user