[dia] PyDia: support ConnectionPoint.flags and .directions
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] PyDia: support ConnectionPoint.flags and .directions
- Date: Sat, 20 Jul 2013 22:24:59 +0000 (UTC)
commit be9457f24bcf72c837dfda3a8fdf15ec00dfc8f9
Author: Hans Breuer <hans breuer org>
Date: Sun Jun 30 11:29:54 2013 +0200
PyDia: support ConnectionPoint.flags and .directions
use it to draw connection point indices for the selected objects
plug-ins/python/mark-cps.py | 70 ++++++++++++++++++++++++++++++++++++++++
plug-ins/python/pydia-cpoint.c | 8 ++++
2 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/plug-ins/python/mark-cps.py b/plug-ins/python/mark-cps.py
new file mode 100644
index 0000000..720516a
--- /dev/null
+++ b/plug-ins/python/mark-cps.py
@@ -0,0 +1,70 @@
+# A little debug helper marking and numbering the connection points
+# of selected objects
+# Copyright (c) 2013 Hans Breuer <hans breuer org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import dia
+
+def mark_cps (data, flags) :
+ objs = data.get_sorted_selected()
+ layer = data.active_layer
+ if len(objs) == 0 :
+ dia.message (1, "Select objects for marking it's connection points!")
+ return
+ textType = dia.get_object_type("Standard - Text")
+ for o in objs:
+ for i in range(0, len(o.connections)):
+ cp = o.connections[i]
+ t, h1, h2 = textType.create (cp.pos.x, cp.pos.y)
+ t.properties["text"] = str(i)
+ # align the text based on the given directions
+ if cp.flags & 0x3 : #CP_FLAGS_MAIN
+ t.properties["text_vert_alignment"] = 3 # first line
+ if cp.directions & 0x1: # north
+ t.properties["text_vert_alignment"] = 1 # bottom
+ elif cp.directions & 0x4: # south
+ t.properties["text_vert_alignment"] = 0 # top
+ else :
+ t.properties["text_vert_alignment"] = 2 # center
+ if cp.flags & 0x3 : #CP_FLAGS_MAIN
+ t.properties["text_alignment"] = 1 # middle
+ elif cp.directions & 0x2: # east
+ t.properties["text_alignment"] = 0 # left
+ elif cp.directions & 0x8: # west
+ t.properties["text_alignment"] = 2 # right
+ else :
+ t.properties["text_alignment"] = 1 # middle
+ # tint it with the connection point color
+ if cp.flags & 0x3 : #CP_FLAGS_MAIN
+ t.properties["text_colour"] = "red"
+ elif cp.directions == 0 : # not necessarily a bug
+ t.properties["text_colour"] = "green"
+ else :
+ t.properties["text_colour"] = "blue"
+ # add it to the diagram
+ layer.add_object(t)
+ # connect the object with the cp at hand
+ h2.connect(cp)
+ # update the object and it's connected?
+ data.update_extents ()
+ adisp = dia.active_display()
+ if adisp :
+ adisp.diagram.update_extents()
+ adisp.diagram.flush()
+
+
+dia.register_action("DebugMarkConnectionPoints", "Mark Connection Points",
+ "/DisplayMenu/Debug/DebugExtensionStart", mark_cps)
diff --git a/plug-ins/python/pydia-cpoint.c b/plug-ins/python/pydia-cpoint.c
index edcf941..09265c7 100644
--- a/plug-ins/python/pydia-cpoint.c
+++ b/plug-ins/python/pydia-cpoint.c
@@ -67,6 +67,10 @@ PyDiaConnectionPoint_GetAttr(PyDiaConnectionPoint *self, gchar *attr)
return PyDiaPoint_New(&(self->cpoint->pos));
else if (!strcmp(attr, "object"))
return PyDiaObject_New(self->cpoint->object);
+ else if (!strcmp(attr, "flags"))
+ return PyInt_FromLong(self->cpoint->flags);
+ else if (!strcmp(attr, "directions"))
+ return PyInt_FromLong(self->cpoint->directions);
else if (!strcmp(attr, "connected")) {
PyObject *ret;
GList *tmp;
@@ -90,6 +94,10 @@ static PyMemberDef PyDiaConnectionPoint_Members[] = {
"Object: the object owning this connection point" },
{ "pos", T_INVALID, 0, RESTRICTED|READONLY,
"Point: read-only position of the connection point" },
+ { "flags", T_INVALID, 0, RESTRICTED|READONLY,
+ "Flags, e.g. CP_FLAGS_MAIN (=0x3)" },
+ { "directions", T_INVALID, 0, RESTRICTED|READONLY,
+ "Preferred directions away from the object (e.g. DIR_NORTH=0x1)" },
{ NULL }
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]