Custom UI for Blender 2.8 Addons


(calembendell) #1

Hullo everyone,

The available widgets that can be used to develop addons is unfortunately a little limiting for complex addons.
Customisability is also understandably low to keep the Blender editor’s appearance consistent.

If we need a sort of widget that is not already available in Blender, what is our best course of action?

I could write the necessary UI code in C to implement the widget, which would be painful and means the addon would take extra steps to install.

I could also implement the addon as a separate program that sends commands to Blender through an addon listening at a socket.
This adds to the complexity of the development of the addon and means that multiple windows need to be open, which is a pain, but grants all the flexibility an individual could want for the addon.

Is there another way?


(Roy Nieterau) #2

Do you have a design example of what you are trying to achieve that you are not able to produce with Blender’s UI? Maybe that could help you get started if others could help propose design ideas that would be a good fit in Blender?

If there really is good reason to use another UI toolkit… Managing other UI toolkits within Blender should be doable - I have seen some code examples using PyQt although I haven’t been able to run that stable myself yet, but I might be investigating that more soon as I need to reproduce the same UI I am using in multiple host applications, Maya, Houdini, Blender, etc. Using the same UI in multiple applications could be one of the reasons for not choosing specifically for Blender UI. :slight_smile:

(Ben H) #3

The available widgets that can be used to develop addons is unfortunately a little limiting for complex addons.

Could you be more specific about what you are looking for? Perhaps you have overlooked some options.

(SynaGl0w) #4

The current layout engine is very limited, especially via the python API. Despite that, the API does have one very handy feature: the as_pointer() method. If you look at the corresponding source you can recreate the C structs via the ctypes module and access many members that the python API does not provide access to. It’s actually quite amazing how many things the python API leaves out.

I assume what you are after is a custom widget placed in a panel along with other controls such as buttons and text fields? Always wanted a multi-line text widget with optional scroll bar(s). A widget with custom drawing and custom event handling (something that is usually possible in other UI toolkits).

I see a lot of possibilities to abuse the hell out of the gizmo API. Have not actually touched it much yet so we’ll see.

Supposedly custom editors should be a thing but can’t figure that out yet:

Some addons (asset managers, game engines etc) make sense to integrate as an entirely separate Editor. In 2.8 it is now possible for addons.

(calembendell) #5

Hey @BigRoy and @brhumphe,

I can definitely provide more context.
Many things are surprisingly difficult to do with Blender’s UI.
In my case, I wanted a big icon with a slider next to it or below it.
We tried to make Blender’s UI submit to that simple request for a bit before giving up since it isn’t really possible to set the size of an image.
Fortunately, the preview layout presents images as large enough to be legible if you’re presenting a complex image, so we settled for using 10 preview images rather than having a slider.

Now I would like to do things like allow an individual to select a point on a 2D grid to select X and Y values for complex morph targets, allowing procedural mesh editing to be controlled by selecting points on a grid.
Another thing I can’t figure out is how to let someone specify float curves in the editor for procedural generation or really to express any sort of complex data structure outside of having a very large dialogue box with single floats able to be specified.
I can’t really work around these requirements outside of creating an impossibly complex UI.

Thanks for the pointer to as_pointer @SynaGl0w, I’ll be giving it a look soon!
Having to boot up another UI would be a rubbish solution since it introduces a lot of unfortunate window management.
Maybe there’s a way to abuse the gizmo to deal with that indeed! :smiley:

(SynaGl0w) #6

That subject could supply an entire book of rants and rage.

The main reason I recommend looking into them is it appears they can be continuously active if desired (such as the ones in the 3D view), and handle drawing and input/events:

Still the annoying problem is being able to integrate any kind of custom control into Blenders UI system, layouts, panels, etc. The easy solution is to ignore the UI and just do custom drawing over the top of it, while consuming events that are relevant. If gizmos can work the way I assume, I might try to redo this little experiment: It might be much easier now with gizmos.

Just curious, do you have a mockup image of the kind of interface you are trying to create?


You can use the gpu python module inside Blender to develop your own GUIs , the gpu module allow to do custom drawing on top of the viewport.

I am also making a custom GUI but I decided to go the C route, I started with Python but I simply could not debug properly because obviously it depends on C code that I could not view. I agree that making a custom Blender build should always be the last option, but in my case it was because I wanted a very customisable interface and several other features , I could have implemented in Python but it would have been a lot trickier.

If you feel forced to have to develop an external windows then hacking Blender source is much better option. The most important thing for a developer is not the user but his ability to maintain and extend his code with ease. The user will be more than happy to tolerate the extra inconvenience if that means that you will be able to bombard him with extra features and productivity enhancements. Not to exclude much better performance.

There is a reason afterall that Pie Menus started as a python addon and now is C code. Same for animation nodes.

The important thing to remember that hacking Blender’s C source does not mean you have to marry C. You can extend the Blender Python API with C code and still keep your code 90% python. Although if you figure out the C part it then becomes as easy if not easier than using Python.

As a rule of thumb

  1. If you want easy but limited and slow stick with Python
  2. If you want hard, powerful and fast stick with C
  3. If you want medium difficulty, quite powerful and fast enough stick with extending the Blender Python API

None of the 3 is ideal and chances are depending on your actual needs that the choice will be crystal clear.

I also went with choice (1) , I actually tried to make it work but it became apparent that my best choice was between (2) and (3). Of course the scale of my project and the fact that it is commercial justifies this move from pure Python even more.

Learning the Blender source is a huge pain and C does not make it any easier(there is a reason why we can count with the fingers of one hand the numbers of blender forks out there) , but once you prevail you basically in god mode and you can do whatever you want.