Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillian Padovani Germano <wpgermano@gmail.com>2005-05-09 01:20:34 +0400
committerWillian Padovani Germano <wpgermano@gmail.com>2005-05-09 01:20:34 +0400
commit09fb5d6b8d1aafc66d33bded48b149105be41675 (patch)
treeb609f8ab8b109fc26db4c23a5557cc0e8327f454 /source/blender/src/buttons_script.c
parent8077caa96ec59aac67ff597ff3c96c23fb71b046 (diff)
BPython:
- Made Blender.event var (previously only used by script links) hold ascii value -- where it applies -- of current event during events callback registered with Draw.Register(gui, events, button_events). Useful for gui scripts like Campbell's Python console. No problem using this var to hold the value, since in gui scripts it was not used (always None). - Updated Window and Window.Theme with new theme vars and the Time space. - Script links: -- Added "Render" event for script links (runs twice, second time as "PostEvent", for clean-up actions). Now FrameChanged links don't run when a single pic is rendered. -- Added "Enable Script Links" button in the script buttons tab. Now this bit gets saved in .blends along with the rest of G.f, so users can define per .blend if they are on or off by default. "blender -y" also disables all slinks as happened before with OnLoad ones only. -- Other small changes in the script buttons tab: When a link is added (button "new"), it becomes the active one for the window, no need to press a button to reach it. Also, a pupmenu showing all available texts is shown when "new" is pressed, so users can choose a text w/o having to type. Cancel the popup to leave the string button empty (link exists, but has no script assigned). A pulldown would be better UI-wise, but it's kinda weird to show both scripts and normal texts (Blender doesn't differentiate them) in a script links pulldown. With a popup we can show only texts ending in ".py" (not done in this commit, need opinions) and if the script has no or another extension, case of many in old and current .blend's, there's still the string box for writing its name. -- Implemented Ton's space handler script links: Right now only for the 3d View, but it's trivial to add for others. There are two types: EVENT, to receive 3d View events from a chosen window and DRAW, to draw on the window. Ton's idea was to give scripts a controlled way to integrate better within Blender. Here's how it works: - scripts must have a proper header, like: # SPACEHANDLER.VIEW3D.EVENT and then they are shown in 3d View's View menu, "Space Handler Scripts" submenu. Check (mark, click on it) a script to make it active. EVENT handlers should consult the Blender.event var to get the current event, which can be compared with values from the Draw module: import Blender from Blender import Draw evt = Blender.event if evt == Draw.AKEY: print "a" elif evt == Draw.LEFTMOUSE: print "left mouse button" else: return # ignore, pass event back to Blender Blender.event = None # tell Blender not to process itself the event DRAW handlers are free to draw to their owner 3D View. OpenGL attributes and modelview and projection matrices are pushed before running the handler and poped when it finishes. To communicate between EVENT and DRAW handler scripts we have the Blender.Registry module, as always. Still need to code some nice example, which should also serve to test properly space handlers. Simple tests went fine. - doc updates about the additions. ======= Note: the UI part of the space handlers and script links is of course open for changes, I just tried to make it understandable. Probably we won't use the scriptlinks icon for "None Available" (check 3d View -> View -> Space Handler Scripts), though it hints at what space handlers are. The tooltips may not be accepted either, since other menus don't use them. Opinions welcomed.
Diffstat (limited to 'source/blender/src/buttons_script.c')
-rw-r--r--source/blender/src/buttons_script.c145
1 files changed, 95 insertions, 50 deletions
diff --git a/source/blender/src/buttons_script.c b/source/blender/src/buttons_script.c
index 3088486322f..54cbe328a4e 100644
--- a/source/blender/src/buttons_script.c
+++ b/source/blender/src/buttons_script.c
@@ -47,6 +47,7 @@
#include "DNA_curve_types.h"
#include "DNA_effect_types.h"
#include "DNA_group_types.h"
+#include "DNA_ID.h"
#include "DNA_ika_types.h"
#include "DNA_image_types.h"
#include "DNA_key_types.h"
@@ -59,6 +60,7 @@
#include "DNA_screen_types.h"
#include "DNA_scene_types.h"
#include "DNA_sound_types.h"
+#include "DNA_text_types.h"
#include "DNA_texture_types.h"
#include "DNA_userdef_types.h"
#include "DNA_vfont_types.h"
@@ -77,6 +79,7 @@
#include "BKE_image.h"
#include "BKE_ipo.h"
#include "BKE_lattice.h"
+#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mball.h"
#include "BKE_mesh.h"
@@ -87,6 +90,7 @@
#include "BKE_utildefines.h"
#include "BLI_blenlib.h"
+#include "BLI_dynstr.h"
#include "BSE_filesel.h"
@@ -111,10 +115,6 @@
/* ************************ function prototypes ********************** */
void draw_scriptlink(uiBlock *, ScriptLink *, int , int , int ) ;
-
-
-
-
/* *************************** SCRIPT ******************************** */
static void extend_scriptlink(ScriptLink *slink)
@@ -141,8 +141,7 @@ static void extend_scriptlink(ScriptLink *slink)
slink->flag[slink->totscript]= SCRIPT_FRAMECHANGED;
slink->totscript++;
-
- if(slink->actscript<1) slink->actscript=1;
+ slink->actscript = slink->totscript;
}
static void delete_scriptlink(ScriptLink *slink)
@@ -172,16 +171,55 @@ static void delete_scriptlink(ScriptLink *slink)
}
}
+static char *scriptlinks_menu_string(void)
+{
+ char *menu = NULL;
+ DynStr *ds = BLI_dynstr_new();
+ Text *text = G.main->text.first;
+ int txtcounter = 0;
+
+ if (text) {
+ BLI_dynstr_append(ds, "Select Script Link%t");
+ while (text) {
+ BLI_dynstr_append(ds, "|");
+ BLI_dynstr_append(ds, text->id.name+2);
+ txtcounter += 1;
+ text = text->id.next;
+ }
+ if (txtcounter) menu = BLI_dynstr_get_cstring(ds);
+ }
+ BLI_dynstr_free(ds);
+ return menu;
+}
+
+static void scriptlinks_pupmenu(ScriptLink *slink)
+{
+ short menuitem;
+ char *menustr = scriptlinks_menu_string();
+
+ if (menustr) {
+ menuitem = pupmenu_col(menustr, 20);
+ MEM_freeN(menustr);
+ if (menuitem > 0) {
+ Text *text = G.main->text.first;
+ while (--menuitem) text = text->id.next;
+ if (text) slink->scripts[slink->totscript - 1]= (ID *)text;
+ }
+ }
+}
+
void do_scriptbuts(unsigned short event)
{
Object *ob=NULL;
- ScriptLink *script=NULL;
+ ScriptLink *slink=NULL;
Material *ma;
switch (event) {
case B_SSCRIPT_ADD:
- extend_scriptlink(&G.scene->scriptlink);
+ slink = &G.scene->scriptlink;
+ extend_scriptlink(slink);
BIF_undo_push("Add scriptlink");
+ scriptlinks_pupmenu(slink);
break;
case B_SSCRIPT_DEL:
BIF_undo_push("Delete scriptlink");
@@ -193,31 +231,32 @@ void do_scriptbuts(unsigned short event)
ob= OBACT;
if (ob && G.buts->scriptblock==ID_OB) {
- script= &ob->scriptlink;
+ slink= &ob->scriptlink;
} else if (ob && G.buts->scriptblock==ID_MA) {
ma= give_current_material(ob, ob->actcol);
- if (ma) script= &ma->scriptlink;
+ if (ma) slink= &ma->scriptlink;
} else if (ob && G.buts->scriptblock==ID_CA) {
if (ob->type==OB_CAMERA)
- script= &((Camera *)ob->data)->scriptlink;
+ slink= &((Camera *)ob->data)->scriptlink;
} else if (ob && G.buts->scriptblock==ID_LA) {
if (ob->type==OB_LAMP)
- script= &((Lamp *)ob->data)->scriptlink;
+ slink= &((Lamp *)ob->data)->scriptlink;
} else if (G.buts->scriptblock==ID_WO) {
if (G.scene->world)
- script= &(G.scene->world->scriptlink);
+ slink= &(G.scene->world->scriptlink);
}
if (event==B_SCRIPT_ADD) {
- extend_scriptlink(script);
+ extend_scriptlink(slink);
BIF_undo_push("Add scriptlink");
+ scriptlinks_pupmenu(slink);
}
else {
- delete_scriptlink(script);
+ delete_scriptlink(slink);
BIF_undo_push("Delete scriptlink");
}
break;
@@ -235,6 +274,7 @@ void draw_scriptlink(uiBlock *block, ScriptLink *script, int sx, int sy, int sce
if (script->totscript) {
strcpy(str, "FrameChanged%x 1|");
strcat(str, "Redraw%x 4|");
+ strcat(str, "Render%x 16|");
if (scene) {
strcat(str, "OnLoad%x 2|");
strcat(str, "OnSave%x 8");
@@ -254,7 +294,7 @@ void draw_scriptlink(uiBlock *block, ScriptLink *script, int sx, int sy, int sce
if (script->totscript)
uiDefBut(block, BUT, B_SSCRIPT_DEL, "Del", (short)(sx+200), (short)sy-20, 40, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
- uiDefBut(block, LABEL, 0, "Scene scriptlink", sx,sy-20,140,20, 0, 0, 0, 0, 0, "");
+ uiDefBut(block, LABEL, 0, "Scene Script link", sx,sy-20,140,20, 0, 0, 0, 0, 0, "");
}
else {
@@ -263,7 +303,7 @@ void draw_scriptlink(uiBlock *block, ScriptLink *script, int sx, int sy, int sce
if (script->totscript)
uiDefBut(block, BUT, B_SCRIPT_DEL, "Del", (short)(sx+200), (short)sy-20, 40, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
- uiDefBut(block, LABEL, 0, "Selected scriptlink", sx,sy-20,140,20, 0, 0, 0, 0, 0, "");
+ uiDefBut(block, LABEL, 0, "Selected Script link", sx,sy-20,140,20, 0, 0, 0, 0, 0, "");
}
}
@@ -276,53 +316,58 @@ static void script_panel_scriptlink(void)
ScriptLink *script=NULL;
Material *ma;
int xco = 10;
-
+
block= uiNewBlock(&curarea->uiblocks, "script_panel_scriptlink", UI_EMBOSS, UI_HELV, curarea->win);
if(uiNewPanel(curarea, block, "Scriptlinks", "Script", 0, 0, 318, 204)==0) return;
-
-
- ob= OBACT;
- if(ob)
- uiDefIconButS(block, ROW, B_REDR, ICON_OBJECT, xco,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_OB, 0, 0, "Displays Object script links");
- if(ob && give_current_material(ob, ob->actcol))
- uiDefIconButS(block, ROW, B_REDR, ICON_MATERIAL, xco+=25,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_MA, 0, 0, "Displays Material script links ");
+ uiDefButI(block, TOG|BIT|13, REDRAWBUTSSCRIPT,
+ "Enable Script Links", xco, 200, 150, 20, &G.f, 0, 0, 0, 0,
+ "Enable execution of all assigned Script links");
+ /* for proper alignment: */
+ uiDefBut(block, LABEL, 0, "", 160, 200,150,20, NULL, 0.0, 0.0, 0, 0, "");
+
+ if (G.f & G_DOSCRIPTLINKS) {
+ ob= OBACT;
+ if(ob)
+ uiDefIconButS(block, ROW, B_REDR, ICON_OBJECT, xco,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_OB, 0, 0, "Displays Object script links");
+
+ if(ob && give_current_material(ob, ob->actcol))
+ uiDefIconButS(block, ROW, B_REDR, ICON_MATERIAL, xco+=25,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_MA, 0, 0, "Displays Material script links ");
- if(G.scene->world)
- uiDefIconButS(block, ROW, B_REDR, ICON_WORLD, xco+=25,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_WO, 0, 0, "Displays World script links");
+ if(G.scene->world)
+ uiDefIconButS(block, ROW, B_REDR, ICON_WORLD, xco+=25,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_WO, 0, 0, "Displays World script links");
- if(ob && ob->type==OB_CAMERA)
- uiDefIconButS(block, ROW, B_REDR, ICON_CAMERA, xco+=25,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_CA, 0, 0, "Displays Camera script links");
+ if(ob && ob->type==OB_CAMERA)
+ uiDefIconButS(block, ROW, B_REDR, ICON_CAMERA, xco+=25,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_CA, 0, 0, "Displays Camera script links");
- if(ob && ob->type==OB_LAMP)
- uiDefIconButS(block, ROW, B_REDR, ICON_LAMP, xco+=25,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_LA, 0, 0, "Displays Lamp script links");
+ if(ob && ob->type==OB_LAMP)
+ uiDefIconButS(block, ROW, B_REDR, ICON_LAMP, xco+=25,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_LA, 0, 0, "Displays Lamp script links");
- if (ob && G.buts->scriptblock==ID_OB) {
- script= &ob->scriptlink;
+ if (ob && G.buts->scriptblock==ID_OB) {
+ script= &ob->scriptlink;
- } else if (ob && G.buts->scriptblock==ID_MA) {
- ma= give_current_material(ob, ob->actcol);
- if (ma) script= &ma->scriptlink;
+ } else if (ob && G.buts->scriptblock==ID_MA) {
+ ma= give_current_material(ob, ob->actcol);
+ if (ma) script= &ma->scriptlink;
- } else if (ob && G.buts->scriptblock==ID_CA) {
- if (ob->type==OB_CAMERA)
- script= &((Camera *)ob->data)->scriptlink;
+ } else if (ob && G.buts->scriptblock==ID_CA) {
+ if (ob->type==OB_CAMERA)
+ script= &((Camera *)ob->data)->scriptlink;
- } else if (ob && G.buts->scriptblock==ID_LA) {
- if (ob->type==OB_LAMP)
- script= &((Lamp *)ob->data)->scriptlink;
-
- } else if (G.buts->scriptblock==ID_WO) {
- if (G.scene->world)
- script= &(G.scene->world->scriptlink);
- }
-
- if (script) draw_scriptlink(block, script, 10, 140, 0);
+ } else if (ob && G.buts->scriptblock==ID_LA) {
+ if (ob->type==OB_LAMP)
+ script= &((Lamp *)ob->data)->scriptlink;
- draw_scriptlink(block, &G.scene->scriptlink, 10, 80, 1);
+ } else if (G.buts->scriptblock==ID_WO) {
+ if (G.scene->world)
+ script= &(G.scene->world->scriptlink);
+ }
+ if (script) draw_scriptlink(block, script, 10, 140, 0);
+ draw_scriptlink(block, &G.scene->scriptlink, 10, 80, 1);
+ }
}