I'd like to add a poll function to my BoolProperty, but I don't understand how it works.
Is it similar to the poll function of an operator? What represents the "object" argument of this function?
EDIT after Teck-freak answer:
There is no poll function for Properties.
HOWEVER: You can skip the property in the layout or (even better) block the layout (layout.enable=False) so it can be seen but not used. You can also fake the behaviour within the update-funktion, but you'll need a second property. Finally you can define getter, and setter functions for your property.
BLOCK THE LAYOUT:
row = layout.row() row.enable = False row.prop(self, 'MyBool') #this will appear grayed out
GETTER & SETTER:
def get_MyBool(self, context): return self.MyBool_internal def set_MyBool(self, context, value): if not self.dont_touch_MyBool: self.MyBool_internal = value MyBool_internal = bpy.props.BoolProperty() # This is where its actually stored MyBool = bpy.props.BoolProperty( # This is for your user-interface name='MyBool', get=get_MyBool, set=set_MyBool)
ABUSING THE UPDATE-FUNCTION: (Documentary only. Avoid if possible.)
def update_MyBool(self, context): if self.dont_touch_MyBool: # condition to check if changing mybool is allowed self.MyBool = self.MyBool_Backup else: self.MyBool_Backup = self.MyBool MyBool = bpy.props.BoolProperty(name='MyBool', update=update_MyBool)
You can read more about bpy.props here
BLOCKING CERTAIN INPUT:
Let's say you'd like to define an integer that may NOT accept multiples of 2 or 3.
# this will only be called if a valid entry is made def upd_MyInt(self, context): print('Entry accepted') # This is where its actually stored MyInt_Internal = bpy.props.IntProperty() # This is for your user-interface def get_MyInt(self, context): return self.MyInt_internal def set_MyInt(self, context, value): if value%2 and value%3: self.MyInt_internal = value MyInt = bpy.props.IntProperty(get=get_MyInt, set=set_MyInt)
[P]oll, checked before running the operator, which will never run when poll fails, used to check if an operator can run, menu items will be greyed out and if key bindings should be ignored.
A poll operator method would not make sense for a property. You may be looking for the update method.
update (function) – Function to be called when this value is modified, This function must take 2 values (self, context) and return None. Warning there are no safety checks to avoid infinite recursion.