Skip to content

Commit

Permalink
Rename the binding universal argument to priority
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Dec 14, 2022
1 parent 9cec7bd commit 7c37c9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def __init__(

self._logger = Logger(self._log)

self._bindings.bind("ctrl+c", "quit", show=False, universal=True)
self._bindings.bind("ctrl+c", "quit", show=False, priority=True)
self._refresh_required = False

self.design = DEFAULT_COLORS
Expand Down Expand Up @@ -1729,20 +1729,20 @@ def _binding_chain(self) -> list[tuple[DOMNode, Bindings]]:
]
return namespace_bindings

async def check_bindings(self, key: str, universal: bool = False) -> bool:
async def check_bindings(self, key: str, priority: bool = False) -> bool:
"""Handle a key press.
Args:
key (str): A key
universal (bool): Check universal keys if True, otherwise non-universal keys.
priority (bool): If `True` check from `App` down, otherwise from focused up.
Returns:
bool: True if the key was handled by a binding, otherwise False
"""

for namespace, bindings in self._binding_chain:
binding = bindings.keys.get(key)
if binding is not None and binding.universal == universal:
if binding is not None and binding.priority == priority:
await self.action(binding.action, default_namespace=namespace)
return True
return False
Expand All @@ -1762,7 +1762,7 @@ async def on_event(self, event: events.Event) -> None:
self.mouse_position = Offset(event.x, event.y)
await self.screen._forward_event(event)
elif isinstance(event, events.Key):
if not await self.check_bindings(event.key, universal=True):
if not await self.check_bindings(event.key, priority=True):
forward_target = self.focused or self.screen
await forward_target._forward_event(event)
else:
Expand Down
12 changes: 6 additions & 6 deletions src/textual/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Binding:
"""bool: Show the action in Footer, or False to hide."""
key_display: str | None = None
"""str | None: How the key should be shown in footer."""
universal: bool = False
"""bool: Allow forwarding from app to focused widget."""
priority: bool = False
"""bool: Is this a priority binding, checked form app down to focused widget?"""


@rich.repr.auto
Expand All @@ -60,7 +60,7 @@ def make_bindings(bindings: Iterable[BindingType]) -> Iterable[Binding]:
description=binding.description,
show=binding.show,
key_display=binding.key_display,
universal=binding.universal,
priority=binding.priority,
)
yield new_binding
else:
Expand Down Expand Up @@ -107,7 +107,7 @@ def bind(
description: str = "",
show: bool = True,
key_display: str | None = None,
universal: bool = False,
priority: bool = False,
) -> None:
"""Bind keys to an action.
Expand All @@ -117,7 +117,7 @@ def bind(
description (str, optional): An optional description for the binding.
show (bool, optional): A flag to say if the binding should appear in the footer.
key_display (str | None, optional): Optional string to display in the footer for the key.
universal (bool, optional): Allow forwarding from the app to the focused widget.
priority (bool, optional): Is this a priority binding, checked form app down to focused widget?
"""
all_keys = [key.strip() for key in keys.split(",")]
for key in all_keys:
Expand All @@ -127,7 +127,7 @@ def bind(
description,
show=show,
key_display=key_display,
universal=universal,
priority=priority,
)

def get_key(self, key: str) -> Binding:
Expand Down

0 comments on commit 7c37c9b

Please sign in to comment.