Developing a New Editor

Hello everyone,

I’m trying to implement a new editor for Blender 2.8. However, I’m having a few problems, especially because the documentation is not really updated. I’m trying to learn from what I can find in the documentation and the code.

This page https://wiki.blender.org/index.php/Dev:Source/UI/Tutorials/AddAnEditor has been of great help, and thanks to it I managed to create a “blank” space in Blender. However, I’m struggling to continue the development.

The space I create doesn’t have the drop menu to change the space again. I couldn’t find a way to add it. Actually, I couldn’t find a way to add anything to the header or the main region.

Following this page Reference/FAQ - Blender Developer Wiki at the section “Where is the UI code?” I have created the python code for my new editor (and also added it to the __init__.py file) in release/scripts/modules/bl_ui/ . But I’m not sure of how I should “connect” the python code with the C code I wrote to create the editor! I’ve tried to mess around with the python files of other editors, and I can see that it has influence (making disappear menus or buttons), so I really believe that the python code I wrote is not working because I need to connect it with the C code I previously wrote.

I also compared what I wrote with other editors’ code (in particular INFO and CONSOLE, which I believe are the simplest), and they are pretty similar to mine. Am I missing something?

Any help would be really appreciated :blush: thank you in advance!

Regards,
Simone

3 Likes

Are you trying to do it in Python or C++ ?

if its in Python , then BGL modules is the way to go, if its C++ you will have to do what I do now, read through the implementation of regions and how they draw their elements, including GUIs and work areas.

It’s also a good idea to always link your code and an image with the error or problem you get so the devs can help you more accurately

Hello kilon,

Thank you for your reply :slight_smile:

I actually thought I need to use them both! I’ve created a new editor in source/blender/editors (in C++) and a Python script in release/scripts/startup/bl_ui/ .

You are right :slight_smile: I don’t really get an error. The new editor window is created, but it is empty, and I really do not understand how to add new elements in the header and in the main region! Not even the toggle to change editor again! Here’s the result:

For what concerns the code, the C++ code is basically the same of the tutorial I linked in my last post ( https://wiki.blender.org/index.php/Dev:Source/UI/Tutorials/AddAnEditor ). While the Python script is:

import bpy
from bpy.types import Header, Menu

class ACTOR_HT_header(Header):
    bl_space_type = 'ACTOR'

    def draw(self, context):
        layout = self.layout
        layout.template_header()

        pass


class ACTOR_MT_area(Menu):
    bl_label = "Area"

    def draw(self, context):
        layout = self.layout

        layout.operator("screen.area_dupli")
        if context.space_data.type == 'VIEW_3D':
            layout.operator("screen.region_quadview")
        layout.operator("screen.screen_full_area")
        layout.operator("screen.screen_full_area", text="Toggle Fullscreen Area").use_hide_panels = True


classes = (
    ACTOR_HT_header,
    ACTOR_MT_area,
)

if __name__ == "__main__":  # only for live edit.
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)

It is basically the same code of the info editor (which I think is the simplest), but I changed the name (Actor).

Following opinion should be taken with a mountain of salt because of how new I am to Blender C++ coding

Yes if you followed the tutorial to the letter not having menus, buttons or any gui elements seems normal to me. Those things will have to be added to the C++ code. Generally speaking you got the regions that do the drawing and you have to make sure you have the right region for the UI stuff.

How you do this in C++ is beyond me , I have not touched that part yet. My advice is find the editor you like the most and is closer to what you trying to achieve, launch the debug build with the debugger of your choice, add the breakpoint to the areas you want to examine and step over the code you see exactly how it executes the drawing and see the data that it expects.

If you really want to use Quad View for example , then examine the 3DVIEW.

You also could also try to modify the existing editor , in this example 3DView , to see how it behaves.

The layout indeed is done by Python but you have to make sure first that what Python requires is there and that is where C++ code comes in.

I know its not much but thats how I learned how to contribute my first patch today , took me a couple of hours because I had to battle both C++ and Python (my patch also deals with both suspects) so it can be tricky.

