Esempio n. 1
0
static PyObject *
PyDiaDiagram_FindClosestHandle(PyDiaDiagram *self, PyObject *args)
{
    Point p;
    double dist;
    Handle *handle;
    DiaObject *obj;
    PyObject *ret;

    if (!PyArg_ParseTuple(args, "dd:Diagram.find_closest_handle",
			  &p.x, &p.y))
	return NULL;
    dist = diagram_find_closest_handle(self->dia, &handle, &obj, &p);
    ret = PyTuple_New(3);
    PyTuple_SetItem(ret, 0, PyFloat_FromDouble(dist));
    if (handle)
	PyTuple_SetItem(ret, 1, PyDiaHandle_New(handle, obj));
    else {
	Py_INCREF(Py_None);
	PyTuple_SetItem(ret, 1, Py_None);
    }
    if (obj)
	PyTuple_SetItem(ret, 1, PyDiaObject_New(obj));
    else {
	Py_INCREF(Py_None);
	PyTuple_SetItem(ret, 1, Py_None);
    }
    return ret;
}
Esempio n. 2
0
static PyObject *
PyDiaObject_GetAttr(PyDiaObject *self, gchar *attr)
{
    if (!strcmp(attr, "__members__"))
	return Py_BuildValue("[sssss]", "bounding_box", "connections",
			     "handles", "properties", "type");
    else if (!strcmp(attr, "type"))
	return PyDiaObjectType_New(self->object->type);
    else if (!strcmp(attr, "bounding_box"))
	return PyDiaRectangle_New(&(self->object->bounding_box), NULL);
    else if (!strcmp(attr, "handles")) {
	int i;
	PyObject *ret = PyTuple_New(self->object->num_handles);

	for (i = 0; i < self->object->num_handles; i++)
	    PyTuple_SetItem(ret, i, PyDiaHandle_New(self->object->handles[i], self->object));
	return ret;
    } else if (!strcmp(attr, "connections")) {
	int i;
	PyObject *ret = PyTuple_New(self->object->num_connections);

	for (i = 0; i < self->object->num_connections; i++)
	    PyTuple_SetItem(ret, i, PyDiaConnectionPoint_New(
				self->object->connections[i]));
	return ret;
    } else if (!strcmp(attr, "properties")) {
	return PyDiaProperties_New(self->object);
    }

    return Py_FindMethod(PyDiaObject_Methods, (PyObject *)self, attr);
}
Esempio n. 3
0
static PyObject *
PyDiaObjectType_Create(PyDiaObjectType *self, PyObject *args)
{
    Point p;
    gint data = 0;
    gpointer user_data;
    DiaObject *ret;
    Handle *h1 = NULL, *h2 = NULL;
    PyObject *pyret;

    if (!PyArg_ParseTuple(args, "dd|i:ObjectType.create", &p.x,&p.y, &data))
	return NULL;
    user_data = GINT_TO_POINTER(data);
    if (!self->otype->ops) {
	PyErr_SetString(PyExc_RuntimeError, "Type has no ops!?");
	return NULL;
    }
    ret = self->otype->ops->create(&p, 
		  user_data ? user_data : self->otype->default_user_data, &h1, &h2);
    if (!ret) {
	PyErr_SetString(PyExc_RuntimeError, "could not create new object");
	return NULL;
    }
    pyret = PyTuple_New(3);
    PyTuple_SetItem(pyret, 0, PyDiaObject_New(ret));
    if (h1)
	PyTuple_SetItem(pyret, 1, PyDiaHandle_New(h1, ret));
    else {
	Py_INCREF(Py_None);
	PyTuple_SetItem(pyret, 1, Py_None);
    }
    if (h2)
	PyTuple_SetItem(pyret, 2, PyDiaHandle_New(h2, ret));
    else {
	Py_INCREF(Py_None);
	PyTuple_SetItem(pyret, 2, Py_None);
    }
    return pyret;
}