-
Executing this demo https://textual.textualize.io/guide/events/#custom-messages yields the following trace. I was wondering if this is only happening locally for me? ╭──────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────╮
│ /Users/nporcino/dev/mastermind/./mm.py:879 in on_click │
│ │
│ 876 │ │
│ 877 │ def on_click(self) -> None: │
│ 878 │ │ # The post_message method sends an event to be handled in the DOM │
│ ❱ 879 │ │ self.post_message(self.Selected(self.color)) │
│ 880 │ │
│ 881 │ def render(self) -> str: │
│ 882 │ │ return str(self.color) │
│ │
│ ╭──────────────────── locals ────────────────────╮ │
│ │ self = ColorButton(pseudo_classes={'enabled'}) │ │
│ ╰────────────────────────────────────────────────╯ │
│ │
│ /Users/nporcino/miniforge3/envs/jira-py310/lib/python3.10/site-packages/textual/widget.py:2818 in │
│ post_message │
│ │
│ 2815 │ │ │ │ self.log.warning(self, f"IS NOT RUNNING, {message!r} not sent") │
│ 2816 │ │ │ except NoActiveAppError: │
│ 2817 │ │ │ │ pass │
│ ❱ 2818 │ │ return super().post_message(message) │
│ 2819 │ │
│ 2820 │ async def _on_idle(self, event: events.Idle) -> None: │
│ 2821 │ │ """Called when there are no more events on the queue. │
│ │
│ ╭───────────────────── locals ──────────────────────╮ │
│ │ message = Selected(pseudo_classes={'enabled'}) │ │
│ │ self = ColorButton(pseudo_classes={'enabled'}) │ │
│ ╰───────────────────────────────────────────────────╯ │
│ │
│ /Users/nporcino/miniforge3/envs/jira-py310/lib/python3.10/site-packages/textual/message_pump.py:632 in │
│ post_message │
│ │
│ 629 │ │ │ return False │
│ 630 │ │ # Add a copy of the prevented message types to the message │
│ 631 │ │ # This is so that prevented messages are honoured by the event's handler │
│ ❱ 632 │ │ message._prevent.update(self._get_prevented_messages()) │
│ 633 │ │ if self._thread_id != threading.get_ident() and self.app._loop is not None: │
│ 634 │ │ │ # If we're not calling from the same thread, make it threadsafe │
│ 635 │ │ │ loop = self.app._loop │
│ │
│ ╭───────────────────── locals ──────────────────────╮ │
│ │ message = Selected(pseudo_classes={'enabled'}) │ │
│ │ self = ColorButton(pseudo_classes={'enabled'}) │ │
│ ╰───────────────────────────────────────────────────╯ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'Selected' object has no attribute '_prevent' |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
There's 3 example bodies of code in the page you point to and it's not obvious to me which one you have in mind -- the trace you post above doesn't seem to match any of the examples either (the line near the top seems to be from I can run each of the example on that page just fine. Could you confirm exactly what it is you're running and how, and also the version of Textual you're using. Posting the output of |
Beta Was this translation helpful? Give feedback.
-
It was indeed my fault. I had put the custom01.py sample in the same file as a larger app, and it seems there was an interaction I didn't understand with one of my own classes. If I run exactly the sample, it works for me, I think I was getting a bit over-confident in my understanding of the framework. I apologize for not doing the obvious basic test. I appreciate the team's patience, my app is otherwise functioning very nicely thanks to the quick responses you've given me in my other questions. |
Beta Was this translation helpful? Give feedback.
It was indeed my fault. I had put the custom01.py sample in the same file as a larger app, and it seems there was an interaction I didn't understand with one of my own classes. If I run exactly the sample, it works for me, I think I was getting a bit over-confident in my understanding of the framework. I apologize for not doing the obvious basic test.
I appreciate the team's patience, my app is otherwise functioning very nicely thanks to the quick responses you've given me in my other questions.