1 /* -*- Mode: C; c-basic-offset: 4 -*-
2  * Gimp-Python - allows the writing of Gimp plugins in Python.
3  * Copyright (C) 1997-2002  James Henstridge <james@daa.com.au>
4  *
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 3 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18 
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22 
23 #include "pygimp.h"
24 
25 static PyMethodDef disp_methods[] = {
26     {NULL,	NULL}		/* sentinel */
27 };
28 
29 static PyObject *
disp_get_ID(PyGimpDisplay * self,void * closure)30 disp_get_ID(PyGimpDisplay *self, void *closure)
31 {
32     return PyInt_FromLong(self->ID);
33 }
34 
35 static PyGetSetDef disp_getsets[] = {
36     { "ID", (getter)disp_get_ID, (setter)0 },
37     { NULL, (getter)0, (setter)0 }
38 };
39 
40 /* ---------- */
41 
42 
43 PyObject *
pygimp_display_new(gint32 ID)44 pygimp_display_new(gint32 ID)
45 {
46     PyGimpDisplay *self;
47 
48     if (!gimp_display_is_valid(ID)) {
49         Py_INCREF(Py_None);
50         return Py_None;
51     }
52 
53     self = PyObject_NEW(PyGimpDisplay, &PyGimpDisplay_Type);
54 
55     if (self == NULL)
56 	return NULL;
57 
58     self->ID = ID;
59 
60     return (PyObject *)self;
61 }
62 
63 static void
disp_dealloc(PyGimpDisplay * self)64 disp_dealloc(PyGimpDisplay *self)
65 {
66     PyObject_DEL(self);
67 }
68 
69 static PyObject *
disp_repr(PyGimpDisplay * self)70 disp_repr(PyGimpDisplay *self)
71 {
72     PyObject *s;
73 
74     s = PyString_FromString("<display>");
75 
76     return s;
77 }
78 
79 static int
disp_init(PyGimpDisplay * self,PyObject * args,PyObject * kwargs)80 disp_init(PyGimpDisplay *self, PyObject *args, PyObject *kwargs)
81 {
82     PyGimpImage *img;
83 
84     if (!PyArg_ParseTuple(args, "O!:gimp.Display.__init__",
85 			  &PyGimpImage_Type, &img))
86 	return -1;
87 
88     self->ID = gimp_display_new(img->ID);
89 
90     if (self->ID < 0) {
91 	PyErr_Format(pygimp_error, "could not create display for image (ID %d)",
92 		     img->ID);
93 	return -1;
94     }
95 
96     return 0;
97 }
98 
99 PyTypeObject PyGimpDisplay_Type = {
100     PyObject_HEAD_INIT(NULL)
101     0,                                  /* ob_size */
102     "gimp.Display",                     /* tp_name */
103     sizeof(PyGimpDisplay),              /* tp_basicsize */
104     0,                                  /* tp_itemsize */
105     /* methods */
106     (destructor)disp_dealloc,           /* tp_dealloc */
107     (printfunc)0,                       /* tp_print */
108     (getattrfunc)0,                     /* tp_getattr */
109     (setattrfunc)0,                     /* tp_setattr */
110     (cmpfunc)0,                         /* tp_compare */
111     (reprfunc)disp_repr,                /* tp_repr */
112     0,                                  /* tp_as_number */
113     0,                                  /* tp_as_sequence */
114     0,                                  /* tp_as_mapping */
115     (hashfunc)0,                        /* tp_hash */
116     (ternaryfunc)0,                     /* tp_call */
117     (reprfunc)0,                        /* tp_str */
118     (getattrofunc)0,                    /* tp_getattro */
119     (setattrofunc)0,                    /* tp_setattro */
120     0,					/* tp_as_buffer */
121     Py_TPFLAGS_DEFAULT,	                /* tp_flags */
122     NULL, /* Documentation string */
123     (traverseproc)0,			/* tp_traverse */
124     (inquiry)0,				/* tp_clear */
125     (richcmpfunc)0,			/* tp_richcompare */
126     0,					/* tp_weaklistoffset */
127     (getiterfunc)0,			/* tp_iter */
128     (iternextfunc)0,			/* tp_iternext */
129     disp_methods,			/* tp_methods */
130     0,					/* tp_members */
131     disp_getsets,			/* tp_getset */
132     (PyTypeObject *)0,			/* tp_base */
133     (PyObject *)0,			/* tp_dict */
134     0,					/* tp_descr_get */
135     0,					/* tp_descr_set */
136     0,					/* tp_dictoffset */
137     (initproc)disp_init,                /* tp_init */
138     (allocfunc)0,			/* tp_alloc */
139     (newfunc)0,				/* tp_new */
140 };
141