How to set selection values in a wizard state?

Thx. Of course, that’s the idea :slight_smile:

The initial configuration wizard seems to “just” get the next config wizard and executes that. Which does not match my problem (Please correct my if I’m wrong). My specific issue is: How to set the selectable values for this next StateView.

Meanwhile I tried:

  • Passing a method name as first parameter to fields.Selection(). The method depends on a hidden field (which I wanted to use to pass the table names around):

    class ImportWizardQuerySheetname(ModelView):
        sheets2 = fields.Binary('sheets_'')
        sheet = fields.Selection('get_sheetnames', "Sheet to import")
        def get_sheetnames(self):
            print("========>>>> ", repr(self), flush=1)
            return [(n, n) for n in self.sheets2.decode().split('\0')]

    This did not succeed since the value of the hidden field is always None when get_sheetnames() gets called.

  • Setting value and default for sheet in the wizard, using value_… and default_….
    This did not succeed since the value for sheet2 set in the value_… method did not make it to get_sheetnames() either.

The Solution I Found

Thus I ended up with defining a subclass of StateView which hacks the selectable values:

class QuerySheetnameStateView(StateView):
    def get_view(self, wizard, state_name):
        view = super().get_view(wizard, state_name)
        sheetnames = wizard.row_reader.sheetnames()
        if sheetnames:
            view['fields']['sheet']['selection'] = [
                (n, n) for n in sheetnames
        return view

and using this subclass:

class ImportWizard(Wizard):
            query_sheetname = QuerySheetnameStateView(…)

I someone knows a better solution, I’d be happy to learn about.