Textualize/textual

SelectionList weird behavior when removing options in its own event handler until freeze

Closed this issue · 2 comments

When you interact with a SelectionList and remove the option in one of the event handlers one of the following happens:

  • Wrong options is removed
  • Option just deselects
  • Entire component just freezes (not the entire app; most likely occurs with the first or last option in the Selection List)

Example code:

from textual.app import App
from textual.widgets import SelectionList
from textual.widgets.selection_list import Selection
from textual.widget import Widget
import typing as t
from string import ascii_letters


class MyApp(App[str]):
    def compose(self) -> t.Iterable[Widget]:
        yield SelectionList(
            *[Selection(letter, letter, True, letter) for letter in ascii_letters],
        )

    def on_selection_list_selection_toggled(
        self, event: SelectionList.SelectionToggled[str]
    ) -> None:
        id_ = event.selection.id
        if id_ is not None:
            event.selection_list.remove_option(id_)


if __name__ == "__main__":
    app = MyApp()
    app.run()

It will be helpful if you run the following command and paste the results:

Textual Diagnostics

Versions

Name Value
Textual 0.58.0
Rich 13.7.1

Python

Name Value
Version 3.11.2
Implementation CPython
Compiler GCC 12.2.0
Executable /home/jan/Documents/dev/trove-setup/.venv/bin/python

Operating System

Name Value
System Linux
Release 6.1.0-17-amd64
Version #1 SMP PREEMPT_DYNAMIC Debian 6.1.69-1 (2023-12-30)

Terminal

Name Value
Terminal Application vscode (1.88.1)
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=208, height=17
legacy_windows False
min_width 1
max_width 208
is_terminal True
encoding utf-8
max_height 17
justify None
overflow None
no_wrap False
highlight None
markup None
height None

Video:

2024-04-29_19-33-11.mp4

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

Don't forget to star the repository!

Follow @textualizeio for Textual updates.