diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2004-07-03 21:28:15 +0400 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2004-07-03 21:28:15 +0400 |
commit | cbe7471905bd6f34c00b5d1b6b9cde84f3f24cb4 (patch) | |
tree | e0a028d26d3cb6939c1ea396242d6f739fe124b0 | |
parent | 5c543698c9fd5377aee5630ed22a87921593a3ad (diff) |
Interface:
- added submenu "Scripts" in both View3D->Object and Mesh menus.
Put them on top (it's better to follow some guideline, so users don't have to search for "Scripts" submenu in a different position in each menu), feel free to change.
- added button 'previous win' to SpaceScript, makes accessing buttons win, for example, much faster. Maybe all spaces could have this button.
BPython:
- added Window.EditMode(), to check, enter and leave edit mode. Scripts that change mesh data need this to leave edit mode before making changes to the active (G.obedit) mesh, of course.
- updated script bevel_center to use the above function and also popup an error msg if the active obj is not a mesh.
- doc updates, minor fixes.
Forgot to mention in my previous commit that I also updated the "-P" command-line option (for running script files) to be able to run already loaded Blender Texts, too. So, if you have a script called 'Text' in foo.blend, you can run it with blender foo.blend -P Text .
-rw-r--r-- | release/scripts/bevel_center.py | 8 | ||||
-rw-r--r-- | release/scripts/disp_paint233f.py | 2 | ||||
-rw-r--r-- | release/scripts/unweld044.py | 2 | ||||
-rw-r--r-- | source/blender/include/blendef.h | 2 | ||||
-rw-r--r-- | source/blender/python/BPY_extern.h | 1 | ||||
-rw-r--r-- | source/blender/python/BPY_interface.c | 9 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Window.c | 30 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Blender.py | 2 | ||||
-rw-r--r-- | source/blender/src/header_image.c | 2 | ||||
-rw-r--r-- | source/blender/src/header_info.c | 4 | ||||
-rw-r--r-- | source/blender/src/header_script.c | 32 | ||||
-rw-r--r-- | source/blender/src/header_view3d.c | 67 |
12 files changed, 126 insertions, 35 deletions
diff --git a/release/scripts/bevel_center.py b/release/scripts/bevel_center.py index eef2f630cea..e40c25b3ec1 100644 --- a/release/scripts/bevel_center.py +++ b/release/scripts/bevel_center.py @@ -19,7 +19,7 @@ Tip: 'Bevel selected vertices.' ###################################################################### import Blender -from Blender import NMesh +from Blender import NMesh, Window from Blender.Draw import * from Blender.BGL import * @@ -404,6 +404,11 @@ def bevel(): global me,NF,NV,NE,NC, old_dist # objects = Blender.Object.GetSelected() + if objects[0].getType() != "Mesh": + PupMenu("Error|Active object for bevelling must be a mesh.") + return + editmode = Window.EditMode() + if editmode: Window.EditMode(0) me = NMesh.GetRaw(objects[0].data.name) # NF = [] @@ -420,6 +425,7 @@ def bevel(): old_dist = dist.val # me.update(1) + if editmode: Window.EditMode(1) Blender.Redraw() def bevel_update(): diff --git a/release/scripts/disp_paint233f.py b/release/scripts/disp_paint233f.py index ed2db043fb2..d71d7857af2 100644 --- a/release/scripts/disp_paint233f.py +++ b/release/scripts/disp_paint233f.py @@ -4,7 +4,7 @@ Name: 'Dispaint' Blender: 233 Group: 'Mesh' -Tip: 'use vertex paint color value to modify shape displacing vertices along normal.' +Tip: 'Use vertex paint color value to modify shape displacing vertices along normal.' """ # $Id$ diff --git a/release/scripts/unweld044.py b/release/scripts/unweld044.py index d6fa71090a1..d93ef474703 100644 --- a/release/scripts/unweld044.py +++ b/release/scripts/unweld044.py @@ -3,7 +3,7 @@ Name: 'UnWeld' Blender: 232 Group: 'Mesh' -Tip: 'unweld all faces from one selected and commun vertex. Made vertex bevelling' +Tip: 'Unweld all faces from a selected and common vertex. Made vertex bevelling.' """ # $Id$ diff --git a/source/blender/include/blendef.h b/source/blender/include/blendef.h index a4a50114841..2ff08352d0d 100644 --- a/source/blender/include/blendef.h +++ b/source/blender/include/blendef.h @@ -342,7 +342,7 @@ /* SCRIPT: 525 */ #define B_SCRIPTBROWSE 526 -#define B_SCRIPT2BUTS 527 +#define B_SCRIPT2PREV 527 /* FILE: 550 */ #define B_SORTFILELIST 551 diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index 9829226db81..901f5c5ee4e 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -53,6 +53,7 @@ int BPY_Err_getLinenumber(void); const char *BPY_Err_getFilename(void); /* void BPY_Err_Handle(struct Text *text); */ int BPY_txt_do_python(struct SpaceText* st); +int BPY_menu_do_python(short menutype, int event); void BPY_run_python_script(char *filename); void BPY_free_compiled_text(struct Text* text); /*void BPY_clear_bad_scriptlink(struct ID *id, struct Text *byebye); */ diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index fecff8e02e8..24888677279 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -42,7 +42,6 @@ #include <MEM_guardedalloc.h> #include <BLI_blenlib.h> /* for BLI_last_slash() */ -#include <BDR_editobject.h> /* for exit_editmode() */ #include <BIF_interface.h> /* for pupmenu() */ #include <BIF_space.h> #include <BIF_screen.h> @@ -448,10 +447,6 @@ int BPY_txt_do_python_Text(struct Text* text) * will have been deallocated already, so we need to copy its name here. */ BLI_strncpy(textname, GetName(text), strlen(GetName(text))+1); - /* if in it, leave editmode, since changes a script makes to meshdata - * can be lost otherwise. */ - if (G.obedit) exit_editmode(1); - script->id.us = 1; script->flags = SCRIPT_RUNNING; script->py_draw = NULL; @@ -621,10 +616,6 @@ int BPY_menu_do_python(short menutype, int event) return 0; } - /* if in editmode, leave it, since changes a script makes to meshdata - * can be lost otherwise. */ - if (G.obedit) exit_editmode(1); - /* let's find a proper area for an eventual script gui: * (still experimenting here, need definition on which win * each group will be put to code this properly) */ diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c index 99f9ec9b709..5377bc3b89b 100644 --- a/source/blender/python/api2_2x/Window.c +++ b/source/blender/python/api2_2x/Window.c @@ -32,6 +32,7 @@ #include <Python.h> #include <stdio.h> +#include <BDR_editobject.h> /* enter / leave editmode */ #include <BKE_global.h> #include <BKE_library.h> #include <BKE_object.h> /* for during_script() */ @@ -73,6 +74,7 @@ static PyObject *M_Window_GetViewVector (PyObject *self); static PyObject *M_Window_GetViewMatrix (PyObject *self); static PyObject *M_Window_FileSelector (PyObject *self, PyObject *args); static PyObject *M_Window_ImageSelector (PyObject *self, PyObject *args); +static PyObject *M_Window_EditMode (PyObject *self, PyObject *args); /*****************************************************************************/ /* The following string definitions are used for documentation strings. */ @@ -130,6 +132,13 @@ static char M_Window_GetViewVector_doc[] = static char M_Window_GetViewMatrix_doc[] = "() - Get the current 3d view matrix."; +static char M_Window_EditMode_doc[] = +"() - Get the current status -- 0: not in edit mode; 1: in edit mode.\n\ +(status) - if 1: enter edit mode; if 0: leave edit mode.\n\ +Returns the current status. This function is mostly useful to leave\n\ +edit mode before applying changes to a mesh (otherwise the changes will\n\ +be lost) and then returning to it upon leaving."; + /*****************************************************************************/ /* Python method structure definition for Blender.Window module: */ /*****************************************************************************/ @@ -153,6 +162,8 @@ struct PyMethodDef M_Window_methods[] = { M_Window_GetViewVector_doc}, {"GetViewMatrix", (PyCFunction)M_Window_GetViewMatrix, METH_NOARGS, M_Window_GetViewMatrix_doc}, + {"EditMode", (PyCFunction)M_Window_EditMode, METH_VARARGS, + M_Window_EditMode_doc}, {NULL, NULL, 0, NULL} }; @@ -466,6 +477,25 @@ static PyObject *M_Window_GetViewMatrix(PyObject *self) return viewmat; } +static PyObject *M_Window_EditMode(PyObject *self, PyObject *args) +{ + short status = -1; + + if(!PyArg_ParseTuple(args, "|h", &status)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected nothing or an int (bool) as argument")); + + if (status >= 0) { + if (status) { + if (!G.obedit) enter_editmode(); + } + else if (G.obedit) exit_editmode(1); + } + + return Py_BuildValue("h", G.obedit?1:0); +} + + /*****************************************************************************/ /* Function: Window_Init */ /*****************************************************************************/ diff --git a/source/blender/python/api2_2x/doc/Blender.py b/source/blender/python/api2_2x/doc/Blender.py index eb048b65e31..985608b53b4 100644 --- a/source/blender/python/api2_2x/doc/Blender.py +++ b/source/blender/python/api2_2x/doc/Blender.py @@ -44,7 +44,7 @@ The Blender Python API Reference - L{Text} - L{Texture} - L{Types} - - L{Window} + - L{Window} (* important: L{Window.EditMode}) - L{World} (*) - L{sys<Sys>} (*) diff --git a/source/blender/src/header_image.c b/source/blender/src/header_image.c index 03a0901c8c7..b110a3d9a2c 100644 --- a/source/blender/src/header_image.c +++ b/source/blender/src/header_image.c @@ -81,6 +81,7 @@ #include "BSE_filesel.h" #include "BSE_headerbuttons.h" +#include "BPY_extern.h" #include "BPY_menus.h" #include "IMB_imbuf.h" @@ -815,7 +816,6 @@ static uiBlock *image_uvs_transformmenu(void *arg_unused) static void do_image_uvsmenu(void *arg, int event) { - extern int BPY_menu_do_python(short menutype, int event); // BPY_interface.c ScrArea *sa; /* events >=20 are registered bpython scripts */ diff --git a/source/blender/src/header_info.c b/source/blender/src/header_info.c index bd537fa3d1b..d483a1b9a50 100644 --- a/source/blender/src/header_info.c +++ b/source/blender/src/header_info.c @@ -672,7 +672,6 @@ static uiBlock *info_runtime_optionsmenu(void *arg_unused) static void do_info_file_importmenu(void *arg, int event) { - extern int BPY_menu_do_python(short menutype, int event); // BPY_interface.c ScrArea *sa; if(curarea->spacetype==SPACE_INFO) { @@ -738,7 +737,6 @@ static uiBlock *info_file_importmenu(void *arg_unused) static void do_info_file_exportmenu(void *arg, int event) { - extern int BPY_menu_do_python(short menutype, int event); // BPY_interface.c ScrArea *sa; if(curarea->spacetype==SPACE_INFO) { @@ -1590,8 +1588,6 @@ static uiBlock *info_help_websitesmenu(void *arg_unused) static void do_info_helpmenu(void *arg, int event) { - - extern int BPY_menu_do_python(short menutype, int event); // BPY_interface.c ScrArea *sa; if(curarea->spacetype==SPACE_INFO) { diff --git a/source/blender/src/header_script.c b/source/blender/src/header_script.c index 0ce38ec9846..01d400bcbbf 100644 --- a/source/blender/src/header_script.c +++ b/source/blender/src/header_script.c @@ -45,6 +45,8 @@ #include "BLI_winstuff.h" #endif +#include "BLI_blenlib.h" + #include "BMF_Api.h" #include "BIF_language.h" #ifdef INTERNATIONAL @@ -80,7 +82,6 @@ /* action executed after clicking in Scripts menu */ static void do_scripts_submenus(void *int_arg, int event) { - extern int BPY_menu_do_python(short menutype, int event); // BPY_interface.c int menutype = (int)int_arg; BPY_menu_do_python (menutype, event); @@ -97,9 +98,8 @@ static uiBlock *script_scripts_submenus(void *int_menutype) if ((menutype < 0) || (menutype > PYMENU_TOTAL)) return NULL; - block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); + block= uiNewBlock(&curarea->uiblocks, "scriptsscriptssubmenus", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); uiBlockSetButmFunc(block, do_scripts_submenus, int_menutype); - //uiBlockSetXOfs(block, -50); // offset to parent button for (pym = BPyMenuTable[menutype]; pym; pym = pym->next, i++) { uiDefBut(block, BUTM, 1, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename); @@ -168,7 +168,7 @@ void do_script_buttons(unsigned short event) SpaceScript *sc= curarea->spacedata.first; ID *id, *idtest; int nr= 1; - Script *script; + Script *script = sc->script; if (!sc) return; if (sc->spacetype != SPACE_SCRIPT) return; @@ -176,13 +176,12 @@ void do_script_buttons(unsigned short event) switch (event) { case B_SCRIPTBROWSE: if (sc->menunr==-2) { - activate_databrowse((ID *)sc->script, ID_SCR, 0, B_SCRIPTBROWSE, + activate_databrowse((ID *)script, ID_SCR, 0, B_SCRIPTBROWSE, &sc->menunr, do_script_buttons); break; } - if(sc->menunr < 0) break; - script = sc->script; + if(sc->menunr < 0) break; nr = 1; id = (ID *)script; @@ -202,8 +201,13 @@ void do_script_buttons(unsigned short event) allqueue(REDRAWHEADERS, 0); } break; - case B_SCRIPT2BUTS: - newspace(curarea, SPACE_BUTS); + case B_SCRIPT2PREV: + if(sc->next) { + BLI_remlink(&curarea->spacedata, sc); + BLI_addtail(&curarea->spacedata, sc); + sc = curarea->spacedata.first; + newspace(curarea, sc->spacetype); + } break; } @@ -256,7 +260,9 @@ void script_buttons(void) } uiBlockSetEmboss(block, UI_EMBOSSX); - xco += 10; + + uiDefIconBut(block, BUT, B_SCRIPT2PREV, ICON_GO_LEFT, xco+=XIC, 0, XIC, YIC, + 0, 0, 0, 0, 0, "Returns to previous window"); /* FULL WINDOW */ if(curarea->full) @@ -270,12 +276,6 @@ void script_buttons(void) xco += 2*XIC; xco= std_libbuttons(block, xco, 0, 0, NULL, B_SCRIPTBROWSE, (ID*)sc->script, 0, &(sc->menunr), 0, 0, 0, 0, 0); - if (sc->script && sc->script->lastspace == SPACE_BUTS) { - xco += 10; - uiDefIconBut(block, BUT, B_SCRIPT2BUTS, ICON_BUTS, xco+=XIC, 0, XIC, YIC, - 0, 0, 0, 0, 0, "Returns to Buttons Window"); - } - /* always as last */ curarea->headbutlen= xco+2*XIC; diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c index faf2b777c13..aaf063d28d1 100644 --- a/source/blender/src/header_view3d.c +++ b/source/blender/src/header_view3d.c @@ -104,6 +104,9 @@ #include "BIF_toolbox.h" #include "BIF_gl.h" +#include "BPY_extern.h" +#include "BPY_menus.h" + #include "blendef.h" #include "mydevice.h" #include "butspace.h" @@ -1628,6 +1631,35 @@ static uiBlock *view3d_edit_object_trackmenu(void *arg_unused) return block; } +static void do_view3d_edit_object_scriptsmenu(void *arg, int event) +{ + BPY_menu_do_python(PYMENU_OBJECT, event); + + allqueue(REDRAWVIEW3D, 0); +} + +static uiBlock *view3d_edit_object_scriptsmenu(void *arg_unused) +{ + uiBlock *block; + short yco = 20, menuwidth = 120; + BPyMenu *pym; + int i = 0; + + block= uiNewBlock(&curarea->uiblocks, "v3d_eobject_pymenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); + uiBlockSetButmFunc(block, do_view3d_edit_object_scriptsmenu, NULL); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + for (pym = BPyMenuTable[PYMENU_OBJECT]; pym; pym = pym->next, i++) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename); + } + + uiBlockSetDirection(block, UI_RIGHT); + uiTextBoundsBlock(block, 60); + + return block; +} + static void do_view3d_edit_objectmenu(void *arg, int event) { /* needed to check for valid selected objects */ @@ -1731,6 +1763,9 @@ static uiBlock *view3d_edit_objectmenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Move to Layer...|M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, ""); + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBlockBut(block, view3d_edit_object_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Scripts", 0, yco-=20, 120, 19, ""); + if(curarea->headertype==HEADERTOP) { uiBlockSetDirection(block, UI_DOWN); @@ -2103,6 +2138,35 @@ static uiBlock *view3d_edit_mesh_showhidemenu(void *arg_unused) return block; } +static void do_view3d_edit_mesh_scriptsmenu(void *arg, int event) +{ + BPY_menu_do_python(PYMENU_MESH, event); + + allqueue(REDRAWVIEW3D, 0); +} + +static uiBlock *view3d_edit_mesh_scriptsmenu(void *arg_unused) +{ + uiBlock *block; + short yco = 20, menuwidth = 120; + BPyMenu *pym; + int i = 0; + + block= uiNewBlock(&curarea->uiblocks, "v3d_emesh_pymenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); + uiBlockSetButmFunc(block, do_view3d_edit_mesh_scriptsmenu, NULL); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + for (pym = BPyMenuTable[PYMENU_MESH]; pym; pym = pym->next, i++) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename); + } + + uiBlockSetDirection(block, UI_RIGHT); + uiTextBoundsBlock(block, 60); + + return block; +} + static void do_view3d_edit_meshmenu(void *arg, int event) { switch(event) { @@ -2206,6 +2270,9 @@ static uiBlock *view3d_edit_meshmenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); uiDefIconTextBlockBut(block, view3d_edit_mesh_showhidemenu, NULL, ICON_RIGHTARROW_THIN, "Show/Hide Vertices", 0, yco-=20, 120, 19, ""); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBlockBut(block, view3d_edit_mesh_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Scripts", 0, yco-=20, 120, 19, ""); if(curarea->headertype==HEADERTOP) { uiBlockSetDirection(block, UI_DOWN); |