[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

StdProp overhaul: broken plug-ins



+	* plug-ins/python/**/*: I gave up converting this; I can't
+	compile --with-python (problems with object.h defined both by us
+	and by Python). I'll gladly help whomever cares to fix it !
+	(or, fix it myself if someone tells me how to compile it).
+

Hi Cyrille,
while making the Python plug-in compile again I stumbled over
two issues with the new property access, which would be nice
if you could address them.

1) it would be nice if one could get a property refernce directly
from the object, like:

/* Return a reference to objects property with 'name' or NULL */
Property     *object_find_prop (Object *obj, const char* name);

2) IMO the property->type should become integral again, to allow
for a switch statement, instead of string comparsions. See patch.

BTW: 'eml' still doesn't compile.

Thanks in advance,
	Hans

diff --exclude-from=c:\util\tool\diff.ign -u -r
from-cvs/dia/plug-ins/python/pydia-display.c
my-gtk/dia/plug-ins/python/pydia-display.c
--- from-cvs/dia/plug-ins/python/pydia-display.c	Fri Mar 23 20:03:54 2001
+++ my-gtk/dia/plug-ins/python/pydia-display.c	Sun Jul 08 14:19:34 2001
@@ -220,7 +220,8 @@
 			     "zoom_factor");
     else if (!strcmp(attr, "diagram"))
 	return PyDiaDiagram_New(self->disp->diagram);
-    else if (!strcmp(attr, "origo") || !strcmp(attr, "origion"))
+    /* 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);
diff --exclude-from=c:\util\tool\diff.ign -u -r
from-cvs/dia/plug-ins/python/pydia-font.c
my-gtk/dia/plug-ins/python/pydia-font.c
--- from-cvs/dia/plug-ins/python/pydia-font.c	Fri Mar 23 20:03:56 2001
+++ my-gtk/dia/plug-ins/python/pydia-font.c	Wed Aug 15 12:48:34 2001
@@ -27,7 +27,7 @@
 /*
  * New
  */
-PyObject* PyDiaFont_New (Font* font)
+PyObject* PyDiaFont_New (DiaFont* font)
 {
   PyDiaFont *self;
   
diff --exclude-from=c:\util\tool\diff.ign -u -r
from-cvs/dia/plug-ins/python/pydia-font.h
my-gtk/dia/plug-ins/python/pydia-font.h
--- from-cvs/dia/plug-ins/python/pydia-font.h	Sat Aug 11 13:47:14 2001
+++ my-gtk/dia/plug-ins/python/pydia-font.h	Wed Aug 15 12:47:16 2001
@@ -11,6 +11,6 @@
 
 extern PyTypeObject PyDiaFont_Type;
 
-PyObject* PyDiaFont_New (Font* font);
+PyObject* PyDiaFont_New (DiaFont* font);
 
 #endif
\ No newline at end of file
diff --exclude-from=c:\util\tool\diff.ign -u -r
from-cvs/dia/plug-ins/python/pydia-properties.c
my-gtk/dia/plug-ins/python/pydia-properties.c
--- from-cvs/dia/plug-ins/python/pydia-properties.c	Fri May 25 18:35:42 2001
+++ my-gtk/dia/plug-ins/python/pydia-properties.c	Wed Aug 15 17:52:42 2001
@@ -98,17 +98,11 @@
     return NULL;
 
   if (self->object->ops->get_props != NULL) {
-    Property prop;
-
-    prop.name = PyString_AsString(key);
-    prop.type = PROP_TYPE_INVALID;
-    if (prop.name) {
-      /* Get the first property with name */
-      self->object->ops->get_props(self->object, &prop, 1);
-      if (prop.type != PROP_TYPE_INVALID)
-        val = PyDiaProperty_New(&prop); /* makes a copy, too. */
-      prop_free(&prop);
-    }
+    Property *p;
+    char* name = PyString_AsString(key);
+    p = object_find_prop (self->object, name);  
+    if (p && p->type != PROP_TYPE_INVALID)
+      val = PyDiaProperty_New(p); /* makes a copy */
   }
  
   if (val == NULL) { 
@@ -132,22 +126,12 @@
     ok = 0; /* is this too drastic? */
 
   if (self->object->ops->get_props != NULL) {
-    Property prop;
-    PropDescription *desc;
-
-    prop.name = PyString_AsString(key);
+    Property *p;
+    char     *name;
 
-    desc = self->object->ops->describe_props(self->object);
-    desc = prop_desc_list_find_prop (desc, prop.name);
-
-    prop.type = desc->type;
+    name = PyString_AsString(key);
 
-    if (prop.name) {
-      /* Get the first property with name */
-      self->object->ops->get_props(self->object, &prop, 1);
-      ok = (prop.type != PROP_TYPE_INVALID);
-      prop_free(&prop);
-    }
+    ok = (NULL != object_find_prop (self->object, name));
   }
 
   return PyInt_FromLong(ok);
@@ -205,23 +189,14 @@
     return NULL;
   }
   else {
-    Property prop;
-    PropDescription *desc;
+    Property *p;
+    char     *name;  
 
-    prop.name = PyString_AsString(key);
+    name = PyString_AsString(key);
+    p = object_find_prop (self->object, name);
 
-    desc = self->object->ops->describe_props(self->object);
-    desc = prop_desc_list_find_prop (desc, prop.name);
-
-    prop.type = desc->type;
-
-    if (prop.name) {
-      /* Get the first property with name */
-      self->object->ops->get_props(self->object, &prop, 1);
-      if (prop.type != PROP_TYPE_INVALID)
-        v = PyDiaProperty_New(&prop); /* makes a copy, too. */
-      prop_free(&prop);
-    }
+    if (p && p->type != PROP_TYPE_INVALID)
+      v = PyDiaProperty_New(p); /* makes a copy */
   }
 
   if (v == NULL)
@@ -286,4 +261,3 @@
     0L,0L,0L,0L,
     NULL
 };