Starting next week I will be studying the same code myself to make my own GUI API, or rather an extension to the existing for some custom GUI elements I have in mind.

Ok, I found my mistake :slight_smile:

Basically, the “connection” between the python code and the c++ code is in the rna_space.c file, in the rna_enum_space_type_items structure!

The mistake I made was to name in the python file the space type as:

while in the rna_space.c file:

{SPACE_ACTOR, "ACTOR_EDITOR", ICON_INFO, "...", "..." }

I had to use ACTOR_EDITOR in the python file as well :slight_smile: shame on me because it was pretty easy to identify.

By the way, @kilon thank you for the support :slight_smile:

1 Like

Yeah that is coding , forever hunted by Dr Obvious :smiley:

I wish I could more help, glad you found out what was wrong :slight_smile:

1 Like

I am curious, what kind of editor are you developing? If it is a code editor, are you looking to incorporate more of the “modern” features from popular ones like Sublime, Atom or VS Code, such as multi-select, etc.?

Just curious…

Is there any new documentation or release notes about creating a new python editor in Blender 2.80 ?

There is no support for creating editors in Python in 2.8. There was some work towards it, but nothing finished.

3 Likes

@brecht we dont need anyting fancy, being able to add our own tabs to the properties editor is good enough in my opinion.

Are there still plans to implement custom editors for the final 2.8 release? Without it and without the ability to use the T-Shelf for Addons GUI (which admittedly was a mess), I fear Addon developers will have a hard time finding a place for their GUI and will instead clutter the N-Menu, which will result in a mess too.

Maybe in the meantime, a simple new tabbed Editor Type could be introduced that appers in the Editors-List as soon as at least one Addon that uses it is installed. It probably just use the code from the old T-Shelf, but without the vanilla Blender stuff and only Addons.

1 Like

I don’t think there will be custom editor support in 2.80, it would be for a later release. The support for tabs in the N-key sidebar is new in 2.8, and I think the result then will be quite similar to the T-key toolbar in 2.7.

I don’t see how custom editors provide much of a solution to that problem though. For most of the add-ons it would not be convenient to have to open an editor rather than access them from the side of the 3D viewport. There are only a few add-ons where a new editor helps.

Some add-ons can be converted to active tools, which can help clean up the UI by only showing the relevant settings and tools in the topbar when the tool is active.

5 Likes

Indeed, but like you said, some addons really need custom editors.
The N-Panel is narrow, that limits the possibilitiesand UI experience.

1 Like

I will not only have to agree with Brecht , I will take it one step further by saying that Blender has too many editors already.

On the matters of space limitation that’s easily handled by moving settings to properties panel which now has a special tab for addons if I understand it correctly. If you need more flexibility bgl and gpu modules can provide you with means to make your own custom gui anywhere you want. Most complex addons heavily rely on those modules already anyway.

For me the only justification for the introduction of a new editor would be if the addon offered at least 100 (a random big number used as example) new features. If not then an existing editor should be used. However even if it did I still will not find it a good option to introduce a new editor.

1 Like

What if it is a new editor for a rig picker ? A bit like AnimSchool Picker, where you can create and save your own pickers, I think that could be really useful :slight_smile: It doesn’t really fit in the sidebar :confused:

3 Likes

YESSS PLEASE, to add selection, sets, scripts that you can easily run, and buttons that you can rearrange however you feel like, that would be amazing.

1 Like

Well, it depends on the type of addon.

Some addons are entire asset managers, or entire scripting editors, and those kinds of things would be appropriate for an editor.

I was under the impression that Campbell already did the custom Python editors during the code quest?

1 Like

Yes, it really depends on the type of addon,
for example, I want to implement a node-based procedural texture generator for Blender 2.8,
so having its own editor is a must to be able to work with a node graph comfortably.

1 Like

And I can’t wait to see that!
By the way, why wouldn’t the node-editor be already the editor you need?

There was some work on it, but the code is unfinished.