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 /source/blender/python | |
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 .
Diffstat (limited to 'source/blender/python')
-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 |
4 files changed, 32 insertions, 10 deletions
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>} (*) |