Page MenuHome

Multiple return flags for Operators' poll()
Closed, InvalidPublicPATCH

Description

This patch makes Operators poll() functions return multiple flags determining the available or suggested "usage" for the Operator in the current Context.

This makes it possible for instance to let an Operator execute in some Context without being presented in the User Interface (e.g. in the Search Popup) or to disallow re-doing an Operator in the Toolbox re-do because for instance the functionality is buggy or can cause a crash. Also, additional flags can be added later with other meanings.

The patch also takes care of backward compatibility assigning special meaning to values 1 and 0, thus leaving old Operators fully functional as they were before without actual code changes.

One problem is that for Python operators, because it performs type checking, not returning an enum value actually causes an error and poll() is then assumed returning 0. To fix this I added some hackish type conversion in pyrna which can be removed once all scripts are ported.

I admit though that having a one-liner poll() like "return context.object" was more appealing then having to return an enum value. If we want to keep this we could add a RNA_define_enum_int_range through which you can define a valid, i.e. safe, range of int values compatible with the enum/flags.