Posts a message on to this widget's queue. Args: message: A message (including Event). Returns: `True` if the message was queued for processing, otherwise `False`.
(self, message: Message)
| 858 | return self.post_message(message) |
| 859 | |
| 860 | def post_message(self, message: Message) -> bool: |
| 861 | """Posts a message on to this widget's queue. |
| 862 | |
| 863 | Args: |
| 864 | message: A message (including Event). |
| 865 | |
| 866 | Returns: |
| 867 | `True` if the message was queued for processing, otherwise `False`. |
| 868 | """ |
| 869 | _rich_traceback_omit = True |
| 870 | if not hasattr(message, "_prevent"): |
| 871 | # Catch a common error (forgetting to call super) |
| 872 | raise RuntimeError( |
| 873 | "Message is missing attributes; did you forget to call super().__init__() ?" |
| 874 | ) |
| 875 | if self._closing or self._closed: |
| 876 | return False |
| 877 | if not self.check_message_enabled(message): |
| 878 | return False |
| 879 | # Add a copy of the prevented message types to the message |
| 880 | # This is so that prevented messages are honoured by the event's handler |
| 881 | message._prevent.update(self._get_prevented_messages()) |
| 882 | if self._thread_id != threading.get_ident() and self.app._loop is not None: |
| 883 | # If we're not calling from the same thread, make it threadsafe |
| 884 | loop = self.app._loop |
| 885 | loop.call_soon_threadsafe(self._message_queue.put_nowait, message) |
| 886 | else: |
| 887 | self._message_queue.put_nowait(message) |
| 888 | return True |
| 889 | |
| 890 | async def on_callback(self, event: events.Callback) -> None: |
| 891 | if self.app._closing: |
no test coverage detected