pick icon indicating copy to clipboard operation
pick copied to clipboard

Default selections of multi-select

Open r3a1d3a1 opened this issue 2 years ago • 1 comments

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.

r3a1d3a1 avatar Jul 24 '23 00:07 r3a1d3a1

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...

manurFR avatar Feb 27 '24 14:02 manurFR