mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Rename the binding universal argument to priority
As per https://github.com/Textualize/textual/issues/1343#issuecomment-1351087237
This commit is contained in:
@@ -298,7 +298,7 @@ class App(Generic[ReturnType], DOMNode):
|
||||
|
||||
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
|
||||
@@ -1729,12 +1729,12 @@ class App(Generic[ReturnType], DOMNode):
|
||||
]
|
||||
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
|
||||
@@ -1742,7 +1742,7 @@ class App(Generic[ReturnType], DOMNode):
|
||||
|
||||
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
|
||||
@@ -1762,7 +1762,7 @@ class App(Generic[ReturnType], DOMNode):
|
||||
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:
|
||||
|
||||
@@ -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
|
||||
@@ -60,7 +60,7 @@ class Bindings:
|
||||
description=binding.description,
|
||||
show=binding.show,
|
||||
key_display=binding.key_display,
|
||||
universal=binding.universal,
|
||||
priority=binding.priority,
|
||||
)
|
||||
yield new_binding
|
||||
else:
|
||||
@@ -107,7 +107,7 @@ class Bindings:
|
||||
description: str = "",
|
||||
show: bool = True,
|
||||
key_display: str | None = None,
|
||||
universal: bool = False,
|
||||
priority: bool = False,
|
||||
) -> None:
|
||||
"""Bind keys to an action.
|
||||
|
||||
@@ -117,7 +117,7 @@ class Bindings:
|
||||
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:
|
||||
@@ -127,7 +127,7 @@ class Bindings:
|
||||
description,
|
||||
show=show,
|
||||
key_display=key_display,
|
||||
universal=universal,
|
||||
priority=priority,
|
||||
)
|
||||
|
||||
def get_key(self, key: str) -> Binding:
|
||||
|
||||
Reference in New Issue
Block a user