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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-03-25 12:00:00 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-03-25 12:00:00 +0300
commit662c57d63e011c0ad1623e9d4eb0aa2f1b7a409c (patch)
tree5c43e18ee96b9633d232942b3d89369800c022d8 /source/blender/python/api2_2x/Window.c
parenta2dd82570a09d2f6b5f1fe057fff71f09c6db9c1 (diff)
fix for [bf-blender-Bug Tracker][8739] image selector never exits.
This fix was made to the file selector weren't applied to the image selector. Made file and image selector use same python api function.
Diffstat (limited to 'source/blender/python/api2_2x/Window.c')
-rw-r--r--source/blender/python/api2_2x/Window.c83
1 files changed, 17 insertions, 66 deletions
diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c
index b4a14cc6ac8..64349cdb83c 100644
--- a/source/blender/python/api2_2x/Window.c
+++ b/source/blender/python/api2_2x/Window.c
@@ -556,22 +556,23 @@ static void getSelectedFile( char *name )
return;
}
-static PyObject *M_Window_FileSelector( PyObject * self, PyObject * args )
+/* Use for file and image selector */
+static PyObject * FileAndImageSelector(PyObject * self, PyObject * args, int type)
{
- char *title = "SELECT FILE";
+ char *title = (type==0 ? "SELECT FILE" : "SELECT IMAGE");
char *filename = G.sce;
SpaceScript *sc;
Script *script = NULL;
PyObject *pycallback = NULL;
int startspace = 0;
-
+
if (during_scriptlink())
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "script links can't call the file selector");
+ "script links can't call the file/image selector");
if (G.background)
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "the file selector is not available in background mode");
+ "the file/image selector is not available in background mode");
if((!PyArg_ParseTuple( args, "O|ss", &pycallback, &title, &filename))
|| (!PyCallable_Check(pycallback)))
@@ -621,72 +622,22 @@ static PyObject *M_Window_FileSelector( PyObject * self, PyObject * args )
script->scriptname[0] = '\0';
script->scriptarg[0] = '\0';
}
- activate_fileselect( FILE_BLENDER, title, filename, getSelectedFile );
+ if (type==0) {
+ activate_fileselect( FILE_BLENDER, title, filename, getSelectedFile );
+ } else {
+ activate_imageselect( FILE_BLENDER, title, filename, getSelectedFile );
+ }
Py_RETURN_NONE;
}
-static PyObject *M_Window_ImageSelector( PyObject * self, PyObject * args )
+static PyObject *M_Window_FileSelector( PyObject * self, PyObject * args )
{
- char *title = "SELECT IMAGE";
- char *filename = G.sce;
- SpaceScript *sc;
- Script *script = NULL;
- PyObject *pycallback = NULL;
- int startspace = 0;
-
- if (during_scriptlink())
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "script links can't call the image selector");
-
- if (G.background)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "the image selector is not available in background mode");
-
- if( !PyArg_ParseTuple( args, "O|ss", &pycallback, &title, &filename )
- || (!PyCallable_Check(pycallback)))
- return EXPP_ReturnPyObjError ( PyExc_AttributeError,
- "\nexpected a callback function (and optionally one or two strings) "
- "as argument(s)" );
-
- Py_INCREF(pycallback);
-
-/* 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
- * selection. This is necessary because when a user cancels, the
- * getSelectedFile function above doesn't get called and so couldn't unset the
- * flag. */
- startspace = curarea->spacetype;
- if( startspace != SPACE_SCRIPT )
- newspace( curarea, SPACE_SCRIPT );
-
- sc = curarea->spacedata.first;
-
- /* let's find the script that called us */
- script = G.main->script.first;
- while (script) {
- if (script->flags & SCRIPT_RUNNING) break;
- script = script->id.next;
- }
-
- if( !script ) {
- /* if not running, then we were already on a SpaceScript space, executing
- * a registered callback -- aka: this script has a gui */
- script = sc->script; /* this is the right script */
- } else { /* still running, use the trick */
- script->lastspace = startspace;
- sc->script = script;
- }
-
- script->flags |= SCRIPT_FILESEL; /* same flag as filesel */
- /* clear any previous callback (nested calls to selector) */
- if (script->py_browsercallback) {
- Py_DECREF((PyObject *)script->py_browsercallback);
- }
- script->py_browsercallback = pycallback;
-
- activate_imageselect( FILE_BLENDER, title, filename, getSelectedFile );
+ return FileAndImageSelector( self, args, 0 );
+}
- Py_RETURN_NONE;
+static PyObject *M_Window_ImageSelector( PyObject * self, PyObject * args )
+{
+ return FileAndImageSelector( self, args, 1 );
}
/*****************************************************************************/