-
Notifications
You must be signed in to change notification settings - Fork 0
Operators
Blender defines a struct, wmOperatorType
.
Distilled down, this is essentially an abstract representation of an "action" of some sort. It is similar to ICommand in WPF, if you've ever used that, although it does a fair bit more. ICommand provides members for checking whether a function can currently be invoked (i.e. is it greyed out?), and a method to actually invoke the operation.
As well as that, Operators in Blender also contain names and descriptions for use in UI labels and tooltips, information on the command's "undoability", and keyboard shortcuts. There are also points exposed so they are callable from Python scripts. I've extended wmOperatorType
in my own branch so that every operator can also specify its own icon, for use when the UI wants to display that on buttons or menus.
Because the available operations in Blender are so self-describing, this makes it very easy to script the UI in Python, in what is effectively a declarative style. The script author just needs to specify where commands appear. Blender will then drop them pre-formed into the interface, and every time a command appears on the UI it will be consistent whether it's in a toolbar, menu, or button. Custom keybindings can be added and modified with little effort and behave just the same as if the operator was invoked by clicking a button. In principle, you could extend this further, so e.g. a gesture performed on a touchscreen could be hooked up to invoke some function.
As a general pattern found throughout Blender's codebase, Operators are identified and accessed via their idname so that they are accessible from Python as well as C.
So there you have it, that is what an Operator is.