Ejemplo n.º 1
0
/* 
 *  Callback for "removed" signal, used by the connect_after method,
 *  it's a proxy for the python function, creating the values it needs.
 *  Params are those of the "removed" signal on the Diagram object.
 *  @param Diagram The Diagram that emitted the signal
 *  @param user_data The python function to be called by the callback.
 */
static void
PyDiaDiagram_CallbackRemoved(Diagram *dia,void *user_data)
{
    /* Check that we got a function */
    PyObject *diaobj,*res,*arg;
    PyObject *func = user_data;
    
    if (!func || !PyCallable_Check (func)) {
        g_warning ("Callback called without valid callback function.");
        return;
    }
      
    /* Create a new PyDiaDiagram object. This really should reuse the object that we connected to. 
     * We'll do that later.
     */
    if (dia)
        diaobj = PyDiaDiagram_New (dia);
    else {
        diaobj = Py_None;
        Py_INCREF (diaobj);
    }
      
    Py_INCREF(func);

    /* Call the callback. */
    arg = Py_BuildValue ("(O)", diaobj);
    if (arg) {
      res = PyEval_CallObject (func, arg);
      ON_RES(res, FALSE);
    }
    Py_XDECREF (arg);

    Py_DECREF(func);
    Py_XDECREF(diaobj);
}
Ejemplo n.º 2
0
static PyObject *
PyDiaDisplay_GetAttr(PyDiaDisplay *self, gchar *attr)
{
    if (!strcmp(attr, "__members__"))
	return Py_BuildValue("[ssss]", "diagram", "origin", "visible",
			     "zoom_factor");
    else if (!strcmp(attr, "diagram"))
	return PyDiaDiagram_New(self->disp->diagram);
    /* FIXME: shouldn't it have only one name */
    else if (!strcmp(attr, "origo") || !strcmp(attr, "origion") || !strcmp(attr, "origin"))
	return Py_BuildValue("(dd)", self->disp->origo.x, self->disp->origo.y);
    else if (!strcmp(attr, "zoom_factor"))
	return PyFloat_FromDouble(self->disp->zoom_factor);
    else if (!strcmp(attr, "visible"))
	return Py_BuildValue("(dddd)", self->disp->visible.top,
			     self->disp->visible.left,
			     self->disp->visible.bottom,
			     self->disp->visible.right);

    return Py_FindMethod(PyDiaDisplay_Methods, (PyObject *)self, attr);
}