MCPcopy
hub / github.com/Textualize/textual / prevent

Method prevent

src/textual/message_pump.py:199–217  ·  view source on GitHub ↗

A context manager to *temporarily* prevent the given message types from being posted. Example: ```python input = self.query_one(Input) with self.prevent(Input.Changed): input.value = "foo" ```

(self, *message_types: type[Message])

Source from the content-addressed store, hash-verified

197
198 @contextmanager
199 def prevent(self, *message_types: type[Message]) -> Generator[None, None, None]:
200 """A context manager to *temporarily* prevent the given message types from being posted.
201
202 Example:
203 ```python
204 input = self.query_one(Input)
205 with self.prevent(Input.Changed):
206 input.value = "foo"
207 ```
208 """
209 if message_types:
210 prevent_stack = self._prevent_message_types_stack
211 prevent_stack.append(prevent_stack[-1].union(message_types))
212 try:
213 yield
214 finally:
215 prevent_stack.pop()
216 else:
217 yield
218
219 @property
220 def task(self) -> Task:

Callers 15

_pre_processMethod · 0.95
_flush_next_callbacksMethod · 0.95
_dispatch_messageMethod · 0.95
_check_watchersMethod · 0.80
_select_commandMethod · 0.80
_on_mountMethod · 0.80
__init__Method · 0.80
_apply_to_allMethod · 0.80
_watch_activeMethod · 0.80
_on_tabs_tab_disabledMethod · 0.80

Calls 3

unionMethod · 0.80
popMethod · 0.80
appendMethod · 0.45

Tested by 2

test_preventFunction · 0.64