Viewprovider/ru

Введение
Viewproviders are classes that define the way objects will look like in the tree view and the 3D view, and how they will interact with certain graphical actions such as selection.

They complement the scripted objects. While the base class of the scripted object defines its properties, the viewprovider defines it  properties. These view properties are not essential information of the object, as they only indicate superficial information like line width, line color, face color, etc. In a terminal only session, the viewprovider is not loaded because there will be no interface to manipulate those visible properties.

Like with data properties, view properties are accessible from the property editor.

Python view providers
The viewproviders classes usually include in their name. They are assigned on the attribute of the base object.

In this example, we define two properties for the viewprovider, only if the properties don't already exist, and assign their default values. We also define the method that runs every time a property changes. We need to test the property by name, and then we will call one of two methods that will do the actual work of updating the pattern or setting its size.

The normal workflow is to first add the object proxy class, for example,, and then the viewprovider, for example,. The viewprovider can only be assigned when we have verified that the graphical interface is available, as otherwise the attribute doesn't exist, and it will be an error to use this element as input for our class.

Custom icons
By implementing the method, you can specify the icon that will be shown in the tree view in the upper part of the combo view.

The return value can be the full path to an icon.

The relative path to an icon inside a compiled resource file.

A raw XPM icon, which is essentially ASCII art.

See various examples in Custom icon in tree view.