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,7 +45,14 @@ 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
|
||||||
|
if isinstance(binding, tuple):
|
||||||
|
if len(binding) != 3:
|
||||||
|
raise BindingError(
|
||||||
|
f"BINDINGS must contain a tuple of three strings, not {binding!r}"
|
||||||
|
)
|
||||||
|
binding = Binding(*binding)
|
||||||
|
|
||||||
binding_keys = binding.key.split(",")
|
binding_keys = binding.key.split(",")
|
||||||
if len(binding_keys) > 1:
|
if len(binding_keys) > 1:
|
||||||
for key in binding_keys:
|
for key in binding_keys:
|
||||||
@@ -60,12 +67,6 @@ class Bindings:
|
|||||||
yield new_binding
|
yield new_binding
|
||||||
else:
|
else:
|
||||||
yield binding
|
yield binding
|
||||||
else:
|
|
||||||
if len(binding) != 3:
|
|
||||||
raise BindingError(
|
|
||||||
f"BINDINGS must contain a tuple of three strings, not {binding!r}"
|
|
||||||
)
|
|
||||||
yield Binding(*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