[dia] PyDia: support DiagramData.diagram (kind of dynamic cast)
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] PyDia: support DiagramData.diagram (kind of dynamic cast)
- Date: Sat, 26 Apr 2014 17:17:17 +0000 (UTC)
commit 5e9d0490107542e2a5852610bb36da385f26707d
Author: Hans Breuer <hans breuer org>
Date: Mon Apr 21 16:52:20 2014 +0200
PyDia: support DiagramData.diagram (kind of dynamic cast)
The DiagramData object passed to plug-ins usually is-a Diagram, too.
The new read-only attribute can be used to access methods only
implemented by the latter.
plug-ins/python/pydia-diagramdata.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/plug-ins/python/pydia-diagramdata.c b/plug-ins/python/pydia-diagramdata.c
index d8de53e..4dc3f0c 100644
--- a/plug-ins/python/pydia-diagramdata.c
+++ b/plug-ins/python/pydia-diagramdata.c
@@ -32,6 +32,7 @@
#include <structmember.h> /* PyMemberDef */
#include "app/diagram.h"
+#include "pydia-diagram.h" /* support dynamic_cast */
PyObject *
PyDiaDiagramData_New(DiagramData *dd)
@@ -333,6 +334,8 @@ static PyMemberDef PyDiaDiagramData_Members[] = {
"List of real: vertical guides."},
{ "selected", T_INVALID, 0, RESTRICTED|READONLY,
"List of Object: current selection."},
+ { "diagram", T_INVALID, 0, RESTRICTED|READONLY,
+ "This data objects Diagram or None"},
{ NULL }
};
@@ -409,6 +412,12 @@ PyDiaDiagramData_GetAttr(PyDiaDiagramData *self, gchar *attr)
PyTuple_SetItem(ret, i, PyDiaObject_New((DiaObject *)tmp->data));
return ret;
}
+ else if (!strcmp(attr, "diagram")) {
+ if (DIA_IS_DIAGRAM (self->data))
+ return PyDiaDiagram_New (DIA_DIAGRAM (self->data));
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
return Py_FindMethod(PyDiaDiagramData_Methods, (PyObject *)self, attr);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]