mango.fields.base module

class mango.fields.base.Field(name=None, editable=True, persist=True, unique=False, choices=None, min_value=None, max_value=None, default_value=None, default_value_only=False, hidden=False, keyable=False, channel_box=False)

Bases: object

The field class is the base descriptor that can be subclassed and used in the models. The descriptors have the possibility to validate provided values. It is possible for fields to persist through subclasses if the persist flag is set.

add_attribute_to_instance(instance)

Create the field attribute to the instance. This function will take the fields settings into account. It is possible to create arrays, compounds and all sorts of other attribute types.

Parameters:instance (models.Model) –
array = False
compound = None
create()

Create the attribute using the state of the class. This function handles the creation or any attribute but contains special handling to deal with compound attributes.

Returns:Attribute
Return type:OpenMaya.MObject
default(index=None)

Get the default value based on an index. By default this function handles four states. When a field is a compound field and the index is None ( meaning the parent attribute ) no default value can be present, the same goes for array attributes. Then based on the index either the entire default value or the provided index of the default value will be returned.

Parameters:index (int/None) –
Returns:Default value
default_value = None
get(instance)
Parameters:instance (models.Model) –
Returns:Value
Return type:str/int/float/list/tuple/dict/None
get_parent_plug(plug)

It is possible for fields to get connected via a proxy attribute connection. This function will find that connection and return it as a plug so the attribute can safely be set.

Parameters:plug (OpenMaya.MPlug) –
Returns:Parent plug
Return type:OpenMaya.MPlug
get_plug_value(plug)
Parameters:plug (OpenMaya.MPlug) –
Returns:Value
Return type:str/int/float/bool/list/tuple/None
mfn = None
mfn_type = None
set(instance, value, initialize=False)
Parameters:
  • instance (models.Model) –
  • value (str/int/float/list/tuple/dict/None) –
  • initialize (bool) –
set_plug_value(modifier, plug, value)
Parameters:
  • modifier (OpenMaya.MDGModifier) –
  • plug (OpenMaya.MPlug) –
  • value (str/int/float/bool/list/tuple/None) –
validate_default_only(value, instance)
Raises:RuntimeError – When the field is only allowed to take in the default value.
validate_editable(value, instance)
Raises:RuntimeError – When the field is not editable.
validate_list_or_tuple(value, instance)
Raises:TypeError – When the value is not a list.
validate_max_value(value, instance)
Raises:ValueError – When the value is not smaller than the provided max value.
validate_min_value(value, instance)
Raises:ValueError – When the value is not bigger than the provided min value.
validate_unique(value, instance)
Raises:RuntimeError – When the required value change makes the instance not unique to its reverse relations.
validators
Returns:Validators
Return type:list