File: pyginterface.c

package info (click to toggle)
pygobject 3.55.3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 5,728 kB
  • sloc: ansic: 39,419; python: 26,856; sh: 114; makefile: 81; xml: 35; cpp: 1
file content (98 lines) | stat: -rw-r--r-- 3,127 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* -*- Mode: C; c-basic-offset: 4 -*-
 * pygtk- Python bindings for the GTK toolkit.
 * Copyright (C) 1998-2003  James Henstridge
 *               2004-2008  Johan Dahlin
 *   pyginterface.c: wrapper for the gobject library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#include "pygi-type.h"
#include "pygi-util.h"
#include "pyginterface.h"

GQuark pyginterface_type_key;
GQuark pyginterface_info_key;

PYGI_DEFINE_TYPE ("gobject.GInterface", PyGInterface_Type, PyObject)

static int
pyg_interface_init (PyObject *self, PyObject *args, PyObject *kwargs)
{
    gchar buf[512];

    if (!PyArg_ParseTuple (args, ":GInterface.__init__")) return -1;

    g_snprintf (buf, sizeof (buf), "%s can not be constructed",
                Py_TYPE (self)->tp_name);
    PyErr_SetString (PyExc_NotImplementedError, buf);
    return -1;
}

static void
pyg_interface_free (PyObject *op)
{
    PyObject_Free (op);
}

void
pyg_register_interface_info (GType gtype, const GInterfaceInfo *info)
{
    GInterfaceInfo *prev_info = pyg_lookup_interface_info (gtype);

    if (prev_info) {
        g_free (prev_info);
    }

    g_type_set_qdata (gtype, pyginterface_info_key,
                      g_memdup2 (info, sizeof (GInterfaceInfo)));
}

const GInterfaceInfo *
pyg_lookup_interface_info (GType gtype)
{
    return g_type_get_qdata (gtype, pyginterface_info_key);
}

/**
 * Returns 0 on success, or -1 and sets an exception.
 */
int
pygi_interface_register_types (PyObject *d)
{
    PyObject *pygtype;

    pyginterface_type_key = g_quark_from_static_string ("PyGInterface::type");
    pyginterface_info_key = g_quark_from_static_string ("PyGInterface::info");

    PyGInterface_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
    PyGInterface_Type.tp_init = (initproc)pyg_interface_init;
    PyGInterface_Type.tp_free = (freefunc)pyg_interface_free;
    PyGInterface_Type.tp_alloc = PyType_GenericAlloc;
    PyGInterface_Type.tp_new = PyType_GenericNew;
    if (PyType_Ready (&PyGInterface_Type)) return -1;

    pygtype = pyg_type_wrapper_new (G_TYPE_INTERFACE);
    PyDict_SetItemString (PyGInterface_Type.tp_dict, "__gtype__", pygtype);
    Py_DECREF (pygtype);

    PyDict_SetItemString (PyGInterface_Type.tp_dict, "__doc__",
                          pyg_object_descr_doc_get ());
    PyDict_SetItemString (PyGInterface_Type.tp_dict, "__gdoc__",
                          pyg_object_descr_doc_get ());

    PyDict_SetItemString (d, "GInterface", (PyObject *)&PyGInterface_Type);

    return 0;
}