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

Default selections of multi-select #106

Open
r3a1d3a1 opened this issue Jul 24, 2023 · 1 comment
Open

Default selections of multi-select #106

r3a1d3a1 opened this issue Jul 24, 2023 · 1 comment

Comments

@r3a1d3a1
Copy link

I can't tell from the README whether it's possible to have a few options selected as the dialog is presented to the user at first.
For example, there may be 10 options, 3 of which are selected initially.

@manurFR
Copy link

manurFR commented Feb 27, 2024

Some hack for this (works with pick 2.2.0):

import pick

# Example 1: Pre-select 3 options (first, third, sixth)
preselected = [0, 2, 5]

# Example 2: Pre-select all options
# preselected = list(range(len(options)))

__original_post_init__ = pick.Picker.__post_init__

def __hacked_post_init__(self):
    __original_post_init__(self)
    self.selected_indexes.extend(preselected)

pick.Picker.__post_init__ = __hacked_post_init__

selected = pick.pick(options=options, multiselect=True)

It would be trivial to add the feature to the main code without an ugly hack.
@wong2 Do you review and accept pull requests ? I see there are some of them that have never been evaluated...

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

No branches or pull requests

2 participants