I would like to rewrite majority of VSE operators in python
Why
Maintenance and support
By rewriting all operators, we will greatly reduce amount of code, while keeping original functionality.
All C programmers are able to write python code. The reverse is not true.
In quite short period of time I was contacted by 2 contributors, that created operators in python:
https://developer.blender.org/D4290
Cleaner implementation
We are working with objects and python is object oriented language. We can do this in C, but this can lead to repeating of code or bloated not well readable code.
Leading examples
Currently there is no example code to learn from more quickly. If we use and maintain core python operators, there is no need to maintain examples in documentation.
Improving instead of rebuilding
Great feature of python is inheritance or use decorators to improve existing operators or those introduced in addon. This can lead to more consistent UI.
Why not
Speed?
I can not agree. If you are thinking about using operator on 10 000 strips, you are probably doing it wrong.
Conventions
https://www.youtube.com/watch?v=-QfhTWJIDCM
I can see that this approach may not be OK for other editors.
On the other hand all editors should have a nice and maintained object model. Using python operators would force developers to maintain it.
How
I will be explaining this for VSE, as other editors do have different workflows and interfaces.
API
Have very simple API’s to do simple things, group them in objects and collections.
Don’t know if RNA was meant to be object model, but it’s evident, that it has evolved into one.
Strip object example:
Expose all properties, that we allow user to change directly - position, length, inputs, …
Any user controllable behavior not accessible by properties should be exposed as object methods - remove, duplicate
Selection
To work effectively with selections, well-featured(filters, iterators) python object should be provided to us. Such object can be created in C using python library functions. I would rather use a interface, to which I can register an object, that will be instantiated when accessing a selection.
To further talk about selections and UI workflow, I think that it is good to introduce a mechanism of caching and invalidating a selection, so it can be accessed quickly. There are too many workarounds because of this.
Operators
This is pretty straight forward and documented, so I have pretty much nothing to say here.
list of operators after “refactoring”
http://pasteall.org/1514744
operators accessing single property (SEQUENCER_OT_mute, SEQUENCER_OT_lock, …) can be automatically generated on UI load, so number of those will be reduced. The same goes for selection classifiers and similar code
example of refactoring cut operator
In this example cut operator was rewritten in python
#58011 - Deleting the strip leading up to a crossfade - blender - Blender Projects was fixed
new modal mode was introduced.
simplified patch:
https://developer.blender.org/D4403
release/scripts/startup/bl_operators/sequencer.py | 124 ++++++++++++
.../editors/space_sequencer/sequencer_edit.c | 207 +--------------------
2 files changed, 125 insertions(+), 206 deletions(-)