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 weird behavior when removing options in its own event handler until freeze #4462

Closed
jvllmr opened this issue Apr 29, 2024 · 2 comments · Fixed by #4464
Closed

Comments

@jvllmr
Copy link

jvllmr commented Apr 29, 2024

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
Copy link

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

Copy link

github-actions bot commented May 2, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant