Skip to content
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

SelectionList crashes on content overflow or resize #2969

Closed
zdovcj opened this issue Jul 18, 2023 · 5 comments · Fixed by #2970
Closed

SelectionList crashes on content overflow or resize #2969

zdovcj opened this issue Jul 18, 2023 · 5 comments · Fixed by #2970
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@zdovcj
Copy link

zdovcj commented Jul 18, 2023

When using SelectionList and resizing the terminal so that the text cannot fit in the screen, the program will crash. I think it also works with OptionList.

Environment:
Textual version: 0.30.0
Python version: 3.10.8

Code to reproduce:

import textual.widgets
import textual.app

class App(textual.app.App):

    def compose(self):
        yield textual.widgets.SelectionList (('random_text' * 10, 0), id='id')

if __name__ == '__main__':
    App().run()

The last error printed is:

                                                                                                             
│ /opt/homebrew/lib/python3.10/site-packages/textual/widgets/_option_list.py:749 in get_option_at_index       
│                                                                                                             
│   746 │   │   try:                                                                                          
│   747 │   │   │   return self._options[index]                                                               
│   748 │   │   except IndexError:                                                                            
│ ❱ 749 │   │   │   raise OptionDoesNotExist(                                                                 
│   750 │   │   │   │   f"There is no option with an index of {index}"                                        
│   751 │   │   │   ) from None                                                                               
│   752                                                                                                       
│                                                                                                             
│ ╭──────────── locals ────────────╮                                                                          
│ │ index = 1                      │                                                                          
│ │  self = SelectionList(id='id') │                                                                          
│ ╰────────────────────────────────╯                                                                          
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────

I have tried to size my content upon resize event, but it doesn't solve the issue. In this case, it will even crash on increasing the terminal size. I assume that the function that sets the content length might be called before the the code that crashes.

Code to reproduce the crash upon increasing:

import textual.widgets
import textual.app
import textual.events
import textual  

class App(textual.app.App):

    @textual.on(textual.events.Resize)
    def resize_handler(self):
        width = self.size.width
        text = 'a' * (width - 4)
        widget = self.query_one(textual.widgets.SelectionList)
        widget.clear_options()
        widget.add_option((text, 0, None))

    def compose(self):
        yield textual.widgets.SelectionList (('random_text', 0), id='widget_id')

if __name__ == '__main__':
    App().run()
@github-actions
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@zdovcj zdovcj changed the title SelectionList crashes on resize SelectionList crashes on content overflow or resize Jul 18, 2023
@davep
Copy link
Contributor

davep commented Jul 18, 2023

Thanks. That looks to be a duplicate of #2900 so I'll close this in favour of the earlier report.

@davep davep closed this as completed Jul 18, 2023
@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@davep davep added bug Something isn't working duplicate This issue or pull request already exists labels Jul 18, 2023
@zdovcj
Copy link
Author

zdovcj commented Jul 18, 2023

Ok. Sorry for not noticing and posting a duplicate. I will at least add the code that dynamically changes the content length to #2900.

@davep
Copy link
Contributor

davep commented Jul 18, 2023

Sorry for not noticing and posting a duplicate

Absolutely no need to apologise; it's not always simple to find other issues and we'd sooner have a duplicate report than no report at all! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants