diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2004-04-11 08:41:33 +0400 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2004-04-11 08:41:33 +0400 |
commit | 149fad4be63e1926f923890730fe0b578a7f3f92 (patch) | |
tree | 7eef6199bc7bd406fb10e2cc38272d304c27744b | |
parent | ae9233a5b05ebfc925fd542afbdb3bb9220ed65c (diff) |
BPython: cleaning some bug tracker entries:
(excuse me for doing all in a single commit, but they are tiny
fixes and it's bpython, that dark corner ...)
#1025 - FileSelector SEGV on dynamic callback Category:
Can't reproduce with current cvs, I'd say recent changes to fix
another crash related to FileSelector in gui-less scripts solved this
one, too.
#1028 - Reserved button event number:
Menu choices generate two events, one extra related to the menu
itself, with value=4. Made bpython ignore this extra event.
#1068 - FileSelector No file extension support:
As Ton wrote there, Blender itself doesn't support this yet. But the
requester also wanted Window.File/ImageSelector to accept a pathname. Done. Also updated doc.
#959 - Segfault on background rendering:
This happened in bg mode (blender -b filename -a, for example) when
a script with the line "Blender.Redraw()" was linked to FRAMECHANGED events. As reported in the bug page, it was because curarea is NULL in bg mode. Made Redraw() check for this and not call functions that expected curarea in Redraw, like one to swap buffers.
#1072 - Blender.Redraw() Segfault:
Good catch : ). Scripts called from the scripts win that called
Blender.Redraw() or Blender.Window.Redraw() would crash Blender because of a dirty pointer in Spacescript->script. Fixed.
-rw-r--r-- | source/blender/python/BPY_interface.c | 10 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Blender.h | 8 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Draw.c | 1596 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Window.c | 162 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Window.h | 124 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Window.py | 10 |
6 files changed, 943 insertions, 967 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 5bc64d20c22..9eb82b619aa 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -655,10 +655,20 @@ int BPY_menu_do_python(short menutype, int event) else { Py_DECREF (py_res); script->flags &=~SCRIPT_RUNNING; + if (!script->flags) { ReleaseGlobalDictionary(py_dict); script->py_globaldict = NULL; free_libblock(&G.main->script, script); + + /* special case: called from the menu in the Scripts window + * we have to change sc->script pointer, since it'll be freed here.*/ + if (curarea->spacetype == SPACE_SCRIPT) { + SpaceScript *sc = curarea->spacedata.first; + sc->script = G.main->script.first; /* can be null, which is ok ... */ + /* ... meaning no other script is running right now. */ + } + } } diff --git a/source/blender/python/api2_2x/Blender.h b/source/blender/python/api2_2x/Blender.h index f44df3e3cb0..12417651637 100644 --- a/source/blender/python/api2_2x/Blender.h +++ b/source/blender/python/api2_2x/Blender.h @@ -93,10 +93,10 @@ char Blender_Quit_doc[] = /* Python method structure definition. */ /*****************************************************************************/ struct PyMethodDef Blender_methods[] = { - {"Set", &Blender_Set, METH_VARARGS, Blender_Set_doc}, - {"Get", &Blender_Get, METH_VARARGS, Blender_Get_doc}, - {"Redraw", &Blender_Redraw, METH_VARARGS, Blender_Redraw_doc}, - {"Quit", &Blender_Quit, METH_NOARGS, Blender_Quit_doc}, + {"Set", Blender_Set, METH_VARARGS, Blender_Set_doc}, + {"Get", Blender_Get, METH_VARARGS, Blender_Get_doc}, + {"Redraw", Blender_Redraw, METH_VARARGS, Blender_Redraw_doc}, + {"Quit", (PyCFunction)Blender_Quit, METH_NOARGS, Blender_Quit_doc}, {"ReleaseGlobalDict", &Blender_ReleaseGlobalDict, METH_VARARGS, Blender_ReleaseGlobalDict_doc}, {NULL, NULL} diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c index bd1494dbe51..4667cb9e07f 100644 --- a/source/blender/python/api2_2x/Draw.c +++ b/source/blender/python/api2_2x/Draw.c @@ -63,10 +63,10 @@ #include "BIF_mywindow.h" #include "BIF_toolbox.h" -#include "BPI_script.h" /* script struct */ +#include "BPI_script.h" /* script struct */ #include "interface.h" -#include "mydevice.h" /*@ for all the event constants */ +#include "mydevice.h" /*@ for all the event constants */ /* This one was an extern in BPY_main.h, but only opy_draw.c was using it */ int g_window_redrawn; @@ -74,23 +74,21 @@ int g_window_redrawn; /*@ hack to flag that window redraw has happened inside slider callback: */ int EXPP_disable_force_draw = 0; -/* - * forward declarations for internal functions - */ -static void Button_dealloc (PyObject * self); -static PyObject *Button_getattr (PyObject * self, char *name); -static PyObject *Button_repr (PyObject * self); -static int Button_setattr (PyObject * self, char *name, PyObject * v); +/* forward declarations for internal functions */ +static void Button_dealloc (PyObject *self); +static PyObject *Button_getattr (PyObject *self, char *name); +static PyObject *Button_repr (PyObject *self); +static int Button_setattr (PyObject *self, char *name, PyObject *v); static Button *newbutton (void); /* GUI interface routines */ -static void exit_pydraw (SpaceScript * sc, short error); -static void exec_callback (SpaceScript * sc, PyObject * callback, - PyObject * args); -static void spacescript_do_pywin_buttons (SpaceScript * sc, - unsigned short event); +static void exit_pydraw (SpaceScript *sc, short error); +static void exec_callback (SpaceScript *sc, PyObject *callback, + PyObject *args); +static void spacescript_do_pywin_buttons (SpaceScript *sc, + unsigned short event); static PyObject *Method_Exit (PyObject * self, PyObject * args); static PyObject *Method_Register (PyObject * self, PyObject * args); @@ -115,13 +113,13 @@ static void py_slider_update (void *butv, void *data2_unused); static char Draw_doc[] = "The Blender.Draw submodule"; static char Method_Register_doc[] = - "(draw, event, button) - Register callbacks for windowing\n\n\ +"(draw, event, button) - Register callbacks for windowing\n\n\ (draw) A function to draw the screen, taking no arguments\n\ (event) A function to handle events, taking 2 arguments (evt, val)\n\ - (evt) The event number\n\ - (val) The value modifier (for key and mouse press/release)\n\ + (evt) The event number\n\ + (val) The value modifier (for key and mouse press/release)\n\ (button) A function to handle button events, taking 1 argument (evt)\n\ - (evt) The button number\n\n\ + (evt) The button number\n\n\ A None object can be passed if a callback is unused."; @@ -137,12 +135,12 @@ exactly once for everytime this function is called."; static char Method_Create_doc[] = - "(value) - Create a default Button object\n\n\ +"(value) - Create a default Button object\n\n\ (value) - The value to store in the button\n\n\ Valid values are ints, floats, and strings"; static char Method_Button_doc[] = - "(name, event, x, y, width, height, [tooltip]) - Create a new Button \ +"(name, event, x, y, width, height, [tooltip]) - Create a new Button \ (push) button\n\n\ (name) A string to display on the button\n\ (event) The event number to pass to the button event function when activated\n\ @@ -151,7 +149,7 @@ static char Method_Button_doc[] = [tooltip=] The button's tooltip"; static char Method_Menu_doc[] = - "(name, event, x, y, width, height, default, [tooltip]) - Create a new Menu \ +"(name, event, x, y, width, height, default, [tooltip]) - Create a new Menu \ button\n\n\ (name) A string to display on the button\n\ (event) The event number to pass to the button event function when activated\n\ @@ -163,11 +161,11 @@ The menu options are specified through the name of the\n\ button. Options are followed by a format code and separated\n\ by the '|' (pipe) character.\n\ Valid format codes are\n\ - %t - The option should be used as the title\n\ - %xN - The option should set the integer N in the button value."; + %t - The option should be used as the title\n\ + %xN - The option should set the integer N in the button value."; static char Method_Toggle_doc[] = - "(name, event, x, y, width, height, default, [tooltip]) - Create a new Toggle \ +"(name, event, x, y, width, height, default, [tooltip]) - Create a new Toggle \ button\n\n\ (name) A string to display on the button\n\ (event) The event number to pass to the button event function when activated\n\ @@ -178,33 +176,33 @@ button\n\n\ static char Method_Slider_doc[] = - "(name, event, x, y, width, height, initial, min, max, [update, tooltip]) - \ +"(name, event, x, y, width, height, initial, min, max, [update, tooltip]) - \ Create a new Slider button\n\n\ (name) A string to display on the button\n\ (event) The event number to pass to the button event function when activated\n\ (x, y) The lower left coordinate of the button\n\ (width, height) The button width and height\n\ (initial, min, max) Three values (int or float) specifying the initial \ - and limit values.\n\ + and limit values.\n\ [update=1] A value controlling whether the slider will emit events as it \ is edited.\n\ - A non-zero value (default) enables the events. A zero value supresses them.\n\ + A non-zero value (default) enables the events. A zero value supresses them.\n\ [tooltip=] The button's tooltip"; static char Method_Scrollbar_doc[] = - "(event, x, y, width, height, initial, min, max, [update, tooltip]) - Create a \ +"(event, x, y, width, height, initial, min, max, [update, tooltip]) - Create a \ new Scrollbar\n\n\ (event) The event number to pass to the button event function when activated\n\ (x, y) The lower left coordinate of the button\n\ (width, height) The button width and height\n\ (initial, min, max) Three values (int or float) specifying the initial and limit values.\n\ [update=1] A value controlling whether the slider will emit events as it is edited.\n\ - A non-zero value (default) enables the events. A zero value supresses them.\n\ + A non-zero value (default) enables the events. A zero value supresses them.\n\ [tooltip=] The button's tooltip"; static char Method_Number_doc[] = - "(name, event, x, y, width, height, initial, min, max, [tooltip]) - Create a \ +"(name, event, x, y, width, height, initial, min, max, [tooltip]) - Create a \ new Number button\n\n\ (name) A string to display on the button\n\ (event) The event number to pass to the button event function when activated\n\ @@ -215,7 +213,7 @@ limit values.\n\ [tooltip=] The button's tooltip"; static char Method_String_doc[] = - "(name, event, x, y, width, height, initial, length, [tooltip]) - Create a \ +"(name, event, x, y, width, height, initial, length, [tooltip]) - Create a \ new String button\n\n\ (name) A string to display on the button\n\ (event) The event number to pass to the button event function when activated\n\ @@ -225,30 +223,26 @@ new String button\n\n\ (length) The maximum input length\n\ [tooltip=] The button's tooltip"; - static char Method_GetStringWidth_doc[] = - "(text, font = 'normal') - Return the width in pixels of the given string\n\ +"(text, font = 'normal') - Return the width in pixels of the given string\n\ (font) The font size: 'normal' (default), 'small' or 'tiny'."; - - static char Method_Text_doc[] = - "(text, font = 'normal') - Draw text onscreen\n\n\ +"(text, font = 'normal') - Draw text onscreen\n\n\ (text) The text to draw\n\ (font) The font size: 'normal' (default), 'small' or 'tiny'.\n\n\ -NEW! - This function now returns the width of the drawn string."; - +This function returns the width of the drawn string."; static char Method_PupMenu_doc[] = - "(string, maxrow = None) - Display a pop-up menu at the screen.\n\ +"(string, maxrow = None) - Display a pop-up menu at the screen.\n\ The contents of the pop-up are specified through the 'string' argument,\n\ like with Draw.Menu.\n\ 'maxrow' is an optional int to control how many rows the pop-up should have.\n\ Options are followed by a format code and separated\n\ by the '|' (pipe) character.\n\ Valid format codes are\n\ - %t - The option should be used as the title\n\ - %xN - The option should set the integer N in the button value.\n\n\ + %t - The option should be used as the title\n\ + %xN - The option should set the integer N in the button value.\n\n\ Ex: Draw.PupMenu('OK?%t|QUIT BLENDER') # should be familiar ..."; static char Method_Exit_doc[] = "() - Exit the windowing interface"; @@ -258,7 +252,7 @@ static char Method_Exit_doc[] = "() - Exit the windowing interface"; */ #define _MethodDef(func, prefix) \ - {#func, prefix##_##func, METH_VARARGS, prefix##_##func##_doc} + {#func, prefix##_##func, METH_VARARGS, prefix##_##func##_doc} /* So that _MethodDef(delete, Scene) expands to: * {"delete", Scene_delete, METH_VARARGS, Scene_delete_doc} */ @@ -267,174 +261,158 @@ static char Method_Exit_doc[] = "() - Exit the windowing interface"; #define MethodDef(func) _MethodDef(func, Method) static struct PyMethodDef Draw_methods[] = { - MethodDef (Create), - MethodDef (Button), - MethodDef (Toggle), - MethodDef (Menu), - MethodDef (Slider), - MethodDef (Scrollbar), - MethodDef (Number), - MethodDef (String), - MethodDef (GetStringWidth), - MethodDef (Text), - MethodDef (PupMenu), - MethodDef (Exit), - MethodDef (Redraw), - MethodDef (Draw), - MethodDef (Register), - {NULL, NULL} + MethodDef (Create), + MethodDef (Button), + MethodDef (Toggle), + MethodDef (Menu), + MethodDef (Slider), + MethodDef (Scrollbar), + MethodDef (Number), + MethodDef (String), + MethodDef (GetStringWidth), + MethodDef (Text), + MethodDef (PupMenu), + MethodDef (Exit), + MethodDef (Redraw), + MethodDef (Draw), + MethodDef (Register), + {NULL, NULL} }; PyTypeObject Button_Type = { - PyObject_HEAD_INIT (NULL) 0, /*ob_size */ - "Button", /*tp_name */ - sizeof (Button), /*tp_basicsize */ - 0, /*tp_itemsize */ - (destructor) Button_dealloc, /*tp_dealloc */ - (printfunc) 0, /*tp_print */ - (getattrfunc) Button_getattr, /*tp_getattr */ - (setattrfunc) Button_setattr, /*tp_setattr */ - (cmpfunc) 0, /*tp_cmp */ - (reprfunc) Button_repr, /*tp_repr */ + PyObject_HEAD_INIT (NULL) 0, /*ob_size */ + "Button", /*tp_name */ + sizeof (Button), /*tp_basicsize */ + 0, /*tp_itemsize */ + (destructor) Button_dealloc, /*tp_dealloc */ + (printfunc) 0, /*tp_print */ + (getattrfunc) Button_getattr, /*tp_getattr */ + (setattrfunc) Button_setattr, /*tp_setattr */ + (cmpfunc) 0, /*tp_cmp */ + (reprfunc) Button_repr, /*tp_repr */ }; -static void -Button_dealloc (PyObject * self) +static void Button_dealloc (PyObject *self) { - Button *but = (Button *) self; + Button *but = (Button *) self; - if (but->type == 3) - MEM_freeN (but->val.asstr); + if (but->type == 3) MEM_freeN (but->val.asstr); - PyObject_DEL (self); + PyObject_DEL (self); } -static PyObject * -Button_getattr (PyObject * self, char *name) +static PyObject *Button_getattr (PyObject *self, char *name) { - Button *but = (Button *) self; - - if (strcmp (name, "val") == 0) - { - if (but->type == 1) - return Py_BuildValue ("i", but->val.asint); - else if (but->type == 2) - return Py_BuildValue ("f", but->val.asfloat); - else if (but->type == 3) - return Py_BuildValue ("s", but->val.asstr); - } - - PyErr_SetString (PyExc_AttributeError, name); - return NULL; + Button *but = (Button *) self; + + if (strcmp (name, "val") == 0) { + if (but->type == 1) + return Py_BuildValue ("i", but->val.asint); + else if (but->type == 2) + return Py_BuildValue ("f", but->val.asfloat); + else if (but->type == 3) + return Py_BuildValue ("s", but->val.asstr); + } + + PyErr_SetString (PyExc_AttributeError, name); + return NULL; } -static int -Button_setattr (PyObject * self, char *name, PyObject * v) +static int Button_setattr (PyObject *self, char *name, PyObject *v) { - Button *but = (Button *) self; - - if (strcmp (name, "val") == 0) - { - if (but->type == 1) - PyArg_Parse (v, "i", &but->val.asint); - else if (but->type == 2) - PyArg_Parse (v, "f", &but->val.asfloat); - else if (but->type == 3) - { - char *newstr; - PyArg_Parse (v, "s", &newstr); - - /* if the length of the new string is the same as */ - /* the old one, just copy, else delete and realloc. */ - if (but->slen == strlen (newstr)) - { - strncpy (but->val.asstr, newstr, but->slen); - } - else - { - MEM_freeN (but->val.asstr); - but->slen = strlen (newstr); - but->val.asstr = MEM_mallocN (but->slen + 1, "button setattr"); - strcpy (but->val.asstr, newstr); - } + Button *but = (Button *) self; + + if (strcmp (name, "val") == 0) { + if (but->type == 1) + PyArg_Parse (v, "i", &but->val.asint); + else if (but->type == 2) + PyArg_Parse (v, "f", &but->val.asfloat); + else if (but->type == 3) { + char *newstr; + PyArg_Parse (v, "s", &newstr); + + /* if the length of the new string is the same as */ + /* the old one, just copy, else delete and realloc. */ + if (but->slen == strlen (newstr)) { + strncpy (but->val.asstr, newstr, but->slen); + } + else { + MEM_freeN (but->val.asstr); + but->slen = strlen (newstr); + but->val.asstr = MEM_mallocN (but->slen + 1, "button setattr"); + strcpy (but->val.asstr, newstr); + } + } } - } - else - { - PyErr_SetString (PyExc_AttributeError, name); - return -1; - } - - return 0; + else { + PyErr_SetString (PyExc_AttributeError, name); + return -1; + } + + return 0; } -static PyObject * -Button_repr (PyObject * self) +static PyObject *Button_repr (PyObject * self) { - return PyObject_Repr (Button_getattr (self, "val")); + return PyObject_Repr (Button_getattr (self, "val")); } -static Button * -newbutton (void) +static Button *newbutton (void) { - Button *but = (Button *) PyObject_NEW (Button, &Button_Type); + Button *but = (Button *) PyObject_NEW (Button, &Button_Type); - return but; + return but; } /* GUI interface routines */ -static void -exit_pydraw (SpaceScript * sc, short err) +static void exit_pydraw (SpaceScript *sc, short err) { - Script *script = NULL; + Script *script = NULL; - if (!sc || !sc->script) - return; + if (!sc || !sc->script) return; - script = sc->script; + script = sc->script; - if (err) - { - PyErr_Print (); - script->flags = 0; /* mark script struct for deletion */ - error ("Python script error: check console"); - scrarea_queue_redraw (sc->area); - } + if (err) { + PyErr_Print (); + script->flags = 0; /* mark script struct for deletion */ + error ("Python script error: check console"); + scrarea_queue_redraw (sc->area); + } - Py_XDECREF ((PyObject *) script->py_draw); - Py_XDECREF ((PyObject *) script->py_event); - Py_XDECREF ((PyObject *) script->py_button); + Py_XDECREF ((PyObject *) script->py_draw); + Py_XDECREF ((PyObject *) script->py_event); + Py_XDECREF ((PyObject *) script->py_button); - script->py_draw = script->py_event = script->py_button = NULL; + script->py_draw = script->py_event = script->py_button = NULL; } -static void -exec_callback (SpaceScript * sc, PyObject * callback, PyObject * args) +static void exec_callback (SpaceScript *sc, PyObject *callback, PyObject *args) { - PyObject *result = PyObject_CallObject (callback, args); - - if (result == NULL && sc->script) - { /* errors in the script */ - if (sc->script->lastspace == SPACE_TEXT) - { /*if it can be an ALT+P script */ - Text *text = G.main->text.first; - while (text) - { /* find it and free its compiled code */ - if (!strcmp (text->id.name + 2, sc->script->id.name + 2)) - { - BPY_free_compiled_text (text); - break; + PyObject *result = PyObject_CallObject (callback, args); + + if (result == NULL && sc->script) {/* errors in the script */ + + if (sc->script->lastspace == SPACE_TEXT) {/*if it can be an ALT+P script */ + Text *text = G.main->text.first; + + while (text) {/* find it and free its compiled code */ + + if (!strcmp (text->id.name + 2, sc->script->id.name + 2)) { + BPY_free_compiled_text (text); + break; + } + + text = text->id.next; + } } - text = text->id.next; - } + exit_pydraw (sc, 1); } - exit_pydraw (sc, 1); - } - Py_XDECREF (result); - Py_DECREF (args); + Py_XDECREF (result); + Py_DECREF (args); } /* BPY_spacescript_do_pywin_draw, the static spacescript_do_pywin_buttons and @@ -443,98 +421,106 @@ exec_callback (SpaceScript * sc, PyObject * callback, PyObject * args) * (see Method_Register below). They are called (only the two BPY_ ones) * from blender/src/drawscript.c */ -void -BPY_spacescript_do_pywin_draw (SpaceScript * sc) +void BPY_spacescript_do_pywin_draw (SpaceScript *sc) { - uiBlock *block; - char butblock[20]; - Script *script = sc->script; - - sprintf (butblock, "win %d", curarea->win); - block = uiNewBlock (&curarea->uiblocks, butblock, UI_EMBOSSX, - UI_HELV, curarea->win); - - if (script->py_draw) - { - glPushAttrib (GL_ALL_ATTRIB_BITS); - exec_callback (sc, script->py_draw, Py_BuildValue ("()")); - glPopAttrib (); - } - else - { - glClearColor (0.4375, 0.4375, 0.4375, 0.0); - glClear (GL_COLOR_BUFFER_BIT); - } - - uiDrawBlock (block); - - curarea->win_swap = WIN_BACK_OK; + uiBlock *block; + char butblock[20]; + Script *script = sc->script; + + sprintf (butblock, "win %d", curarea->win); + block = uiNewBlock (&curarea->uiblocks, butblock, UI_EMBOSSX, + UI_HELV, curarea->win); + + if (script->py_draw) { + glPushAttrib (GL_ALL_ATTRIB_BITS); + exec_callback (sc, script->py_draw, Py_BuildValue ("()")); + glPopAttrib (); + } + else { + glClearColor (0.4375, 0.4375, 0.4375, 0.0); + glClear (GL_COLOR_BUFFER_BIT); + } + + uiDrawBlock (block); + + curarea->win_swap = WIN_BACK_OK; } -static void -spacescript_do_pywin_buttons (SpaceScript * sc, unsigned short event) +static void spacescript_do_pywin_buttons (SpaceScript *sc, unsigned short event) { - if (sc->script->py_button) - { - exec_callback (sc, sc->script->py_button, Py_BuildValue ("(i)", event)); - } + if (sc->script->py_button) + exec_callback (sc, sc->script->py_button, Py_BuildValue ("(i)", event)); } -void -BPY_spacescript_do_pywin_event (SpaceScript * sc, unsigned short event, - short val) +void BPY_spacescript_do_pywin_event (SpaceScript *sc, unsigned short event, + short val) { - if (event == QKEY && G.qual & (LR_ALTKEY | LR_CTRLKEY)) - { - /* finish script: user pressed ALT+Q or CONTROL+Q */ - Script *script = sc->script; + static int menu_hack = 0; + + /* about menu_hack above: when a menu returns after an entry is chosen, + * two events are generated, the second one with val = 4. We don't want + * this second one to be passed to Python, because it can be confused with + * some event with same number defined by the script. + * What we do is set menu_hack to 1 if a button event occurs. + * Then if the next one is also a button event, w/ val = 4, we discard it. */ + + if (event != UI_BUT_EVENT || !val) menu_hack = 0; - exit_pydraw (sc, 0); + if (event == QKEY && G.qual & (LR_ALTKEY | LR_CTRLKEY)) { + /* finish script: user pressed ALT+Q or CONTROL+Q */ + Script *script = sc->script; - script->flags &= ~SCRIPT_GUI; /* we're done with this script */ + exit_pydraw (sc, 0); - return; - } + script->flags &= ~SCRIPT_GUI; /* we're done with this script */ - if (val) - { - if (uiDoBlocks (&curarea->uiblocks, event) != UI_NOTHING) - event = 0; + return; + } + + if (val) { + if (uiDoBlocks (&curarea->uiblocks, event) != UI_NOTHING) event = 0; - if (event == UI_BUT_EVENT) - spacescript_do_pywin_buttons (sc, val); - } + if (event == UI_BUT_EVENT) { - if (sc->script->py_event) - exec_callback (sc, sc->script->py_event, - Py_BuildValue ("(ii)", event, val)); + if (menu_hack && (val == 4)) { /* "false" event? */ + menu_hack = 0; /* if so, discard it and clear menu_hack */ + } + else { + menu_hack = 1; + spacescript_do_pywin_buttons (sc, val); + } + + } + } + + if (sc->script->py_event) + exec_callback (sc, sc->script->py_event, Py_BuildValue("(ii)", event, val)); } -static PyObject * -Method_Exit (PyObject * self, PyObject * args) +static PyObject *Method_Exit (PyObject *self, PyObject *args) { - SpaceScript *sc; - Script *script; + SpaceScript *sc; + Script *script; - /* if users call Draw.Exit when we are already out of the SPACE_SCRIPT, we - * simply return, for compatibility */ - if (curarea->spacetype == SPACE_SCRIPT) - sc = curarea->spacedata.first; - else - return EXPP_incr_ret (Py_None); + /* if users call Draw.Exit when we are already out of the SPACE_SCRIPT, we + * simply return, for compatibility */ + if (curarea->spacetype == SPACE_SCRIPT) + sc = curarea->spacedata.first; + else + return EXPP_incr_ret (Py_None); - if (!PyArg_ParseTuple (args, "")) - return EXPP_ReturnPyObjError (PyExc_AttributeError, - "expected empty argument list"); + if (!PyArg_ParseTuple (args, "")) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected empty argument list"); - exit_pydraw (sc, 0); + exit_pydraw (sc, 0); - script = sc->script; + script = sc->script; - /* remove our lock to the current namespace */ - script->flags &= ~SCRIPT_GUI; + /* remove our lock to the current namespace */ + script->flags &= ~SCRIPT_GUI; - return EXPP_incr_ret (Py_None); + return EXPP_incr_ret (Py_None); } /* Method_Register (Draw.Register) registers callbacks for drawing, events @@ -543,243 +529,229 @@ Method_Exit (PyObject * self, PyObject * args) * the SPACE_SCRIPT window with this script is redrawn, the registered * callbacks are executed and deleted (a new call to Register re-inserts them * or new ones).*/ -static PyObject * -Method_Register (PyObject * self, PyObject * args) +static PyObject *Method_Register (PyObject *self, PyObject *args) { - PyObject *newdrawc = NULL, *neweventc = NULL, *newbuttonc = NULL; - SpaceScript *sc; - Script *script; - int startspace = 0; - - if (!PyArg_ParseTuple (args, "O|OO", &newdrawc, &neweventc, &newbuttonc)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected one or three PyObjects"); - - if (!PyCallable_Check (newdrawc)) - newdrawc = NULL; - if (!PyCallable_Check (neweventc)) - neweventc = NULL; - if (!PyCallable_Check (newbuttonc)) - newbuttonc = NULL; - - if (!(newdrawc || neweventc || newbuttonc)) - return EXPP_incr_ret (Py_None); - - startspace = curarea->spacetype; - - /* first make sure the current area is of type SPACE_SCRIPT */ - if (startspace != SPACE_SCRIPT) - newspace (curarea, SPACE_SCRIPT); - - sc = curarea->spacedata.first; - - /* this is a little confusing: we need to know which script is being executed - * now, so we can preserve its namespace from being deleted. - * There are two possibilities: - * a) One new script was created and the interpreter still hasn't returned - * from executing it. - * b) Any number of scripts were executed but left registered callbacks and - * so were not deleted yet. */ - - /* To find out if we're dealing with a) or b), we start with the last - * created one: */ - script = G.main->script.last; - - if (!script) - { - return EXPP_ReturnPyObjError (PyExc_RuntimeError, - "Draw.Register: couldn't get pointer to script struct"); - } - - /* if the flag SCRIPT_RUNNING is set, this script is case a): */ - if (!(script->flags & SCRIPT_RUNNING)) - { - script = sc->script; - } - /* otherwise it's case b) and the script we want is here: */ - else - sc->script = script; - - /* Now we have the right script and can set a lock so its namespace can't be - * deleted for as long as we need it */ - script->flags |= SCRIPT_GUI; - - /* save the last space so we can go back to it upon finishing */ - if (!script->lastspace) - script->lastspace = startspace; - - /* clean the old callbacks */ - exit_pydraw (sc, 0); - - /* prepare the new ones and insert them */ - Py_XINCREF (newdrawc); - Py_XINCREF (neweventc); - Py_XINCREF (newbuttonc); - - script->py_draw = newdrawc; - script->py_event = neweventc; - script->py_button = newbuttonc; - - scrarea_queue_redraw (sc->area); - - return EXPP_incr_ret (Py_None); + PyObject *newdrawc = NULL, *neweventc = NULL, *newbuttonc = NULL; + SpaceScript *sc; + Script *script; + int startspace = 0; + + if (!PyArg_ParseTuple (args, "O|OO", &newdrawc, &neweventc, &newbuttonc)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected one or three PyObjects"); + + if (!PyCallable_Check (newdrawc)) + newdrawc = NULL; + if (!PyCallable_Check (neweventc)) + neweventc = NULL; + if (!PyCallable_Check (newbuttonc)) + newbuttonc = NULL; + + if (!(newdrawc || neweventc || newbuttonc)) + return EXPP_incr_ret (Py_None); + + startspace = curarea->spacetype; + + /* first make sure the current area is of type SPACE_SCRIPT */ + if (startspace != SPACE_SCRIPT) + newspace (curarea, SPACE_SCRIPT); + + sc = curarea->spacedata.first; + + /* this is a little confusing: we need to know which script is being executed + * now, so we can preserve its namespace from being deleted. + * There are two possibilities: + * a) One new script was created and the interpreter still hasn't returned + * from executing it. + * b) Any number of scripts were executed but left registered callbacks and + * so were not deleted yet. */ + + /* To find out if we're dealing with a) or b), we start with the last + * created one: */ + script = G.main->script.last; + + if (!script) { + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "Draw.Register: couldn't get pointer to script struct"); + } + + /* if the flag SCRIPT_RUNNING is set, this script is case a): */ + if (!(script->flags & SCRIPT_RUNNING)) { + script = sc->script; + } + /* otherwise it's case b) and the script we want is here: */ + else + sc->script = script; + + /* Now we have the right script and can set a lock so its namespace can't be + * deleted for as long as we need it */ + script->flags |= SCRIPT_GUI; + + /* save the last space so we can go back to it upon finishing */ + if (!script->lastspace) + script->lastspace = startspace; + + /* clean the old callbacks */ + exit_pydraw (sc, 0); + + /* prepare the new ones and insert them */ + Py_XINCREF (newdrawc); + Py_XINCREF (neweventc); + Py_XINCREF (newbuttonc); + + script->py_draw = newdrawc; + script->py_event = neweventc; + script->py_button = newbuttonc; + + scrarea_queue_redraw (sc->area); + + return EXPP_incr_ret (Py_None); } -static PyObject * -Method_Redraw (PyObject * self, PyObject * args) +static PyObject *Method_Redraw (PyObject *self, PyObject *args) { - int after = 0; + int after = 0; - if (!PyArg_ParseTuple (args, "|i", &after)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected int argument (or nothing)"); + if (!PyArg_ParseTuple (args, "|i", &after)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected int argument (or nothing)"); - /* XXX shouldn't we redraw all spacescript wins with this script on ? */ - if (after) - addafterqueue (curarea->win, REDRAW, 1); - else - scrarea_queue_winredraw (curarea); + /* XXX shouldn't we redraw all spacescript wins with this script on ? */ + if (after) + addafterqueue (curarea->win, REDRAW, 1); + else + scrarea_queue_winredraw (curarea); - return EXPP_incr_ret (Py_None); + return EXPP_incr_ret (Py_None); } -static PyObject * -Method_Draw (PyObject * self, PyObject * args) +static PyObject *Method_Draw (PyObject * self, PyObject * args) { - /*@ If forced drawing is disable queue a redraw event instead */ - if (EXPP_disable_force_draw) - { - scrarea_queue_winredraw (curarea); - return EXPP_incr_ret (Py_None); - } + /*@ If forced drawing is disable queue a redraw event instead */ + if (EXPP_disable_force_draw) { + scrarea_queue_winredraw (curarea); + return EXPP_incr_ret (Py_None); + } - if (!PyArg_ParseTuple (args, "")) - return EXPP_ReturnPyObjError (PyExc_AttributeError, - "expected empty argument list"); + if (!PyArg_ParseTuple (args, "")) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected empty argument list"); - scrarea_do_windraw (curarea); + scrarea_do_windraw (curarea); - screen_swapbuffers (); + screen_swapbuffers (); - return EXPP_incr_ret (Py_None); + return EXPP_incr_ret (Py_None); } -static PyObject * -Method_Create (PyObject * self, PyObject * args) +static PyObject *Method_Create (PyObject *self, PyObject *args) { - Button *but; - PyObject *in; - - if (!PyArg_ParseTuple (args, "O", &in)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected PyObject argument"); - - but = newbutton (); - if (PyFloat_Check (in)) - { - but->type = 2; - but->val.asfloat = PyFloat_AsDouble (in); - } - else if (PyInt_Check (in)) - { - but->type = 1; - but->val.asint = PyInt_AsLong (in); - } - else if (PyString_Check (in)) - { - char *newstr = PyString_AsString (in); - - but->type = 3; - but->slen = strlen (newstr); - but->val.asstr = MEM_mallocN (but->slen + 1, "button string"); - - strcpy (but->val.asstr, newstr); - } - - return (PyObject *) but; + Button *but; + PyObject *in; + + if (!PyArg_ParseTuple (args, "O", &in)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected PyObject argument"); + + but = newbutton (); + if (PyFloat_Check (in)) { + but->type = 2; + but->val.asfloat = PyFloat_AsDouble (in); + } + else if (PyInt_Check (in)) { + but->type = 1; + but->val.asint = PyInt_AsLong (in); + } + else if (PyString_Check (in)) { + char *newstr = PyString_AsString (in); + + but->type = 3; + but->slen = strlen (newstr); + but->val.asstr = MEM_mallocN (but->slen + 1, "button string"); + + strcpy (but->val.asstr, newstr); + } + + return (PyObject *) but; } -static uiBlock * -Get_uiBlock (void) +static uiBlock *Get_uiBlock (void) { - char butblock[32]; + char butblock[32]; - sprintf (butblock, "win %d", curarea->win); + sprintf (butblock, "win %d", curarea->win); - return uiGetBlock (butblock, curarea); + return uiGetBlock (butblock, curarea); } -static PyObject * -Method_Button (PyObject * self, PyObject * args) +static PyObject *Method_Button (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip = NULL; - int event; - int x, y, w, h; + uiBlock *block; + char *name, *tip = NULL; + int event; + int x, y, w, h; - if (!PyArg_ParseTuple (args, "siiiii|s", &name, &event, - &x, &y, &w, &h, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, five ints and optionally another string as arguments"); + if (!PyArg_ParseTuple (args, "siiiii|s", &name, &event, + &x, &y, &w, &h, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, five ints and optionally another string as arguments"); - block = Get_uiBlock (); + block = Get_uiBlock (); - if (block) - uiDefBut (block, BUT, event, name, x, y, w, h, 0, 0, 0, 0, 0, tip); + if (block) + uiDefBut (block, BUT, event, name, x, y, w, h, 0, 0, 0, 0, 0, tip); - return EXPP_incr_ret (Py_None); + return EXPP_incr_ret (Py_None); } -static PyObject * -Method_Menu (PyObject * self, PyObject * args) +static PyObject *Method_Menu (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip = NULL; - int event, def; - int x, y, w, h; - Button *but; + uiBlock *block; + char *name, *tip = NULL; + int event, def; + int x, y, w, h; + Button *but; - if (!PyArg_ParseTuple (args, "siiiiii|s", &name, &event, + if (!PyArg_ParseTuple (args, "siiiiii|s", &name, &event, &x, &y, &w, &h, &def, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, six ints and optionally another string as arguments"); + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, six ints and optionally another string as arguments"); - but = newbutton (); - but->type = 1; - but->val.asint = def; + but = newbutton (); + but->type = 1; + but->val.asint = def; - block = Get_uiBlock (); - if (block) - uiDefButI (block, MENU, event, name, x, y, w, h, - &but->val.asint, 0, 0, 0, 0, tip); + block = Get_uiBlock (); + if (block) + uiDefButI (block, MENU, event, name, x, y, w, h, + &but->val.asint, 0, 0, 0, 0, tip); - return (PyObject *) but; + return (PyObject *) but; } -static PyObject * -Method_Toggle (PyObject * self, PyObject * args) +static PyObject *Method_Toggle (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip = NULL; - int event; - int x, y, w, h, def; - Button *but; + uiBlock *block; + char *name, *tip = NULL; + int event; + int x, y, w, h, def; + Button *but; - if (!PyArg_ParseTuple (args, "siiiiii|s", &name, &event, + if (!PyArg_ParseTuple (args, "siiiiii|s", &name, &event, &x, &y, &w, &h, &def, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, six ints and optionally another string as arguments"); + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, six ints and optionally another string as arguments"); - but = newbutton (); - but->type = 1; - but->val.asint = def; + but = newbutton (); + but->type = 1; + but->val.asint = def; - block = Get_uiBlock (); - if (block) - uiDefButI (block, TOG, event, name, x, y, w, h, - &but->val.asint, 0, 0, 0, 0, tip); + block = Get_uiBlock (); + if (block) + uiDefButI (block, TOG, event, name, x, y, w, h, + &but->val.asint, 0, 0, 0, 0, tip); - return (PyObject *) but; + return (PyObject *) but; } /*@DO NOT TOUCH THIS FUNCTION ! @@ -789,467 +761,445 @@ Method_Toggle (PyObject * self, PyObject * args) XXX This is condemned to be dinosource in future - it's a hack. */ -static void -py_slider_update (void *butv, void *data2_unused) +static void py_slider_update (void *butv, void *data2_unused) { - uiBut *but = butv; + uiBut *but = butv; - EXPP_disable_force_draw = 1; - /*@ - Disable forced drawing, otherwise the button object which - is still being used might be deleted - */ + EXPP_disable_force_draw = 1; + /*@ + Disable forced drawing, otherwise the button object which + is still being used might be deleted + */ - /*@ - spacetext_do_pywin_buttons(curarea->spacedata.first, but->retval); */ + /*@ + spacetext_do_pywin_buttons(curarea->spacedata.first, but->retval); */ - g_window_redrawn = 0; - curarea->win_swap = WIN_BACK_OK; - /* removed global uiFrontBuf (contact ton when this goes wrong here) */ - spacescript_do_pywin_buttons (curarea->spacedata.first, + g_window_redrawn = 0; + curarea->win_swap = WIN_BACK_OK; + /* removed global uiFrontBuf (contact ton when this goes wrong here) */ + spacescript_do_pywin_buttons (curarea->spacedata.first, uiButGetRetVal (but)); - if (!g_window_redrawn) - { /*@ if Redraw already called */ - disable_where_script (1); - M_Window_Redraw (0, Py_BuildValue ("(i)", SPACE_VIEW3D)); - disable_where_script (0); - } + if (!g_window_redrawn) { /*@ if Redraw already called */ + disable_where_script (1); + M_Window_Redraw (0, Py_BuildValue ("(i)", SPACE_VIEW3D)); + disable_where_script (0); + } - EXPP_disable_force_draw = 0; + EXPP_disable_force_draw = 0; } -static PyObject * -Method_Slider (PyObject * self, PyObject * args) +static PyObject *Method_Slider (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip = NULL; - int event; - int x, y, w, h, realtime = 1; - Button *but; - PyObject *mino, *maxo, *inio; - - if (!PyArg_ParseTuple (args, "siiiiiOOO|is", &name, &event, - &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, - &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, five ints, three PyObjects\n\ + uiBlock *block; + char *name, *tip = NULL; + int event; + int x, y, w, h, realtime = 1; + Button *but; + PyObject *mino, *maxo, *inio; + + if (!PyArg_ParseTuple (args, "siiiiiOOO|is", &name, &event, + &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, five ints, three PyObjects\n\ and optionally another int and string as arguments"); - but = newbutton (); + but = newbutton (); - if (PyFloat_Check (inio)) - { - float ini, min, max; + if (PyFloat_Check (inio)) { + float ini, min, max; - ini = PyFloat_AsDouble (inio); - min = PyFloat_AsDouble (mino); - max = PyFloat_AsDouble (maxo); + ini = PyFloat_AsDouble (inio); + min = PyFloat_AsDouble (mino); + max = PyFloat_AsDouble (maxo); - but->type = 2; - but->val.asfloat = ini; + but->type = 2; + but->val.asfloat = ini; - block = Get_uiBlock (); - if (block) - { - uiBut *ubut; - ubut = uiDefButF (block, NUMSLI, event, name, x, y, w, h, - &but->val.asfloat, min, max, 0, 0, tip); - if (realtime) - uiButSetFunc (ubut, py_slider_update, ubut, NULL); + block = Get_uiBlock (); + if (block) { + uiBut *ubut; + ubut = uiDefButF (block, NUMSLI, event, name, x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + if (realtime) + uiButSetFunc (ubut, py_slider_update, ubut, NULL); + } } - } - else - { - int ini, min, max; - - ini = PyInt_AsLong (inio); - min = PyInt_AsLong (mino); - max = PyInt_AsLong (maxo); - - but->type = 1; - but->val.asint = ini; - - block = Get_uiBlock (); - if (block) - { - uiBut *ubut; - ubut = uiDefButI (block, NUMSLI, event, name, x, y, w, h, - &but->val.asint, min, max, 0, 0, tip); - if (realtime) - uiButSetFunc (ubut, py_slider_update, ubut, NULL); + else { + int ini, min, max; + + ini = PyInt_AsLong (inio); + min = PyInt_AsLong (mino); + max = PyInt_AsLong (maxo); + + but->type = 1; + but->val.asint = ini; + + block = Get_uiBlock (); + if (block) { + uiBut *ubut; + ubut = uiDefButI (block, NUMSLI, event, name, x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + if (realtime) + uiButSetFunc (ubut, py_slider_update, ubut, NULL); + } } - } - return (PyObject *) but; + return (PyObject *) but; } -static PyObject * -Method_Scrollbar (PyObject * self, PyObject * args) +static PyObject *Method_Scrollbar (PyObject *self, PyObject *args) { - char *tip = NULL; - uiBlock *block; - int event; - int x, y, w, h, realtime = 1; - Button *but; - PyObject *mino, *maxo, *inio; - float ini, min, max; - - if (!PyArg_ParseTuple (args, "iiiiiOOO|is", &event, &x, &y, &w, &h, + char *tip = NULL; + uiBlock *block; + int event; + int x, y, w, h, realtime = 1; + Button *but; + PyObject *mino, *maxo, *inio; + float ini, min, max; + + if (!PyArg_ParseTuple (args, "iiiiiOOO|is", &event, &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected five ints, three PyObjects and optionally\n\ + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected five ints, three PyObjects and optionally\n\ another int and string as arguments"); - if (!PyNumber_Check (inio) || !PyNumber_Check (inio) - || !PyNumber_Check (inio)) - return EXPP_ReturnPyObjError (PyExc_AttributeError, - "expected numbers for initial, min, and max"); - - but = newbutton (); - - if (PyFloat_Check (inio)) - but->type = 2; - else - but->type = 1; - - ini = PyFloat_AsDouble (inio); - min = PyFloat_AsDouble (mino); - max = PyFloat_AsDouble (maxo); - - if (but->type == 2) - { - but->val.asfloat = ini; - block = Get_uiBlock (); - if (block) - { - uiBut *ubut; - ubut = uiDefButF (block, SCROLL, event, "", x, y, w, h, - &but->val.asfloat, min, max, 0, 0, tip); - if (realtime) - uiButSetFunc (ubut, py_slider_update, ubut, NULL); + if (!PyNumber_Check (inio) || !PyNumber_Check (inio) + || !PyNumber_Check (inio)) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected numbers for initial, min, and max"); + + but = newbutton (); + + if (PyFloat_Check (inio)) + but->type = 2; + else + but->type = 1; + + ini = PyFloat_AsDouble (inio); + min = PyFloat_AsDouble (mino); + max = PyFloat_AsDouble (maxo); + + if (but->type == 2) { + but->val.asfloat = ini; + block = Get_uiBlock (); + if (block) { + uiBut *ubut; + ubut = uiDefButF (block, SCROLL, event, "", x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + if (realtime) + uiButSetFunc (ubut, py_slider_update, ubut, NULL); + } } - } - else - { - but->val.asint = ini; - block = Get_uiBlock (); - if (block) - { - uiBut *ubut; - ubut = uiDefButI (block, SCROLL, event, "", x, y, w, h, - &but->val.asint, min, max, 0, 0, tip); - if (realtime) - uiButSetFunc (ubut, py_slider_update, ubut, NULL); + else { + but->val.asint = ini; + block = Get_uiBlock (); + if (block) { + uiBut *ubut; + ubut = uiDefButI (block, SCROLL, event, "", x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + if (realtime) + uiButSetFunc (ubut, py_slider_update, ubut, NULL); + } } - } - return (PyObject *) but; + return (PyObject *) but; } -static PyObject * -Method_Number (PyObject * self, PyObject * args) +static PyObject *Method_Number (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip = NULL; - int event; - int x, y, w, h; - Button *but; - PyObject *mino, *maxo, *inio; - - if (!PyArg_ParseTuple (args, "siiiiiOOO|s", &name, &event, - &x, &y, &w, &h, &inio, &mino, &maxo, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, five ints, three PyObjects and\n\ + uiBlock *block; + char *name, *tip = NULL; + int event; + int x, y, w, h; + Button *but; + PyObject *mino, *maxo, *inio; + + if (!PyArg_ParseTuple (args, "siiiiiOOO|s", &name, &event, + &x, &y, &w, &h, &inio, &mino, &maxo, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, five ints, three PyObjects and\n\ optionally another string as arguments"); - but = newbutton (); + but = newbutton (); - if (PyFloat_Check (inio)) - { - float ini, min, max; + if (PyFloat_Check (inio)) { + float ini, min, max; - ini = PyFloat_AsDouble (inio); - min = PyFloat_AsDouble (mino); - max = PyFloat_AsDouble (maxo); + ini = PyFloat_AsDouble (inio); + min = PyFloat_AsDouble (mino); + max = PyFloat_AsDouble (maxo); - but->type = 2; - but->val.asfloat = ini; + but->type = 2; + but->val.asfloat = ini; - block = Get_uiBlock (); - if (block) - uiDefButF (block, NUM, event, name, x, y, w, h, - &but->val.asfloat, min, max, 0, 0, tip); - } - else - { - int ini, min, max; + block = Get_uiBlock (); + if (block) + uiDefButF (block, NUM, event, name, x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + } + else { + int ini, min, max; - ini = PyInt_AsLong (inio); - min = PyInt_AsLong (mino); - max = PyInt_AsLong (maxo); + ini = PyInt_AsLong (inio); + min = PyInt_AsLong (mino); + max = PyInt_AsLong (maxo); - but->type = 1; - but->val.asint = ini; + but->type = 1; + but->val.asint = ini; - block = Get_uiBlock (); - if (block) - uiDefButI (block, NUM, event, name, x, y, w, h, - &but->val.asint, min, max, 0, 0, tip); - } + block = Get_uiBlock (); + if (block) + uiDefButI (block, NUM, event, name, x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + } - return (PyObject *) but; + return (PyObject *) but; } -static PyObject * -Method_String (PyObject * self, PyObject * args) +static PyObject *Method_String (PyObject *self, PyObject *args) { - uiBlock *block; - char *name, *tip = NULL, *newstr; - int event; - int x, y, w, h, len; - Button *but; - - if (!PyArg_ParseTuple (args, "siiiiisi|s", &name, &event, - &x, &y, &w, &h, &newstr, &len, &tip)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string, five ints, a string, an int and\n\ + uiBlock *block; + char *name, *tip = NULL, *newstr; + int event; + int x, y, w, h, len; + Button *but; + + if (!PyArg_ParseTuple (args, "siiiiisi|s", &name, &event, + &x, &y, &w, &h, &newstr, &len, &tip)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string, five ints, a string, an int and\n\ optionally another string as arguments"); - but = newbutton (); - but->type = 3; - but->slen = len; - but->val.asstr = MEM_mallocN (len + 1, "button string"); + but = newbutton (); + but->type = 3; + but->slen = len; + but->val.asstr = MEM_mallocN (len + 1, "button string"); - strncpy (but->val.asstr, newstr, len); - but->val.asstr[len] = 0; + strncpy (but->val.asstr, newstr, len); + but->val.asstr[len] = 0; - block = Get_uiBlock (); - if (block) - uiDefBut (block, TEX, event, name, x, y, w, h, - but->val.asstr, 0, len, 0, 0, tip); + block = Get_uiBlock (); + if (block) + uiDefBut (block, TEX, event, name, x, y, w, h, + but->val.asstr, 0, len, 0, 0, tip); - return (PyObject *) but; + return (PyObject *) but; } -static PyObject * -Method_GetStringWidth (PyObject * self, PyObject * args) +static PyObject *Method_GetStringWidth (PyObject *self, PyObject *args) { - char *text; - char *font_str = "normal"; - struct BMF_Font *font; - PyObject *width; - - if (!PyArg_ParseTuple (args, "s|s", &text, &font_str)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected one or two string arguments"); - - if (!strcmp (font_str, "normal")) - font = (&G)->font; - else if (!strcmp (font_str, "small")) - font = (&G)->fonts; - else if (!strcmp (font_str, "tiny")) - font = (&G)->fontss; - else - return EXPP_ReturnPyObjError (PyExc_AttributeError, - "\"font\" must be: 'normal' (default), 'small' or 'tiny'."); - - width = PyInt_FromLong (BMF_GetStringWidth (font, text)); - - if (!width) - return EXPP_ReturnPyObjError (PyExc_MemoryError, "couldn't create PyInt"); - - return width; + char *text; + char *font_str = "normal"; + struct BMF_Font *font; + PyObject *width; + + if (!PyArg_ParseTuple (args, "s|s", &text, &font_str)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected one or two string arguments"); + + if (!strcmp (font_str, "normal")) + font = (&G)->font; + else if (!strcmp (font_str, "small")) + font = (&G)->fonts; + else if (!strcmp (font_str, "tiny")) + font = (&G)->fontss; + else + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "\"font\" must be: 'normal' (default), 'small' or 'tiny'."); + + width = PyInt_FromLong (BMF_GetStringWidth (font, text)); + + if (!width) + return EXPP_ReturnPyObjError (PyExc_MemoryError, "couldn't create PyInt"); + + return width; } -static PyObject * -Method_Text (PyObject * self, PyObject * args) +static PyObject *Method_Text (PyObject *self, PyObject *args) { - char *text; - char *font_str = NULL; - struct BMF_Font *font; - - if (!PyArg_ParseTuple (args, "s|s", &text, &font_str)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected one or two string arguments"); - - if (!font_str) - font = (&G)->font; - else if (!strcmp (font_str, "normal")) - font = (&G)->font; - else if (!strcmp (font_str, "small")) - font = (&G)->fonts; - else if (!strcmp (font_str, "tiny")) - font = (&G)->fontss; - else - return EXPP_ReturnPyObjError (PyExc_AttributeError, - "\"font\" must be: 'normal' (default), 'small' or 'tiny'."); - - BMF_DrawString (font, text); - - return PyInt_FromLong (BMF_GetStringWidth (font, text)); + char *text; + char *font_str = NULL; + struct BMF_Font *font; + + if (!PyArg_ParseTuple (args, "s|s", &text, &font_str)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected one or two string arguments"); + + if (!font_str) + font = (&G)->font; + else if (!strcmp (font_str, "normal")) + font = (&G)->font; + else if (!strcmp (font_str, "small")) + font = (&G)->fonts; + else if (!strcmp (font_str, "tiny")) + font = (&G)->fontss; + else + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "\"font\" must be: 'normal' (default), 'small' or 'tiny'."); + + BMF_DrawString (font, text); + + return PyInt_FromLong (BMF_GetStringWidth (font, text)); } -static PyObject * -Method_PupMenu (PyObject * self, PyObject * args) +static PyObject *Method_PupMenu (PyObject *self, PyObject *args) { - char *text; - int maxrow = -1; - PyObject *ret; + char *text; + int maxrow = -1; + PyObject *ret; - if (!PyArg_ParseTuple (args, "s|i", &text, &maxrow)) - return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected a string and optionally an int as arguments"); + if (!PyArg_ParseTuple (args, "s|i", &text, &maxrow)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a string and optionally an int as arguments"); - if (maxrow >= 0) - ret = PyInt_FromLong (pupmenu_col (text, maxrow)); - else - ret = PyInt_FromLong (pupmenu (text)); + if (maxrow >= 0) + ret = PyInt_FromLong (pupmenu_col (text, maxrow)); + else + ret = PyInt_FromLong (pupmenu (text)); - if (ret) - return ret; + if (ret) return ret; - return EXPP_ReturnPyObjError (PyExc_MemoryError, "couldn't create a PyInt"); + return EXPP_ReturnPyObjError (PyExc_MemoryError, "couldn't create a PyInt"); } -PyObject * -Draw_Init (void) +PyObject *Draw_Init (void) { - PyObject *submodule, *dict; + PyObject *submodule, *dict; - Button_Type.ob_type = &PyType_Type; + Button_Type.ob_type = &PyType_Type; - submodule = Py_InitModule3 ("Blender.Draw", Draw_methods, Draw_doc); + submodule = Py_InitModule3 ("Blender.Draw", Draw_methods, Draw_doc); - dict = PyModule_GetDict (submodule); + dict = PyModule_GetDict (submodule); #define EXPP_ADDCONST(x) \ PyDict_SetItemString(dict, #x, PyInt_FromLong(x)) - /* So, for example: - * EXPP_ADDCONST(LEFTMOUSE) becomes - * PyDict_SetItemString(dict, "LEFTMOUSE", PyInt_FromLong(LEFTMOUSE)) - */ - - EXPP_ADDCONST (LEFTMOUSE); - EXPP_ADDCONST (MIDDLEMOUSE); - EXPP_ADDCONST (RIGHTMOUSE); - EXPP_ADDCONST (MOUSEX); - EXPP_ADDCONST (MOUSEY); - EXPP_ADDCONST (TIMER0); - EXPP_ADDCONST (TIMER1); - EXPP_ADDCONST (TIMER2); - EXPP_ADDCONST (TIMER3); - EXPP_ADDCONST (KEYBD); - EXPP_ADDCONST (RAWKEYBD); - EXPP_ADDCONST (REDRAW); - EXPP_ADDCONST (INPUTCHANGE); - EXPP_ADDCONST (QFULL); - EXPP_ADDCONST (WINFREEZE); - EXPP_ADDCONST (WINTHAW); - EXPP_ADDCONST (WINCLOSE); - EXPP_ADDCONST (WINQUIT); + /* So, for example: + * EXPP_ADDCONST(LEFTMOUSE) becomes + * PyDict_SetItemString(dict, "LEFTMOUSE", PyInt_FromLong(LEFTMOUSE)) + */ + + EXPP_ADDCONST (LEFTMOUSE); + EXPP_ADDCONST (MIDDLEMOUSE); + EXPP_ADDCONST (RIGHTMOUSE); + EXPP_ADDCONST (MOUSEX); + EXPP_ADDCONST (MOUSEY); + EXPP_ADDCONST (TIMER0); + EXPP_ADDCONST (TIMER1); + EXPP_ADDCONST (TIMER2); + EXPP_ADDCONST (TIMER3); + EXPP_ADDCONST (KEYBD); + EXPP_ADDCONST (RAWKEYBD); + EXPP_ADDCONST (REDRAW); + EXPP_ADDCONST (INPUTCHANGE); + EXPP_ADDCONST (QFULL); + EXPP_ADDCONST (WINFREEZE); + EXPP_ADDCONST (WINTHAW); + EXPP_ADDCONST (WINCLOSE); + EXPP_ADDCONST (WINQUIT); #ifndef IRISGL - EXPP_ADDCONST (Q_FIRSTTIME); + EXPP_ADDCONST (Q_FIRSTTIME); #endif - EXPP_ADDCONST (AKEY); - EXPP_ADDCONST (BKEY); - EXPP_ADDCONST (CKEY); - EXPP_ADDCONST (DKEY); - EXPP_ADDCONST (EKEY); - EXPP_ADDCONST (FKEY); - EXPP_ADDCONST (GKEY); - EXPP_ADDCONST (HKEY); - EXPP_ADDCONST (IKEY); - EXPP_ADDCONST (JKEY); - EXPP_ADDCONST (KKEY); - EXPP_ADDCONST (LKEY); - EXPP_ADDCONST (MKEY); - EXPP_ADDCONST (NKEY); - EXPP_ADDCONST (OKEY); - EXPP_ADDCONST (PKEY); - EXPP_ADDCONST (QKEY); - EXPP_ADDCONST (RKEY); - EXPP_ADDCONST (SKEY); - EXPP_ADDCONST (TKEY); - EXPP_ADDCONST (UKEY); - EXPP_ADDCONST (VKEY); - EXPP_ADDCONST (WKEY); - EXPP_ADDCONST (XKEY); - EXPP_ADDCONST (YKEY); - EXPP_ADDCONST (ZKEY); - EXPP_ADDCONST (ZEROKEY); - EXPP_ADDCONST (ONEKEY); - EXPP_ADDCONST (TWOKEY); - EXPP_ADDCONST (THREEKEY); - EXPP_ADDCONST (FOURKEY); - EXPP_ADDCONST (FIVEKEY); - EXPP_ADDCONST (SIXKEY); - EXPP_ADDCONST (SEVENKEY); - EXPP_ADDCONST (EIGHTKEY); - EXPP_ADDCONST (NINEKEY); - EXPP_ADDCONST (CAPSLOCKKEY); - EXPP_ADDCONST (LEFTCTRLKEY); - EXPP_ADDCONST (LEFTALTKEY); - EXPP_ADDCONST (RIGHTALTKEY); - EXPP_ADDCONST (RIGHTCTRLKEY); - EXPP_ADDCONST (RIGHTSHIFTKEY); - EXPP_ADDCONST (LEFTSHIFTKEY); - EXPP_ADDCONST (ESCKEY); - EXPP_ADDCONST (TABKEY); - EXPP_ADDCONST (RETKEY); - EXPP_ADDCONST (SPACEKEY); - EXPP_ADDCONST (LINEFEEDKEY); - EXPP_ADDCONST (BACKSPACEKEY); - EXPP_ADDCONST (DELKEY); - EXPP_ADDCONST (SEMICOLONKEY); - EXPP_ADDCONST (PERIODKEY); - EXPP_ADDCONST (COMMAKEY); - EXPP_ADDCONST (QUOTEKEY); - EXPP_ADDCONST (ACCENTGRAVEKEY); - EXPP_ADDCONST (MINUSKEY); - EXPP_ADDCONST (SLASHKEY); - EXPP_ADDCONST (BACKSLASHKEY); - EXPP_ADDCONST (EQUALKEY); - EXPP_ADDCONST (LEFTBRACKETKEY); - EXPP_ADDCONST (RIGHTBRACKETKEY); - EXPP_ADDCONST (LEFTARROWKEY); - EXPP_ADDCONST (DOWNARROWKEY); - EXPP_ADDCONST (RIGHTARROWKEY); - EXPP_ADDCONST (UPARROWKEY); - EXPP_ADDCONST (PAD2); - EXPP_ADDCONST (PAD4); - EXPP_ADDCONST (PAD6); - EXPP_ADDCONST (PAD8); - EXPP_ADDCONST (PAD1); - EXPP_ADDCONST (PAD3); - EXPP_ADDCONST (PAD5); - EXPP_ADDCONST (PAD7); - EXPP_ADDCONST (PAD9); - EXPP_ADDCONST (PADPERIOD); - EXPP_ADDCONST (PADSLASHKEY); - EXPP_ADDCONST (PADASTERKEY); - EXPP_ADDCONST (PAD0); - EXPP_ADDCONST (PADMINUS); - EXPP_ADDCONST (PADENTER); - EXPP_ADDCONST (PADPLUSKEY); - EXPP_ADDCONST (F1KEY); - EXPP_ADDCONST (F2KEY); - EXPP_ADDCONST (F3KEY); - EXPP_ADDCONST (F4KEY); - EXPP_ADDCONST (F5KEY); - EXPP_ADDCONST (F6KEY); - EXPP_ADDCONST (F7KEY); - EXPP_ADDCONST (F8KEY); - EXPP_ADDCONST (F9KEY); - EXPP_ADDCONST (F10KEY); - EXPP_ADDCONST (F11KEY); - EXPP_ADDCONST (F12KEY); - EXPP_ADDCONST (PAUSEKEY); - EXPP_ADDCONST (INSERTKEY); - EXPP_ADDCONST (HOMEKEY); - EXPP_ADDCONST (PAGEUPKEY); - EXPP_ADDCONST (PAGEDOWNKEY); - EXPP_ADDCONST (ENDKEY); - - return submodule; + EXPP_ADDCONST (AKEY); + EXPP_ADDCONST (BKEY); + EXPP_ADDCONST (CKEY); + EXPP_ADDCONST (DKEY); + EXPP_ADDCONST (EKEY); + EXPP_ADDCONST (FKEY); + EXPP_ADDCONST (GKEY); + EXPP_ADDCONST (HKEY); + EXPP_ADDCONST (IKEY); + EXPP_ADDCONST (JKEY); + EXPP_ADDCONST (KKEY); + EXPP_ADDCONST (LKEY); + EXPP_ADDCONST (MKEY); + EXPP_ADDCONST (NKEY); + EXPP_ADDCONST (OKEY); + EXPP_ADDCONST (PKEY); + EXPP_ADDCONST (QKEY); + EXPP_ADDCONST (RKEY); + EXPP_ADDCONST (SKEY); + EXPP_ADDCONST (TKEY); + EXPP_ADDCONST (UKEY); + EXPP_ADDCONST (VKEY); + EXPP_ADDCONST (WKEY); + EXPP_ADDCONST (XKEY); + EXPP_ADDCONST (YKEY); + EXPP_ADDCONST (ZKEY); + EXPP_ADDCONST (ZEROKEY); + EXPP_ADDCONST (ONEKEY); + EXPP_ADDCONST (TWOKEY); + EXPP_ADDCONST (THREEKEY); + EXPP_ADDCONST (FOURKEY); + EXPP_ADDCONST (FIVEKEY); + EXPP_ADDCONST (SIXKEY); + EXPP_ADDCONST (SEVENKEY); + EXPP_ADDCONST (EIGHTKEY); + EXPP_ADDCONST (NINEKEY); + EXPP_ADDCONST (CAPSLOCKKEY); + EXPP_ADDCONST (LEFTCTRLKEY); + EXPP_ADDCONST (LEFTALTKEY); + EXPP_ADDCONST (RIGHTALTKEY); + EXPP_ADDCONST (RIGHTCTRLKEY); + EXPP_ADDCONST (RIGHTSHIFTKEY); + EXPP_ADDCONST (LEFTSHIFTKEY); + EXPP_ADDCONST (ESCKEY); + EXPP_ADDCONST (TABKEY); + EXPP_ADDCONST (RETKEY); + EXPP_ADDCONST (SPACEKEY); + EXPP_ADDCONST (LINEFEEDKEY); + EXPP_ADDCONST (BACKSPACEKEY); + EXPP_ADDCONST (DELKEY); + EXPP_ADDCONST (SEMICOLONKEY); + EXPP_ADDCONST (PERIODKEY); + EXPP_ADDCONST (COMMAKEY); + EXPP_ADDCONST (QUOTEKEY); + EXPP_ADDCONST (ACCENTGRAVEKEY); + EXPP_ADDCONST (MINUSKEY); + EXPP_ADDCONST (SLASHKEY); + EXPP_ADDCONST (BACKSLASHKEY); + EXPP_ADDCONST (EQUALKEY); + EXPP_ADDCONST (LEFTBRACKETKEY); + EXPP_ADDCONST (RIGHTBRACKETKEY); + EXPP_ADDCONST (LEFTARROWKEY); + EXPP_ADDCONST (DOWNARROWKEY); + EXPP_ADDCONST (RIGHTARROWKEY); + EXPP_ADDCONST (UPARROWKEY); + EXPP_ADDCONST (PAD2); + EXPP_ADDCONST (PAD4); + EXPP_ADDCONST (PAD6); + EXPP_ADDCONST (PAD8); + EXPP_ADDCONST (PAD1); + EXPP_ADDCONST (PAD3); + EXPP_ADDCONST (PAD5); + EXPP_ADDCONST (PAD7); + EXPP_ADDCONST (PAD9); + EXPP_ADDCONST (PADPERIOD); + EXPP_ADDCONST (PADSLASHKEY); + EXPP_ADDCONST (PADASTERKEY); + EXPP_ADDCONST (PAD0); + EXPP_ADDCONST (PADMINUS); + EXPP_ADDCONST (PADENTER); + EXPP_ADDCONST (PADPLUSKEY); + EXPP_ADDCONST (F1KEY); + EXPP_ADDCONST (F2KEY); + EXPP_ADDCONST (F3KEY); + EXPP_ADDCONST (F4KEY); + EXPP_ADDCONST (F5KEY); + EXPP_ADDCONST (F6KEY); + EXPP_ADDCONST (F7KEY); + EXPP_ADDCONST (F8KEY); + EXPP_ADDCONST (F9KEY); + EXPP_ADDCONST (F10KEY); + EXPP_ADDCONST (F11KEY); + EXPP_ADDCONST (F12KEY); + EXPP_ADDCONST (PAUSEKEY); + EXPP_ADDCONST (INSERTKEY); + EXPP_ADDCONST (HOMEKEY); + EXPP_ADDCONST (PAGEUPKEY); + EXPP_ADDCONST (PAGEDOWNKEY); + EXPP_ADDCONST (ENDKEY); + + return submodule; } diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c index 6a691515b41..99f9ec9b709 100644 --- a/source/blender/python/api2_2x/Window.c +++ b/source/blender/python/api2_2x/Window.c @@ -29,9 +29,133 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ -#include "Window.h" -#include "vector.h" +#include <Python.h> +#include <stdio.h> + +#include <BKE_global.h> #include <BKE_library.h> +#include <BKE_object.h> /* for during_script() */ +#include <BIF_usiblender.h> +#include <BIF_mywindow.h> +#include <BSE_headerbuttons.h> +#include <BSE_filesel.h> +#include <BIF_screen.h> +#include <BIF_space.h> +#include <BIF_drawtext.h> +#include <mydevice.h> +#include <DNA_view3d_types.h> +#include <DNA_screen_types.h> +#include <DNA_space_types.h> +#include <DNA_text_types.h> + +#include "gen_utils.h" +#include "modules.h" +#include "matrix.h" +#include "vector.h" + + +/* See Draw.c */ +extern int EXPP_disable_force_draw; + +/* Callback used by the file and image selector access functions */ +static PyObject *(*EXPP_FS_PyCallback)(PyObject *arg) = NULL; + +/*****************************************************************************/ +/* Python API function prototypes for the Window module. */ +/*****************************************************************************/ +PyObject *M_Window_Redraw (PyObject *self, PyObject *args); +static PyObject *M_Window_RedrawAll (PyObject *self, PyObject *args); +static PyObject *M_Window_QRedrawAll (PyObject *self, PyObject *args); +static PyObject *M_Window_DrawProgressBar (PyObject *self, PyObject *args); +static PyObject *M_Window_GetCursorPos (PyObject *self); +static PyObject *M_Window_SetCursorPos (PyObject *self, PyObject *args); +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); + +/*****************************************************************************/ +/* The following string definitions are used for documentation strings. */ +/* In Python these will be written to the console when doing a */ +/* Blender.Window.__doc__ */ +/*****************************************************************************/ +static char M_Window_doc[] = +"The Blender Window module\n\n"; + +static char M_Window_Redraw_doc[] = +"() - Force a redraw of a specific Window Type (see Window.Types)"; + +static char M_Window_RedrawAll_doc[] = +"() - Redraw all windows"; + +static char M_Window_QRedrawAll_doc[] = +"() - Redraw all windows by queue event"; + +static char M_Window_FileSelector_doc[] = +"(callback [, title, filename]) - Open a file selector window.\n\ +The selected file name is used as argument to a function callback f(name)\n\ +that you must provide. 'title' is optional and defaults to 'SELECT FILE'.\n\ +'filename' is optional and defaults to Blender.Get('filename').\n\n\ +Example:\n\n\ +import Blender\n\n\ +def my_function(filename):\n\ + print 'The selected file was: ', filename\n\n\ +Blender.Window.FileSelector(my_function, 'SAVE FILE')\n"; + +static char M_Window_ImageSelector_doc[] = +"(callback [, title, filename]) - Open an image selector window.\n\ +The selected file name is used as argument to a function callback f(name)\n\ +that you must provide. 'title' is optional and defaults to 'SELECT IMAGE'.\n\ +'filename' is optional and defaults to Blender.Get('filename').\n\n\ +Example:\n\n\ +import Blender\n\n\ +def my_function(filename):\n\ + print 'The selected image file was: ', filename\n\n\ +Blender.Window.ImageSelector(my_function, 'LOAD IMAGE')\n"; + +static char M_Window_DrawProgressBar_doc[] = +"(done, text) - Draw a progress bar.\n\ +'done' is a float value <= 1.0, 'text' contains info about what is\n\ +currently being done."; + +static char M_Window_GetCursorPos_doc[] = +"() - Get the current 3d cursor position as a list of three floats."; + +static char M_Window_SetCursorPos_doc[] = +"([f,f,f]) - Set the current 3d cursor position from a list of three floats."; + +static char M_Window_GetViewVector_doc[] = +"() - Get the current 3d view vector as a list of three floats [x,y,z]."; + +static char M_Window_GetViewMatrix_doc[] = +"() - Get the current 3d view matrix."; + +/*****************************************************************************/ +/* Python method structure definition for Blender.Window module: */ +/*****************************************************************************/ +struct PyMethodDef M_Window_methods[] = { + {"Redraw", M_Window_Redraw, METH_VARARGS, M_Window_Redraw_doc}, + {"RedrawAll", M_Window_RedrawAll, METH_VARARGS, M_Window_RedrawAll_doc}, + {"QRedrawAll", M_Window_QRedrawAll, METH_VARARGS, M_Window_QRedrawAll_doc}, + {"FileSelector", M_Window_FileSelector, METH_VARARGS, + M_Window_FileSelector_doc}, + {"ImageSelector", (PyCFunction)M_Window_ImageSelector, METH_VARARGS, + M_Window_ImageSelector_doc}, + {"DrawProgressBar", M_Window_DrawProgressBar, METH_VARARGS, + M_Window_DrawProgressBar_doc}, + {"drawProgressBar", M_Window_DrawProgressBar, METH_VARARGS, + M_Window_DrawProgressBar_doc}, + {"GetCursorPos", (PyCFunction)M_Window_GetCursorPos, METH_NOARGS, + M_Window_GetCursorPos_doc}, + {"SetCursorPos", M_Window_SetCursorPos, METH_VARARGS, + M_Window_SetCursorPos_doc}, + {"GetViewVector", (PyCFunction)M_Window_GetViewVector, METH_NOARGS, + M_Window_GetViewVector_doc}, + {"GetViewMatrix", (PyCFunction)M_Window_GetViewMatrix, METH_NOARGS, + M_Window_GetViewMatrix_doc}, + {NULL, NULL, 0, NULL} +}; + /* Many parts of the code here come from the older bpython implementation * (file opy_window.c) */ @@ -40,8 +164,9 @@ /* Function: M_Window_Redraw */ /* Python equivalent: Blender.Window.Redraw */ /*****************************************************************************/ +/* not static so py_slider_update in Draw.[ch] can use it */ PyObject *M_Window_Redraw(PyObject *self, PyObject *args) -{ /* not static so py_slider_update in Draw.[ch] can use it */ +{ ScrArea *tempsa, *sa; SpaceText *st; int wintype = SPACE_VIEW3D; @@ -82,9 +207,10 @@ PyObject *M_Window_Redraw(PyObject *self, PyObject *args) if (curarea != tempsa) areawinset (tempsa->win); - if (curarea->headwin) scrarea_do_headdraw (curarea); - - screen_swapbuffers(); + if (curarea) { /* is null if Blender is in bg mode */ + if (curarea->headwin) scrarea_do_headdraw (curarea); + screen_swapbuffers(); + } } Py_INCREF(Py_None); @@ -135,14 +261,16 @@ static void getSelectedFile(char *name) static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args) { char *title = "SELECT FILE"; + char *filename = G.sce; SpaceScript *sc; Script *script = G.main->script.last; int startspace = 0; - if (!PyArg_ParseTuple(args, "O!|s", &PyFunction_Type, &EXPP_FS_PyCallback, - &title)) + if (!PyArg_ParseTuple(args, "O!|ss", + &PyFunction_Type, &EXPP_FS_PyCallback, &title, &filename)) return (EXPP_ReturnPyObjError (PyExc_AttributeError, - "\nexpected a callback function (and optionally a string) as argument(s)")); + "\nexpected a callback function (and optionally one or two strings) " + "as argument(s)")); /* trick: we move to a spacescript because then the fileselector will properly * unset our SCRIPT_FILESEL flag when the user chooses a file or cancels the @@ -167,7 +295,7 @@ static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args) script->flags |= SCRIPT_FILESEL; - activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile); + activate_fileselect(FILE_BLENDER, title, filename, getSelectedFile); Py_INCREF(Py_None); return Py_None; @@ -176,14 +304,16 @@ static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args) static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args) { char *title = "SELECT IMAGE"; + char *filename = G.sce; SpaceScript *sc; Script *script = G.main->script.last; int startspace = 0; - if (!PyArg_ParseTuple(args, "O!|s", &PyFunction_Type, &EXPP_FS_PyCallback, - &title)) + if (!PyArg_ParseTuple(args, "O!|ss", + &PyFunction_Type, &EXPP_FS_PyCallback, &title, &filename)) return (EXPP_ReturnPyObjError (PyExc_AttributeError, - "\nexpected a callback function (and optionally a string) as argument(s)")); + "\nexpected a callback function (and optionally one or two strings) " + "as argument(s)")); /* trick: we move to a spacescript because then the fileselector will properly * unset our SCRIPT_FILESEL flag when the user chooses a file or cancels the @@ -209,7 +339,7 @@ static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args) script->flags |= SCRIPT_FILESEL; /* same flag as filesel */ - activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile); + activate_imageselect(FILE_BLENDER, title, filename, getSelectedFile); Py_INCREF(Py_None); return Py_None; @@ -223,13 +353,13 @@ static PyObject *M_Window_DrawProgressBar(PyObject *self, PyObject *args) { float done; char *info = NULL; - int retval; + int retval = 0; if(!PyArg_ParseTuple(args, "fs", &done, &info)) return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected a float and a string as arguments")); - retval = progress_bar(done, info); + if (!G.background) retval = progress_bar(done, info); return Py_BuildValue("i", retval); } diff --git a/source/blender/python/api2_2x/Window.h b/source/blender/python/api2_2x/Window.h index 800254b47df..81b288f395f 100644 --- a/source/blender/python/api2_2x/Window.h +++ b/source/blender/python/api2_2x/Window.h @@ -29,129 +29,9 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ +/* This file is useless now, CAN BE REMOVED. */ + #ifndef EXPP_WINDOW_H #define EXPP_WINDOW_H -#include <Python.h> -#include <stdio.h> - -#include <BKE_global.h> -#include <BKE_object.h> /* for during_script() */ -#include <BIF_usiblender.h> -#include <BIF_mywindow.h> -#include <BSE_headerbuttons.h> -#include <BSE_filesel.h> -#include <BIF_screen.h> -#include <BIF_space.h> -#include <BIF_drawtext.h> -#include <mydevice.h> -#include <DNA_view3d_types.h> -#include <DNA_screen_types.h> -#include <DNA_space_types.h> -#include <DNA_text_types.h> - -#include "gen_utils.h" -#include "modules.h" -#include "matrix.h" - -/* Used in Draw.c */ -extern int EXPP_disable_force_draw; - -/* Callback used by the file and image selector access functions */ -static PyObject *(*EXPP_FS_PyCallback)(PyObject *arg) = NULL; - -/*****************************************************************************/ -/* Python API function prototypes for the Window module. */ -/*****************************************************************************/ -PyObject *M_Window_Redraw (PyObject *self, PyObject *args); -static PyObject *M_Window_RedrawAll (PyObject *self, PyObject *args); -static PyObject *M_Window_QRedrawAll (PyObject *self, PyObject *args); -static PyObject *M_Window_FileSelector (PyObject *self, PyObject *args); -static PyObject *M_Window_ImageSelector (PyObject *self, PyObject *args); -static PyObject *M_Window_DrawProgressBar (PyObject *self, PyObject *args); -static PyObject *M_Window_GetCursorPos (PyObject *self); -static PyObject *M_Window_SetCursorPos (PyObject *self, PyObject *args); -static PyObject *M_Window_GetViewVector (PyObject *self); -static PyObject *M_Window_GetViewMatrix (PyObject *self); - -/*****************************************************************************/ -/* The following string definitions are used for documentation strings. */ -/* In Python these will be written to the console when doing a */ -/* Blender.Window.__doc__ */ -/*****************************************************************************/ -char M_Window_doc[] = -"The Blender Window module\n\n"; - -char M_Window_Redraw_doc[] = -"() - Force a redraw of a specific Window Type (see Window.Types)"; - -char M_Window_RedrawAll_doc[] = -"() - Redraw all windows"; - -char M_Window_QRedrawAll_doc[] = -"() - Redraw all windows by queue event"; - -char M_Window_FileSelector_doc[] = -"(callback [, title]) - Open a file selector window.\n\ -The selected filename is used as argument to a function callback f(name)\n\ -that you must provide. 'title' is optional and defaults to 'SELECT FILE'.\n\n\ -Example:\n\n\ -import Blender\n\n\ -def my_function(filename):\n\ - print 'The selected file was: ', filename\n\n\ -Blender.Window.FileSelector(my_function, 'SAVE FILE')\n"; - -char M_Window_ImageSelector_doc[] = -"(callback [, title]) - Open an image selector window.\n\ -The selected filename is used as argument to a function callback f(name)\n\ -that you must provide. 'title' is optional and defaults to 'SELECT IMAGE'.\n\n\ -Example:\n\n\ -import Blender\n\n\ -def my_function(filename):\n\ - print 'The selected image file was: ', filename\n\n\ -Blender.Window.ImageSelector(my_function, 'LOAD IMAGE')\n"; - -char M_Window_DrawProgressBar_doc[] = -"(done, text) - Draw a progress bar.\n\ -'done' is a float value <= 1.0, 'text' contains info about what is\n\ -currently being done."; - -char M_Window_GetCursorPos_doc[] = -"() - Get the current 3d cursor position as a list of three floats."; - -char M_Window_SetCursorPos_doc[] = -"([f,f,f]) - Set the current 3d cursor position from a list of three floats."; - -char M_Window_GetViewVector_doc[] = -"() - Get the current 3d view vector as a list of three floats [x,y,z]."; - -char M_Window_GetViewMatrix_doc[] = -"() - Get the current 3d view matrix."; - -/*****************************************************************************/ -/* Python method structure definition for Blender.Window module: */ -/*****************************************************************************/ -struct PyMethodDef M_Window_methods[] = { - {"Redraw", M_Window_Redraw, METH_VARARGS, M_Window_Redraw_doc}, - {"RedrawAll", M_Window_RedrawAll, METH_VARARGS, M_Window_RedrawAll_doc}, - {"QRedrawAll", M_Window_QRedrawAll, METH_VARARGS, M_Window_QRedrawAll_doc}, - {"FileSelector", M_Window_FileSelector, METH_VARARGS, - M_Window_FileSelector_doc}, - {"ImageSelector", M_Window_ImageSelector, METH_VARARGS, - M_Window_ImageSelector_doc}, - {"DrawProgressBar", M_Window_DrawProgressBar, METH_VARARGS, - M_Window_DrawProgressBar_doc}, - {"drawProgressBar", M_Window_DrawProgressBar, METH_VARARGS, - M_Window_DrawProgressBar_doc}, - {"GetCursorPos", (PyCFunction)M_Window_GetCursorPos, METH_NOARGS, - M_Window_GetCursorPos_doc}, - {"SetCursorPos", M_Window_SetCursorPos, METH_VARARGS, - M_Window_SetCursorPos_doc}, - {"GetViewVector", (PyCFunction)M_Window_GetViewVector, METH_NOARGS, - M_Window_GetViewVector_doc}, - {"GetViewMatrix", (PyCFunction)M_Window_GetViewMatrix, METH_NOARGS, - M_Window_GetViewMatrix_doc}, - {NULL, NULL, 0, NULL} -}; - #endif /* EXPP_WINDOW_H */ diff --git a/source/blender/python/api2_2x/doc/Window.py b/source/blender/python/api2_2x/doc/Window.py index cac7c5d5e36..8c87f83b48c 100644 --- a/source/blender/python/api2_2x/doc/Window.py +++ b/source/blender/python/api2_2x/doc/Window.py @@ -8,6 +8,8 @@ Window This module provides access to B{Window} functions in Blender. +B{New}: file and image selectors accept a filename now. + Example: -------- @@ -83,7 +85,7 @@ def QRedrawAll (): Redraw all windows by queue event. """ -def FileSelector (callback, title = 'SELECT FILE'): +def FileSelector (callback, title = 'SELECT FILE', filename = '<default>'): """ Open the file selector window in Blender. After the user selects a filename, it is passed as parameter to the function callback given to FileSelector(). @@ -100,9 +102,11 @@ def FileSelector (callback, title = 'SELECT FILE'): @type title: string @param title: The string that appears in the button to confirm the selection and return from the file selection window. + @type filename: string + @param filename: A filename. This defaults to Blender.Get('filename'). """ -def ImageSelector (callback, title = 'SELECT IMAGE'): +def ImageSelector (callback, title = 'SELECT IMAGE', filename = '<default>'): """ Open the image selector window in Blender. After the user selects a filename, it is passed as parameter to the function callback given to ImageSelector(). @@ -119,6 +123,8 @@ def ImageSelector (callback, title = 'SELECT IMAGE'): @type title: string @param title: The string that appears in the button to confirm the selection and return from the image selection window. + @type filename: string + @param filename: A filename. This defaults to Blender.Get('filename'). """ def DrawProgressBar (done, text): |