-
diff --exclude-from=c:\util\tool\diff.ign -u -r
from-cvs/dia/plug-ins/python/pydia-properties.h
my-gtk/dia/plug-ins/python/pydia-properties.h
--- from-cvs/dia/plug-ins/python/pydia-properties.h	Fri Dec 22 17:27:12 2000
+++ my-gtk/dia/plug-ins/python/pydia-properties.h	Wed Aug 15 17:30:00 2001
@@ -7,7 +7,7 @@
 
 typedef struct {
     PyObject_HEAD
-    Property property; 
+    Property* property; 
 } PyDiaProperty;
 
 extern PyTypeObject PyDiaProperty_Type;
diff --exclude-from=c:\util\tool\diff.ign -u -r
from-cvs/dia/plug-ins/python/pydia-property.c
my-gtk/dia/plug-ins/python/pydia-property.c
--- from-cvs/dia/plug-ins/python/pydia-property.c	Fri May 25 18:35:42 2001
+++ my-gtk/dia/plug-ins/python/pydia-property.c	Wed Aug 15 17:48:52 2001
@@ -37,7 +37,7 @@
   self = PyObject_NEW(PyDiaProperty, &PyDiaProperty_Type);
   if (!self) return NULL;
   
-  prop_copy(&(self->property), property);
+  self->property = property->ops->copy (property);
 
   return (PyObject *)self;
 }
@@ -48,7 +48,7 @@
 static void
 PyDiaProperty_Dealloc(PyDiaProperty *self)
 {
-  prop_free(&(self->property));
+  self->property->ops->free(self->property);
   PyMem_DEL(self);
 }
 
@@ -81,13 +81,14 @@
   if (!strcmp(attr, "__members__"))
     return Py_BuildValue("[sss]", "name", "type", "value");
   else if (!strcmp(attr, "name"))
-    return PyString_FromString(self->property.name);
+    return PyString_FromString(self->property->name);
   else if (!strcmp(attr, "type"))
-    return PyInt_FromLong(self->property.type);
+    return PyInt_FromLong(self->property->type);
   else if (!strcmp(attr, "value")) {
-    switch (self->property.type) {
+#ifdef THE_PROP_TYPE_ID_IS_INTEGRAL
+    switch (self->property->type) {
     case PROP_TYPE_CHAR :
-      return PyInt_FromLong(self->property.d.char_data);
+      return PyInt_FromLong(((CharProperty*)self->property)->char_data);
     case PROP_TYPE_BOOL :
       return PyInt_FromLong(self->property.d.bool_data);
     case PROP_TYPE_INT :
@@ -124,6 +125,7 @@
       Py_INCREF(Py_None);
       return Py_None;
     } /* switch */
+#endif
   }
 
   PyErr_SetString(PyExc_AttributeError, attr);
@@ -140,6 +142,7 @@
   gchar* tname = "OTHER";
   gchar* s;
 
+#ifdef THE_PROP_TYPE_ID_IS_INTEGRAL
 #define CASE_STR(s) case PROP_TYPE_##s : tname = #s; break;
   switch (self->property.type) {
   CASE_STR(INVALID)
@@ -163,11 +166,16 @@
     tname = "OTHER";
   }
 #undef CASE_STR
-
   s = g_strdup_printf("<DiaProperty at 0x%08x, \"%s\", %s>",
                       self,
                       self->property.name,
                       tname);
+#else
+  s = g_strdup_printf("<DiaProperty at 0x%08x, \"%s\", %s>",
+                      self,
+                      self->property->name,
+                      self->property->type);
+#endif
   py_s = PyString_FromString(s);
   g_free (s);
   return py_s;

-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to 
get along without it.                -- Dilbert




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK