[Bf-committers] Integration of scripts in the UI

Willian Padovani Germano bf-committers@blender.org
Sat, 6 Sep 2003 22:46:27 -0300


From: "Jacques Guignot" <guignot@wanadoo.fr>
> When will this Init function be called ?
>     a) When the script is launched
>     b) when blender is launched

b), like with Gimp.  And probably also when the relevant dirs
(blender/script and user's script dir) change, unless we want one of those
"you'll have to restart Blender for these changes to take effect".

> in case b, the bl_load_file will have to be modified. And what happens
> if there is no .blend file ?

No relation to that, it's like this:  scan the dirs, for each script try to
to import its Blender_Init() function:

  from <script_name> import Blender_Init
  # no Init function, return, ignoring this script
  # ...

Blender_Init()  # run the init function found

We'd possibly call this Blender_Init() and do this part in Python/C, not
Python as above.

This init will (either directly like the new Registry module or by returning
the data) have the script data needed for menus stored in a blender dict
we'll keep only for that.

You can check the toolbox.c file to have a better idea of the needed data:
name, tooltip, shortcut and callback -- better not let scripts define
shortcuts for themselves, for sure.

When creating menus, each relevant one can, after adding its normal entries,
use a function to "ask" if there are registered script entries to be put
there, too.  If so, it inserts the entries using the name, callback, etc.
given by the script on startup.

Actually 'callback' above is not the right term.  It is a function in the
script, but to actually run it, we have to call another function and pass
both the script filename and the function inside it that should be executed.
This function then would prepare things and make the expected pyfunction be

I still have to code a first test, see if there are problems.

> btw, u talked about a "space" window. What is it exactly ? A new kind of
> window, like text windows or 3D windows?
> What are its properties?

Blender separates the concepts window (a partition of the screen made with
borders) and contents of the window (space).  The "text window" is the
SpaceText space inside a window.  If you go back to the 3d one or to the
file selector, etc., you changed the space inside that window, not the
window itself.

> Why not use a text window. It *is* a good thing
> to let the users edit a script, advanced users may want to
> fiddle/customize it, no?

Yes, but not every user and not all the time, so it's not good to load all
scripts as texts.  There will also be "nicer" ways to customize scripts: the
buttons in the guis and (added this yesterday night to my local copy) pop-up
menus, for example.  I also learned more about how these widgets are built,
so my next step there will be letting script writers create a pop-up and
embed any of the available types of buttons inside it.

> Don't worry, I'm a bit lengthy to understand, but I don't forget...

: ) My fault, I didn't explain anything.  And I'm afraid this email didn't
help enough, either.  I'll make some tests before writing a real proposal.

Willian, wgermano@ig.com.br