Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple heirarchical program isn't picking up sent messages #3973

Closed
fshriver opened this issue Jan 7, 2024 · 0 comments
Closed

Simple heirarchical program isn't picking up sent messages #3973

fshriver opened this issue Jan 7, 2024 · 0 comments

Comments

@fshriver
Copy link

fshriver commented Jan 7, 2024

Hello,

I'm trying to put together a simple program based on OptionList, however I can't seem to get the parent widget to listen/pick up on messages from child widgets. See below MVE:

from textual.app import App, ComposeResult
from textual.widget import Widget
from textual.widgets import Footer
from textual.widgets import OptionList

class DefaultOptions(Widget):

    def __init__(self) -> None:
        super().__init__()

    def compose(self) -> ComposeResult:
        yield OptionList(
            'Option 1',
            'Option 2'
        )

    def on_option_list_selected(self, event: OptionList.OptionSelected) -> None:
        print('\n\nbark\n\n')


class OptionSelector(App):

    def compose(self) -> ComposeResult:
        yield DefaultOptions()
        yield Footer()

if __name__ == "__main__":
    OptionSelector().run()

In this case, I just need the DefaultOptions widget to "barK' when an option is selected. I've confirmed printing works previously by putting in a print statement in compose() and having it successfully print to the debug console. However, while that worked, and I can see in the debug console that OptionList.OptionSelected event is being sent, on_option_list_selected() is never called as it never prints "bark" to the debug console. Is there something I'm missing or some fundamental problem with this MVE I'm not catching?

Also see below output from the textual console:

[19:10:40] EVENT                                                                                                         message_pump.py:697
Key(key='enter', character='\r', name='enter', is_printable=False, aliases=['enter', 'ctrl+m']) >>> OptionList() method=<Widget.on_key>
[19:10:40] EVENT                                                                                                         message_pump.py:697
Key(key='enter', character='\r', name='enter', is_printable=False, aliases=['enter', 'ctrl+m']) >>> DefaultOptions() method=<Widget.on_key>
[19:10:40] EVENT                                                                                                         message_pump.py:697
Key(key='enter', character='\r', name='enter', is_printable=False, aliases=['enter', 'ctrl+m']) >>> Screen(id='_default') 
method=<Widget.on_key>
[19:10:40] EVENT                                                                                                         message_pump.py:697
Key(key='enter', character='\r', name='enter', is_printable=False, aliases=['enter', 'ctrl+m']) >>> OptionSelector(title='OptionSelector', 
classes={'-dark-mode'}) method=<App.on_key>
[19:10:40] SYSTEM                                                                                                                app.py:2826
<action> namespace=OptionList() action_name='select' params=()
[19:10:40] EVENT                                                                                                         message_pump.py:706
OptionSelected(option_list=OptionList(), option=<textual.widgets._option_list.Option object at 0x7f6f294fe750>, option_id=None, 
option_index=1) >>> OptionList() method=None
[19:10:40] EVENT                                                                                                         message_pump.py:706
OptionSelected(option_list=OptionList(), option=<textual.widgets._option_list.Option object at 0x7f6f294fe750>, option_id=None, 
option_index=1) >>> DefaultOptions() method=None
[19:10:40] EVENT                                                                                                         message_pump.py:706
OptionSelected(option_list=OptionList(), option=<textual.widgets._option_list.Option object at 0x7f6f294fe750>, option_id=None, 
option_index=1) >>> Screen(id='_default') method=None
[19:10:40] EVENT                                                                                                         message_pump.py:706
OptionSelected(option_list=OptionList(), option=<textual.widgets._option_list.Option object at 0x7f6f294fe750>, option_id=None, 
option_index=1) >>> OptionSelector(title='OptionSelector', classes={'-dark-mode'}) method=None
@Textualize Textualize deleted a comment from github-actions bot Jan 7, 2024
@Textualize Textualize locked and limited conversation to collaborators Jan 7, 2024
@davep davep converted this issue into discussion #3974 Jan 7, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant