Dynamically Update RadioList

Open
#1,795 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Start by tracing RadioList's handling of values, current_values, current_value, and app.invalidate(), then reproduce the update_data example from the issue. Done means replacing the RadioList items at runtime refreshes the displayed options and leaves the selected value consistent.

Written by the indexing model from the issue text.

Description

I was wondering if its possible to dynamically update the items in a RadioList.

I've figured out how to update the data inside of a TextArea, and would like to do something similar with the RadioList:

def handle_enter():
    new_value = self.radios.values[self.radios._selected_index][0]
    self.radios.current_value = new_value
    self.text_area.text = "new text"
self.radios._handle_enter = handle_enter

I've tried updating the RadioList's values and current_values but that didn't work:

def update_data(self, new_threads):
  radio_values = [(thread["id"], thread["messages"][0]["subject"]) for thread in threads]
  self.radios.values = radio_values
  self.radios.current_values = radio_values
  self.radios.current_value = radio_values[0][0]
  self.text_area.text = "new text"
  self.app.invalidate()
Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prompt-toolkit/python-prompt-toolkit

All issues in prompt-toolkit/python-prompt-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.