1 /* Python plug-in for dia
2 * Copyright (C) 1999 James Henstridge
3 * Copyright (C) 2000 Hans Breuer
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "pydia-object.h"
25 #include "pydia-image.h"
30 PyObject
* PyDiaImage_New (DiaImage image
)
34 self
= PyObject_NEW(PyDiaImage
, &PyDiaImage_Type
);
35 if (!self
) return NULL
;
37 dia_image_add_ref (image
);
40 return (PyObject
*)self
;
47 PyDiaImage_Dealloc(PyDiaImage
*self
)
49 dia_image_release (self
->image
);
57 PyDiaImage_Compare(PyDiaImage
*self
,
60 return memcmp(&(self
->image
), &(other
->image
), sizeof(DiaImage
));
67 PyDiaImage_Hash(PyObject
*self
)
76 PyDiaImage_GetAttr(PyDiaImage
*self
, gchar
*attr
)
78 if (!strcmp(attr
, "__members__"))
79 return Py_BuildValue("[ssssss]", "width", "height",
80 "rgb_data", "mask_data",
82 else if (!strcmp(attr
, "width"))
83 return PyInt_FromLong(dia_image_width(self
->image
));
84 else if (!strcmp(attr
, "height"))
85 return PyInt_FromLong(dia_image_height(self
->image
));
86 else if (!strcmp(attr
, "filename")) {
87 return PyString_FromString(dia_image_filename(self
->image
));
89 else if (!strcmp(attr
, "uri")) {
91 char* s
= g_filename_to_uri(dia_image_filename(self
->image
), NULL
, &error
);
93 PyObject
* py_s
= PyString_FromString(s
);
98 PyErr_SetString(PyExc_RuntimeError
, error
->message
);
103 else if (!strcmp(attr
, "rgb_data")) {
104 char* s
= dia_image_rgb_data(self
->image
);
105 int len
= dia_image_width(self
->image
) * dia_image_height(self
->image
) * 3;
106 PyObject
* py_s
= PyString_FromStringAndSize(s
, len
);
110 else if (!strcmp(attr
, "mask_data")) {
111 char* s
= dia_image_rgb_data(self
->image
);
112 int len
= dia_image_width(self
->image
) * dia_image_height(self
->image
);
113 PyObject
* py_s
= PyString_FromStringAndSize(s
, len
);
118 PyErr_SetString(PyExc_AttributeError
, attr
);
126 PyDiaImage_Str(PyDiaImage
*self
)
129 gchar
* name
= dia_image_filename(self
->image
);
130 gchar
* s
= g_strdup_printf("%ix%i,%s",
131 dia_image_width(self
->image
),
132 dia_image_height(self
->image
),
134 py_s
= PyString_FromString(s
);
143 PyTypeObject PyDiaImage_Type
= {
144 PyObject_HEAD_INIT(&PyType_Type
)
149 (destructor
)PyDiaImage_Dealloc
,
151 (getattrfunc
)PyDiaImage_GetAttr
,
153 (cmpfunc
)PyDiaImage_Compare
,
158 (hashfunc
)PyDiaImage_Hash
,
160 (reprfunc
)PyDiaImage_Str
,