- Campbell Barton contributed another function (thanks again), the Image.reload method:
  with this a script can keep an image that is being edited and saved by an external program updated in Blender.
This commit is contained in:
Willian Padovani Germano 2004-05-25 10:36:58 +00:00
parent f9fa705cd3
commit 8a64e0e867
3 changed files with 281 additions and 253 deletions

@ -1,4 +1,5 @@
/*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
@ -24,7 +25,7 @@
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
* Contributor(s): Willian P. Germano, Campbell Barton
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@ -106,6 +107,7 @@ static PyObject *Method_String (PyObject * self, PyObject * args);
static PyObject *Method_GetStringWidth (PyObject * self, PyObject * args);
static PyObject *Method_Text (PyObject * self, PyObject * args);
static PyObject *Method_PupMenu (PyObject * self, PyObject * args);
/* next two by Campbell: */
static PyObject *Method_PupIntInput (PyObject * self, PyObject * args);
static PyObject *Method_PupFloatInput (PyObject * self, PyObject * args);

@ -1,4 +1,5 @@
/*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
@ -24,7 +25,7 @@
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
* Contributor(s): Willian P. Germano, Campbell Barton
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@ -33,6 +34,7 @@
#include <BKE_global.h>
#include <BKE_library.h>
#include <BKE_image.h>
#include <BIF_drawimage.h>
#include <BLI_blenlib.h>
#include <IMB_imbuf_types.h> /* for the IB_rect define */
#include "gen_utils.h"
@ -233,6 +235,7 @@ static PyObject *Image_getYRep(BPy_Image *self);
static PyObject *Image_setName(BPy_Image *self, PyObject *args);
static PyObject *Image_setXRep(BPy_Image *self, PyObject *args);
static PyObject *Image_setYRep(BPy_Image *self, PyObject *args);
static PyObject *Image_reload(BPy_Image *self); /* by Campbell */
/*****************************************************************************/
/* Python BPy_Image methods table: */
@ -251,6 +254,8 @@ static PyMethodDef BPy_Image_methods[] = {
"() - Return Image object x repetition value"},
{"getYRep", (PyCFunction)Image_getYRep, METH_NOARGS,
"() - Return Image object y repetition value"},
{"reload", (PyCFunction)Image_reload, METH_NOARGS,
"() - Reload the image from the filesystem"},
{"setName", (PyCFunction)Image_setName, METH_VARARGS,
"(str) - Change Image object name"},
{"setXRep", (PyCFunction)Image_setXRep, METH_VARARGS,
@ -430,6 +435,18 @@ static PyObject *Image_getYRep(BPy_Image *self)
"couldn't get Image.yrep attribute");
}
static PyObject *Image_reload(BPy_Image *self)
{
Image *img = self->image;
free_image_buffers(img); /* force read again */
img->ok = 1;
image_changed(G.sima, 0);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *Image_setName(BPy_Image *self, PyObject *args)
{
char *name;

@ -104,6 +104,15 @@ class Image:
This is for texture tiling.
@rtype: int
"""
def reload():
"""
Reloads this image from the filesystem. If used within a loop you need to
redraw the Window to see the change in the image, e.g. with
Window.RedrawAll().
@warn: if the image file is corrupt or still being written, it will be
replaced by a blank image in Blender, but no error will be returned.
@returns: None
"""
def setName(name):
"""