Howdy pyRevit folks!
I’m currently implementing SelectFromList to allow the user to check items off a checklist. I’ve split the checklist into separate groups and while it seems to load just fine, once I press the “select” button, all that is returned is the results from the last open group.
I have return_all set to True, but that just returns all for the last open group. Is there a way to get the results for all open groups?
Below is a sample of what I’m currently experiencing, and a brief code snippet that creates the ShowFromList and prints the results.
Thanks!
result = forms.SelectFromList.show(myDict, title="QAQC List for " + targetSheet,
button_name="Set Selected As Completed",
group_selector_title="QAQC Item Type",
multiselect=True,
return_all = True)
for item in result:
print(item.name + '-' + str(item.checked))
I expected the same thing, that return_all would return all, not just what was currently in view. I just figured out how to monkey-patch SelectFromList so that it will truly return all items. The problem is that you lose the groups, if that is important to you. I hope someone else can do a better job than I did at this.
def _get_all_ctx(self):
if isinstance(self._context, dict):
return [y for x in self._context.values() for y in x]
else:
return self._context
forms.SelectFromList._get_all_ctx = _get_all_ctx
def _get_options(self):
if self.multiselect:
if self.return_all:
return self._get_all_ctx()
else:
return self._unwrap_options(
[x for x in self._get_active_ctx()
if x.state or x in self.list_lb.SelectedItems]
)
else:
return self._unwrap_options([self.list_lb.SelectedItem])[0]
forms.SelectFromList._get_options = _get_options
Thanks for going behind the curtain to find a fix for it! I ended up dropping the script/project because of the issue but I’ll make sure to add it back to the docket :).