Ejemplo n.º 1
0
/*! 
 *  Callback for "object_add" and "object_remove "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 signals on the Diagram object.
 *  @param dia The DiagramData that emitted the signal
 *  @param layer The Layer that the object is removed or added to.
 *  @param obj The DiaObject that the signal is about.
 *  @param user_data The python function to be called by the callback.
 */
static void
PyDiaDiagramData_CallbackObject(DiagramData *dia,Layer *layer,DiaObject *obj,void *user_data)
{
    PyObject *pydata,*pylayer,*pyobj,*res,*arg;
    PyObject *func = user_data;
    
    /* Check that we got a function */   
    if (!func || !PyCallable_Check (func)) {
        g_warning ("Callback called without valid callback function.");
        return;
    }
      
    /* Create a new PyDiaDiagramData object.
     */
    if (dia)
        pydata = PyDiaDiagramData_New (dia);
    else {
        pydata = Py_None;
        Py_INCREF (pydata);
    }
      
    /*
     * Create PyDiaLayer
     */
    if (layer)
        pylayer = PyDiaLayer_New (layer);
    else {
        pylayer = Py_None;
        Py_INCREF (pylayer);
    }   
    
    /*
     * Create PyDiaObject
     */
    if (layer)
        pyobj = PyDiaObject_New (obj);
    else {
        pyobj = Py_None;
        Py_INCREF (pyobj);
    }   
    
    
    Py_INCREF(func);

    /* Call the callback. */
    arg = Py_BuildValue ("(OOO)", pydata,pylayer,pyobj);
    if (arg) {
      res = PyEval_CallObject (func, arg);
      ON_RES(res, FALSE);
    }
    
    /* Cleanup */
    Py_XDECREF (arg);
    Py_DECREF(func);
    Py_XDECREF(pydata);
    Py_XDECREF(pylayer);
    Py_XDECREF(pyobj);
}
Ejemplo n.º 2
0
static PyObject *
PyDiaDiagramData_AddLayer(PyDiaDiagramData *self, PyObject *args)
{
    gchar *name;
    int pos = -1;
    Layer *layer;

    if (!PyArg_ParseTuple(args, "s|i:DiagramData.add_layer", &name, &pos))
	return NULL;
    layer = new_layer(g_strdup(name),self->data);
    if (pos != -1)
	data_add_layer_at(self->data, layer, pos);
    else
	data_add_layer(self->data, layer);
    return PyDiaLayer_New(layer);
}
Ejemplo n.º 3
0
/*! 
 * \brief Render all the visible object in the layer
 * @param renderer explicit this pointer
 * @param layer    layer to draw
 * @param active   TRUE if it is the currently active layer
 * @param update   the update rectangle, NULL for unlimited
 *
 * \memberof _DiaPyRenderer
 */
static void
draw_layer (DiaRenderer *renderer,
	    Layer       *layer,
	    gboolean     active,
	    Rectangle   *update)
{
  PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer);

  func = PyObject_GetAttrString (self, "draw_layer");
  if (func && PyCallable_Check(func)) {
    PyObject *olayer = PyDiaLayer_New (layer);
    PyObject *orect;

    Py_INCREF (self);
    Py_INCREF (func);
    if (update) {
      orect = PyDiaRectangle_New (update, NULL);
    } else {
      Py_INCREF(Py_None);
      orect = Py_None;
    }
    arg = Py_BuildValue ("(OiO)", olayer, active, orect);
    if (arg) {
      res = PyEval_CallObject (func, arg);
      ON_RES(res, FALSE);
    }
    Py_XDECREF (olayer);
    Py_XDECREF (orect);
    Py_DECREF(func);
    Py_DECREF(self);
  } else { /* member optional */
    PyErr_Clear();
    /* have to call the base class */
    DIA_RENDERER_CLASS (parent_class)->draw_layer (renderer, layer, active, update);
  }
}
Ejemplo n.º 4
0
static PyObject *
PyDiaDiagramData_GetAttr(PyDiaDiagramData *self, gchar *attr)
{
    Diagram *diagram = DIA_DIAGRAM(self->data);

    if (!strcmp(attr, "__members__"))
	return Py_BuildValue("[ssssssssssss]",
                           "extents", "bg_color", "paper",
                           "layers", "active_layer", 
                           "grid_width", "grid_visible", 
                           "hguides", "vguides",
                           "layers", "active_layer",
                           "selected" );
    else if (!strcmp(attr, "extents"))
      return PyDiaRectangle_New(&self->data->extents, NULL);
    else if (!strcmp(attr, "bg_color")) {
      return PyDiaColor_New (&(self->data->bg_color));
    }
    else if (!strcmp(attr, "layers")) {
	guint i, len = self->data->layers->len;
	PyObject *ret = PyTuple_New(len);

	for (i = 0; i < len; i++)
	    PyTuple_SetItem(ret, i, PyDiaLayer_New(
			g_ptr_array_index(self->data->layers, i)));
	return ret;
    } else if (!strcmp(attr, "active_layer")) {
	return PyDiaLayer_New(self->data->active_layer);
    } else if (!strcmp(attr, "paper")) {
        return PyDiaPaperinfo_New (&self->data->paper);
    }
    else if (diagram && !strcmp(attr, "grid_width")) 
      return Py_BuildValue("(dd)", diagram->grid.width_x, diagram->grid.width_y);
    else if (diagram && !strcmp(attr, "grid_visible")) 
      return Py_BuildValue("(ii)", diagram->grid.visible_x, diagram->grid.visible_y);
    else if (diagram && !strcmp(attr, "hguides")) {
      int len = diagram->guides.nhguides;
      PyObject *ret = PyTuple_New(len);
      int i;
      for (i = 0; i < len; i++)
        PyTuple_SetItem(ret, i, PyFloat_FromDouble(diagram->guides.hguides[i]));
      return ret;
    }
    else if (diagram && !strcmp(attr, "vguides")) {
      int len = diagram->guides.nvguides;
      PyObject *ret = PyTuple_New(len);
      int i;
      for (i = 0; i < len; i++)
        PyTuple_SetItem(ret, i, PyFloat_FromDouble(diagram->guides.vguides[i]));
      return ret;
    }
    else if (!strcmp(attr, "layers")) {
	guint i, len = self->data->layers->len;
	PyObject *ret = PyTuple_New(len);

	for (i = 0; i < len; i++)
	    PyTuple_SetItem(ret, i, PyDiaLayer_New(
			g_ptr_array_index(self->data->layers, i)));
	return ret;
    }
    else if (!strcmp(attr, "active_layer")) {
      return PyDiaLayer_New(self->data->active_layer);
    }
    else if (!strcmp(attr, "selected")) {
	PyObject *ret;
	GList *tmp;
	gint i;

	ret = PyTuple_New(g_list_length(self->data->selected));
	for (i = 0, tmp = self->data->selected; tmp; i++, tmp = tmp->next)
	    PyTuple_SetItem(ret, i, PyDiaObject_New((DiaObject *)tmp->data));
	return ret;
    }

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