[Bf-committers] Integration of scripts in the UI

Willian Padovani Germano bf-committers@blender.org
Wed, 3 Sep 2003 00:26:15 -0300


Hi, (long post, sorry)

We've been discussing and experimenting, trying to find the best way to have
python scripts accessible from menus / spacebar toolbox.  This is a summary
of the current ideas:

Jacques Guignot already made a test with a menu, but as he saw, scripts that
open guis don't work.  That is because the current system is hardwired to
put the gui over the text space where the user pressed ALT+P.  To finish his
test, his solution was to, when a script entry was chosen from a menu, load
it as a blender text and follow the current procedure.  It works and he can
explain more / send a patch to anyone who would like to try it.  But we'd
better not have to load all scripts as texts, that's not necessary.

Guignot's test hinted that we need a space in Blender where scripts can open
their guis.  That's the idea, now.

We can divide the job in two parts:

[1] Create the SpaceScript, similar to the SpaceText (text window in
Blender):

- its header should have a dropdown list with currently running scripts
(like the text header has with currently loaded texts).

- when the user chooses a script from a menu: if the script has a gui, the
active window jumps to the script window and the script gui appears there,
+- like the file selector does.

(issue): this creates a problem if we put scripts with guis in the top
menubar, since then no window has focus and we have to choose one, again
like the file selector does (but scripts in general shouldn't need to stay
open only for a short while, the idea is to allow them to work like normal
Blender spaces/modes).  This issue doesn't happen with the spacebar toolbox,
since
then some window has the current focus and we use it to open the script
space.

[2] Scanning the scripts directory and building the Scripts menu

Think Gimp:

- a default installation blender/scripts/ and
- a user dir (.blender/scripts, for a linux example).

This so that installing new versions of Blender don't mess with "user"
scripts (ones they modified, created, downloaded from the net, etc).

To draw the scripts menu or submenu we play simple, like Ton suggested: scan
the scripts/ dir and use filenames and subdirs themselves to create entries
and submenus, resp.  Like this bogus example: the dir structure

blender/scripts/ :
./modeling/
./export/
./import/

blender/scripts/modeling/ :
./TurtleMakerV0_2.py
./GalaxyBuilderV32_5.py
./HandModeler.py

blender/scripts/export/ :
./FormatXYZ.py
./NoUVTex.py
./OnlyTriangles.py
./OnlyNames.py

and so on, would become the menu "Scripts":

-- Export ...
-- Import ...
-- Modeling ...

opening the Modeling submenu:

-- Turtle Maker 0.2
-- Galaxy Builder 32.5
-- Hand Modeler

[[
Possible filename conventions:

-- normal script to be in the menus (executable): ScriptNameV1_0.py,
which becomes the menu entry "Script Name 1.0".

(So to get the menu entry we parse the name and separate it where a
capital appears. If the letter is a "V" followed by a number, we include
it as the script version number.)

-- scripts not to be in the menus ("libs" or data for executable scripts):
m_scriptname.py (or .pyc, .pyo).

(So if an "m_" (or maybe "mod_") for "module" is prepended, we ignore the
file while creating the menus.  We also ignore any extension except those of
executable python code: .py, .pyc, .pyo, .pyd (I guess))
]]
-------------------------------

Once clean / ready, I'll send the SpaceScript to Ton for checking.
Suggestions are of course welcome, just keep in mind that, targetting 2.29
and with possibly big and still undecided changes in the UI being discussed,
the best we can do now is to try to get a simple and flexible design.

While thinking / working on this, I've discussed with (in order of whom I
bothered the most): Ton, LarstiQ, Michel, Guignot, R. Kimball.

Shoot someone I forgot!  Mm?! ...

Thanks,

--
Willian, wgermano@ig.com.br