dia r4251 - in trunk: . lib plug-ins/python po



Author: hans
Date: Sun Feb  1 17:58:11 2009
New Revision: 4251
URL: http://svn.gnome.org/viewvc/dia?rev=4251&view=rev

Log:
2009-02-01  Hans Breuer  <hans breuer org>

	* lib/object.[ch] lib/dia_xml.[ch] lib/prop_dict.[ch] 
	  lib/properties.[ch] lib/propinternals.h lib/Makefile.am 
	  lib/libdia.def po/POTFILES.in : allow to serialize meta info with 
	every DiaObject - no UI to modify it yet
	* lib/plug-ins.h : bump api version because object size has changed
	* plug-ins/python/pydia-property.c : handle translation between Python
	and Dia dictionary to make accesible. Also s/g_warning/g_debug/
	* plug-ins/python/diasvg_import.c : generate object meta info to test
	the above. Also fixes regarding text color.



Added:
   trunk/lib/prop_dict.c   (contents, props changed)
   trunk/lib/prop_dict.h   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/lib/Makefile.am
   trunk/lib/dia_xml.c
   trunk/lib/dia_xml.h
   trunk/lib/libdia.def
   trunk/lib/makefile.msc
   trunk/lib/object.c
   trunk/lib/object.h
   trunk/lib/plug-ins.h
   trunk/lib/properties.c
   trunk/lib/properties.h
   trunk/lib/propinternals.h
   trunk/plug-ins/python/diasvg_import.py
   trunk/plug-ins/python/pydia-property.c
   trunk/po/POTFILES.in

Modified: trunk/lib/Makefile.am
==============================================================================
--- trunk/lib/Makefile.am	(original)
+++ trunk/lib/Makefile.am	Sun Feb  1 17:58:11 2009
@@ -12,6 +12,8 @@
 	propobject.c \
 	prop_basic.c \
 	prop_basic.h \
+	prop_dict.c \
+	prop_dict.h \
 	prop_inttypes.c \
 	prop_inttypes.h \
 	prop_geomtypes.c \

Modified: trunk/lib/dia_xml.c
==============================================================================
--- trunk/lib/dia_xml.c	(original)
+++ trunk/lib/dia_xml.c	Sun Feb  1 17:58:11 2009
@@ -422,6 +422,8 @@
     return DATATYPE_FONT;
   } else if (strcmp(name, "bezpoint")==0) {
     return DATATYPE_BEZPOINT;
+  } else if (strcmp(name, "dict")==0) {
+    return DATATYPE_DICT;
   }
 
   message_error("Unknown type of DataNode");

Modified: trunk/lib/dia_xml.h
==============================================================================
--- trunk/lib/dia_xml.h	(original)
+++ trunk/lib/dia_xml.h	Sun Feb  1 17:58:11 2009
@@ -58,6 +58,7 @@
   DATATYPE_STRING,
   DATATYPE_FONT,
   DATATYPE_BEZPOINT,
+  DATATYPE_DICT
 } DataType;
 
 AttributeNode object_find_attribute(ObjectNode obj_node,
@@ -97,5 +98,8 @@
 DataNode data_add_composite(AttributeNode attr, 
                             const char *type); /* can be NULL */
 
+GHashTable *data_dict (DataNode data);
+void data_add_dict (AttributeNode attr, GHashTable *data);
+
 #endif /* DIA_XML_H */
 

Modified: trunk/lib/libdia.def
==============================================================================
--- trunk/lib/libdia.def	(original)
+++ trunk/lib/libdia.def	Sun Feb  1 17:58:11 2009
@@ -288,6 +288,9 @@
  dia_object_is_selectable
  dia_object_sanity_check
 
+ dia_object_set_meta
+ dia_object_get_meta
+
  dia_plugin_can_unload
  dia_plugin_check_version
  dia_plugin_get_description

Modified: trunk/lib/makefile.msc
==============================================================================
--- trunk/lib/makefile.msc	(original)
+++ trunk/lib/makefile.msc	Sun Feb  1 17:58:11 2009
@@ -92,6 +92,7 @@
 	prefs.obj \
 	prop_attr.obj \
 	prop_basic.obj \
+	prop_dict.obj \
 	prop_geomtypes.obj \
 	prop_inttypes.obj \
 	prop_sdarray.obj \

Modified: trunk/lib/object.c
==============================================================================
--- trunk/lib/object.c	(original)
+++ trunk/lib/object.c	Sun Feb  1 17:58:11 2009
@@ -71,13 +71,15 @@
   
   if (obj->handles)
     g_free(obj->handles);
-
+  obj->handles = NULL;
   if (obj->connections)
     g_free(obj->connections);
-
+  obj->connections = NULL;
+  if (obj->meta)
+    g_hash_table_destroy (obj->meta);
+  obj->meta = NULL;
 }
 
-
 /** Copy the object-level information of this object.
  *  This includes type, position, bounding box, number of handles and
  *  connections, operations, parentability, parent and children.
@@ -591,6 +593,8 @@
 		 &obj->position);
   data_add_rectangle(new_attribute(obj_node, "obj_bb"),
 		     &obj->bounding_box);
+  if (obj->meta)
+    data_add_dict (new_attribute(obj_node, "meta"), obj->meta);
 }
 
 /** Load the object-specific parts of an object.
@@ -615,6 +619,10 @@
   attr = object_find_attribute(obj_node, "obj_bb");
   if (attr != NULL)
     data_rectangle( attribute_first_data(attr), &obj->bounding_box );
+
+  attr = object_find_attribute(obj_node, "meta");
+  if (attr != NULL)
+    obj->meta = data_dict (attribute_first_data(attr));
 }
 
 /** Returns the layer that the given object belongs to.
@@ -1017,3 +1025,25 @@
   }
   return TRUE;
 }
+
+void   
+dia_object_set_meta (DiaObject *obj, const gchar *key, const gchar *value)
+{
+  g_return_if_fail (obj != NULL && key != NULL);
+  if (!obj->meta)
+    obj->meta = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+  if (value)
+    g_hash_table_insert (obj->meta, g_strdup (key), g_strdup (value));
+  else
+    g_hash_table_remove (obj->meta, key);
+}
+
+gchar *
+dia_object_get_meta (DiaObject *obj, const gchar *key)
+{
+  gchar *val;
+  if (!obj->meta)
+    return NULL;
+  val = g_hash_table_lookup (obj->meta, key);
+  return g_strdup (val);
+}

Modified: trunk/lib/object.h
==============================================================================
--- trunk/lib/object.h	(original)
+++ trunk/lib/object.h	Sun Feb  1 17:58:11 2009
@@ -504,6 +504,8 @@
    *  objects.
    */
   Rectangle         enclosing_box;
+  /** Metainfo of the object, should not be manipulated directy */
+  GHashTable       *meta;
 };
 
 /*!
@@ -551,11 +553,14 @@
   { "obj_pos", PROP_TYPE_POINT, PROP_FLAG_OPTIONAL, \
     "Object position", "Where the object is located"}, \
   { "obj_bb", PROP_TYPE_RECT, PROP_FLAG_OPTIONAL, \
-    "Object bounding box", "The bounding box of the object"}
+    "Object bounding box", "The bounding box of the object"}, \
+  { "meta", PROP_TYPE_DICT, PROP_FLAG_OPTIONAL, \
+    "Object meta info", "Some key/value pairs"}
 
 #define OBJECT_COMMON_PROPERTIES_OFFSETS \
   { "obj_pos", PROP_TYPE_POINT, offsetof(DiaObject, position) }, \
-  { "obj_bb", PROP_TYPE_RECT, offsetof(DiaObject, bounding_box) }
+  { "obj_bb", PROP_TYPE_RECT, offsetof(DiaObject, bounding_box) }, \
+  { "meta", PROP_TYPE_DICT, offsetof(DiaObject, meta) }
 
 
 gboolean       dia_object_defaults_load (const gchar *filename,
@@ -579,6 +584,10 @@
 /** A standard definition of a function that takes a DiaObject */
 typedef void (*DiaObjectFunc) (const DiaObject *obj);
 
+/** convenience functions for meta info */
+void   dia_object_set_meta (DiaObject *obj, const gchar *key, const gchar *value);
+gchar *dia_object_get_meta (DiaObject *obj, const gchar *key);
+
 G_END_DECLS
 
 #endif /* OBJECT_H */

Modified: trunk/lib/plug-ins.h
==============================================================================
--- trunk/lib/plug-ins.h	(original)
+++ trunk/lib/plug-ins.h	Sun Feb  1 17:58:11 2009
@@ -48,7 +48,7 @@
  * The list is by no means complete. If in doubt about your change
  * please ask on dia-list or alternative increment ;-)      --hb
  */
-#define DIA_PLUGIN_API_VERSION 11
+#define DIA_PLUGIN_API_VERSION 12
 
 typedef enum {
   DIA_PLUGIN_INIT_OK,

Added: trunk/lib/prop_dict.c
==============================================================================
--- (empty file)
+++ trunk/lib/prop_dict.c	Sun Feb  1 17:58:11 2009
@@ -0,0 +1,210 @@
+/* Dia -- a diagram creation/manipulation program -*- c -*-
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * Property system for dia objects/shapes.
+ * Copyright (C) 2000 James Henstridge
+ * Copyright (C) 2001 Cyrille Chepelov
+ * Copyright (C) 2009 Hans Breuer
+ *
+ * Property types for dictonaries.
+ * These dictionaries are simple key/value pairs both of type string.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#define WIDGET GtkWidget
+#include "widgets.h"
+#include "properties.h"
+#include "propinternals.h"
+
+typedef struct _WellKnownKeys {
+  const gchar *name;
+  const gchar *display_name;
+} WellKnownKeys;
+
+/* a list of wel known keys with their display name */
+static WellKnownKeys _well_known[] = {
+  { "author", N_("Author") },
+  { "id", N_("Identifier") },
+  { "creation", N_("Creation date") },
+  { "modification", N_("Modification date") },
+  { "url", N_("URL") },
+  { NULL, NULL }
+};
+ 
+static DictProperty *
+dictprop_new(const PropDescription *pdesc, PropDescToPropPredicate reason)
+{
+  DictProperty *prop = g_new0(DictProperty,1);
+
+  initialize_property(&prop->common, pdesc, reason);  
+  prop->dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+  return prop;
+}
+
+static void
+dictprop_free(DictProperty *prop) 
+{
+  if (prop->dict)
+    g_hash_table_destroy(prop->dict);
+  g_free(prop);
+} 
+
+static void
+_keyvalue_copy (gpointer key,
+                gpointer value,
+                gpointer user_data)
+{
+  gchar *name = (gchar *)key;
+  gchar *val = (gchar *)value;
+  GHashTable *dest = (GHashTable *)user_data;
+  
+  g_hash_table_insert (dest, g_strdup (key), g_strdup (value));
+}
+static DictProperty *
+dictprop_copy(DictProperty *src) 
+{
+  DictProperty *prop = 
+    (DictProperty *)src->common.ops->new_prop(src->common.descr,
+                                              src->common.reason);
+  if (src->dict)
+    g_hash_table_foreach (src->dict, _keyvalue_copy, prop->dict);
+  
+  return prop;
+}
+
+static void 
+dictprop_load(DictProperty *prop, AttributeNode attr, DataNode data)
+{
+  guint nvals = attribute_num_data(attr);
+  if (!nvals)
+    return;
+
+  while (data) {
+    gchar *value = data_string(data);
+    const gchar *key = data->name;
+    if (!key)
+      g_warning ("Dictionary key missing");
+    if (value && key)
+      g_hash_table_insert (prop->dict, g_strdup(key), value);
+    data = data_next(data);
+  }
+}
+
+static GHashTable *
+_hash_dup (const GHashTable *src)
+{
+  GHashTable *dest = NULL;
+  if (src) {
+    dest = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+    g_hash_table_foreach ((GHashTable *)src, _keyvalue_copy, dest);
+  }
+  return dest;  
+}
+
+static void
+_keyvalue_save (gpointer key,
+                gpointer value,
+                gpointer user_data)
+{
+  gchar *name = (gchar *)key;
+  gchar *val = (gchar *)value;
+  ObjectNode node = (ObjectNode)user_data;
+
+  data_add_string(new_attribute(node, name), val);
+}
+static void 
+dictprop_save(DictProperty *prop, AttributeNode attr) 
+{
+  ObjectNode composite = data_add_composite(attr, "dict");
+  if (prop->dict)
+    g_hash_table_foreach (prop->dict, _keyvalue_save, composite); 
+}
+
+static void 
+dictprop_get_from_offset(DictProperty *prop,
+                         void *base, guint offset, guint offset2) 
+{
+  prop->dict = _hash_dup (struct_member(base,offset,GHashTable *));
+}
+
+static void 
+dictprop_set_from_offset(DictProperty *prop,
+                         void *base, guint offset, guint offset2)
+{
+  GHashTable *dest = struct_member(base,offset,GHashTable *);
+  if (dest)
+    g_hash_table_destroy (dest);
+  struct_member(base,offset, GHashTable *) = _hash_dup (prop->dict);
+}
+
+static const PropertyOps dictprop_ops = {
+  (PropertyType_New) dictprop_new,
+  (PropertyType_Free) dictprop_free,
+  (PropertyType_Copy) dictprop_copy,
+  (PropertyType_Load) dictprop_load,
+  (PropertyType_Save) dictprop_save,
+  (PropertyType_GetWidget) noopprop_get_widget,
+  (PropertyType_ResetWidget) noopprop_reset_widget,
+  (PropertyType_SetFromWidget) noopprop_set_from_widget,
+
+  (PropertyType_CanMerge) noopprop_can_merge,
+  (PropertyType_GetFromOffset) dictprop_get_from_offset,
+  (PropertyType_SetFromOffset) dictprop_set_from_offset
+};
+
+void 
+prop_dicttypes_register(void)
+{
+  prop_type_register(PROP_TYPE_DICT, &dictprop_ops);
+}
+
+GHashTable *
+data_dict (DataNode data)
+{
+  GHashTable *ht = NULL;
+  int nvals = attribute_num_data (data);
+  
+  if (nvals) {
+    DataNode kv = attribute_first_data (data);
+    gchar *val = NULL;
+
+    ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+    while (kv) {
+      xmlChar *key = xmlGetProp(kv, (const xmlChar *)"name");
+
+      if (key) {
+        val = data_string (attribute_first_data (kv));
+        if (val)
+          g_hash_table_insert (ht, g_strdup ((gchar *)key), val);
+	xmlFree (key);
+      }
+      kv = data_next (kv);
+    }
+  }
+  return ht;
+}
+
+void
+data_add_dict (AttributeNode attr, GHashTable *data)
+{
+  ObjectNode composite = data_add_composite(attr, "dict");
+
+  g_hash_table_foreach (data, _keyvalue_save, composite); 
+}

Added: trunk/lib/prop_dict.h
==============================================================================
--- (empty file)
+++ trunk/lib/prop_dict.h	Sun Feb  1 17:58:11 2009
@@ -0,0 +1,38 @@
+/* Dia -- a diagram creation/manipulation program -*- c -*-
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * Property system for dia objects/shapes.
+ * Copyright (C) 2000 James Henstridge
+ * Copyright (C) 2001 Cyrille Chepelov
+ * Copyright (C) 2009 Hans Breuer
+ *
+ * Property types for dictonaries.
+ * These dictionaries are simple key/value pairs both of type string.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#ifndef PROP_DICT_H
+#define PROP_DICT_H
+
+#include "properties.h"
+#include "dia_xml.h"
+
+typedef struct {
+  Property common;
+  GHashTable *dict; /* subprops[i] is a GPtrArray of (Property *) */  
+} DictProperty;
+
+void prop_dicttypes_register(void);
+#endif

Modified: trunk/lib/properties.c
==============================================================================
--- trunk/lib/properties.c	(original)
+++ trunk/lib/properties.c	Sun Feb  1 17:58:11 2009
@@ -49,7 +49,8 @@
   prop_attr_register();
   prop_text_register();
   prop_widgets_register();
-  prop_sdarray_register();  
+  prop_sdarray_register();
+  prop_dicttypes_register();
 }
 
 /* --------------------------------------- */

Modified: trunk/lib/properties.h
==============================================================================
--- trunk/lib/properties.h	(original)
+++ trunk/lib/properties.h	Sun Feb  1 17:58:11 2009
@@ -197,6 +197,7 @@
 /* Special types : */
 #define PROP_TYPE_SARRAY "sarray" /* ArrayProperty */
 #define PROP_TYPE_DARRAY "darray" /* ArrayProperty */
+#define PROP_TYPE_DICT "dict" /* DictProperty */
 
 /* **************************************************************** */
 

Modified: trunk/lib/propinternals.h
==============================================================================
--- trunk/lib/propinternals.h	(original)
+++ trunk/lib/propinternals.h	Sun Feb  1 17:58:11 2009
@@ -88,6 +88,7 @@
 #include "prop_text.h"
 #include "prop_widgets.h"
 #include "prop_sdarray.h"
+#include "prop_dict.h"
 
 #endif /* PROPINTERNALS_H */
 

Modified: trunk/plug-ins/python/diasvg_import.py
==============================================================================
--- trunk/plug-ins/python/diasvg_import.py	(original)
+++ trunk/plug-ins/python/diasvg_import.py	Sun Feb  1 17:58:11 2009
@@ -136,7 +136,7 @@
 			self.props["line-style"] = (3, dlen) # LINESTYLE_DASH_DOT_DOT,
 	def id(self, s) :
 		# just to handle/ignore it
-		self.props["id"] = s
+		self.props["meta"] = { "id" : s }
 	def transform(self, s) :
 		m = rTranslate.match(s)
 		if m :
@@ -173,21 +173,31 @@
 				# Dia can't really display stroke none, some workaround :
 				if self.props.has_key("fill") and self.props["fill"] != "none" : 
 					#does it really matter ?
-					o.properties["line_colour"] = Color(self.props["fill"])
+					try :
+						o.properties["line_colour"] = Color(self.props["fill"])
+					except :
+						pass
 				o.properties["line_width"] = 0.0
 		if self.props.has_key("fill") and o.properties.has_key("fill_colour") :
 			if self.props["fill"] == "none" :
 				o.properties["show_background"] = 0
 			else :
-				o.properties["show_background"] = 1
+				color_key = "fill_colour"
 				try :
-					o.properties["fill_colour"] =Color(self.props["fill"])
+					o.properties["show_background"] = 1
+				except KeyError :
+					# not sure if this is always true
+					color_key = "text_colour"
+				try :
+					o.properties[color_key] =Color(self.props["fill"])
 				except :
 					# rgb(192,27,38) handled by Color() but ...
 					# o.properties["fill_colour"] =self.props["fill"]
 					pass
 		if self.props.has_key("line-style") and o.properties.has_key("line_style") :
 			o.properties["line_style"] = self.props["line-style"]
+		if self.props.has_key("meta") and o.properties.has_key("meta") :
+			o.properties["meta"] = self.props["meta"]
 		self.ApplyProps(o)
 		return o
 
@@ -529,7 +539,7 @@
 			elif self.props["text-anchor"] == "end" : o.properties["text_alignment"] = 2
 			else : o.properties["text_alignment"] = 0
 		if self.props.has_key("fill") :
-			o.properties["text_colour"] = self.props["fill"]
+			o.properties["text_colour"] = Color(self.props["fill"])
 		if self.props.has_key("font-size") :
 			o.properties["text_height"] = self.props["font-size"]
 class Desc(Object) :
@@ -621,11 +631,12 @@
 				try :
 					_eval(s, locals())
 				except AttributeError, msg :
-					if not self.errors.has_key(s) :
-						self.errors[s] = msg
+					o.props["meta"] = { a : attrs[a] }
+					if not self.errors.has_key(msg) :
+						self.errors[msg] = s
 				except SyntaxError, msg :
-					if not self.errors.has_key(s) :
-						self.errors[s] = msg
+					if not self.errors.has_key(msg) :
+						self.errors[msg] = s
 			if grp is None :
 				self.objects.append(o)
 			else :

Modified: trunk/plug-ins/python/pydia-property.c
==============================================================================
--- trunk/plug-ins/python/pydia-property.c	(original)
+++ trunk/plug-ins/python/pydia-property.c	Sun Feb  1 17:58:11 2009
@@ -37,6 +37,7 @@
 #include "prop_attr.h"
 #include "prop_text.h"
 #include "prop_sdarray.h"
+#include "prop_dict.h"
 
 /*
  * New
@@ -192,6 +193,9 @@
 
 static PyObject * PyDia_get_Array (ArrayProperty *prop);
 
+static PyObject * PyDia_get_Dict (DictProperty *prop);
+static int PyDia_set_Dict (Property *prop, PyObject *val);
+
 static int
 PyDia_set_Bool (Property *prop, PyObject *val)
 {
@@ -259,7 +263,7 @@
       p->color_data.blue = color.blue / 65535.0;
       return 0;
     } else
-      g_warning("Failed to parse color string '%s'", str);
+      g_debug("Failed to parse color string '%s'", str);
   } else if (PyTuple_Check (val)) {
     int i, len = PyTuple_Size(val);
     real f[3];
@@ -455,9 +459,9 @@
         bpt.p3.y = PyFloat_AsDouble(PyTuple_GetItem(o, 6));
       } else {
         if (0 == i && tp != BEZ_MOVE_TO)
-          g_warning("First bezpoint must be BEZ_MOVE_TO");
+          g_debug("First bezpoint must be BEZ_MOVE_TO");
         if (0 < i && tp != BEZ_LINE_TO)
-          g_warning("Further bezpoint must be BEZ_LINE_TO or BEZ_CURVE_TO");
+          g_debug("Further bezpoint must be BEZ_LINE_TO or BEZ_CURVE_TO");
 
         bpt.type = (0 == i) ? BEZ_MOVE_TO : BEZ_LINE_TO;
         /* not strictly needed */
@@ -516,7 +520,8 @@
   { PROP_TYPE_COLOUR, PyDia_get_Color, PyDia_set_Color },
   { PROP_TYPE_FONT, PyDia_get_Font },
   { PROP_TYPE_SARRAY, PyDia_get_Array, PyDia_set_Array },
-  { PROP_TYPE_DARRAY, PyDia_get_Array, PyDia_set_Array }
+  { PROP_TYPE_DARRAY, PyDia_get_Array, PyDia_set_Array },
+  { PROP_TYPE_DICT, PyDia_get_Dict, PyDia_set_Dict }
 };
 
 static void
@@ -596,7 +601,7 @@
 	setters[i] = (PyDiaPropSetFunc)prop_type_map[j].propset;
     }
     if (!setters[i]) {
-      g_warning("No setter for '%s'", ex->type);
+      g_debug("No setter for '%s'", ex->type);
       g_free(setters);
       return -1;
     }
@@ -620,7 +625,7 @@
       GPtrArray *record = g_ptr_array_new();
       guint j;
       if (!PyTuple_Check(t) || PyTuple_Size(t) != num_props) {
-        g_warning("PyDia_set_Array: %s.", !PyTuple_Check(t) ? "no tuple" : " wrong size");
+        g_debug("PyDia_set_Array: %s.", !PyTuple_Check(t) ? "no tuple" : " wrong size");
 	ret = -1;
 	break;
       }
@@ -634,7 +639,7 @@
 	  if (Py_None == v) {
             /* use just the defaults, setters don't need to handle this */
 	  } else {
-	    g_warning ("Failed to set '%s::%s' from '%s'", 
+	    g_debug ("Failed to set '%s::%s' from '%s'", 
 	      p->common.name, inner->name, v->ob_type->tp_name);
 	    inner->ops->free(inner);
 	    ret = -1;
@@ -652,6 +657,54 @@
   return ret;
 }
 
+static void
+_keyvalue_get (gpointer key,
+               gpointer value,
+               gpointer user_data)
+{
+  gchar *name = (gchar *)key;
+  gchar *val = (gchar *)value;
+  PyObject *dict = (PyObject *)user_data;
+  PyObject *k, *v;
+  
+  k = PyString_FromString(name);
+  v = PyString_FromString(val);
+  if (k && v)
+    PyDict_SetItem(dict, k, v);
+  Py_XDECREF(k);
+  Py_XDECREF(v);
+}
+static PyObject *
+PyDia_get_Dict (DictProperty *prop)
+{
+  PyObject *dict = PyDict_New();
+  if (prop->dict)
+    g_hash_table_foreach (prop->dict, _keyvalue_get, dict);
+  return dict;
+}
+static int
+PyDia_set_Dict (Property *prop, PyObject *val)
+{
+  DictProperty *p = (DictProperty *)prop;
+
+  if PyDict_Check(val) {
+    int i = 0; /* not to be modified! */
+    PyObject *key, *value;
+
+
+    if (!p->dict)
+      p->dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+    while (PyDict_Next(val, &i, &key, &value)) {
+      /* CHECK semantics: replace or add? */
+      g_hash_table_insert (p->dict, 
+	                   g_strdup (PyString_AsString (key)), 
+			   g_strdup (PyString_AsString (value)));
+    }
+    return 0;
+  }
+  return -1;
+}
+
 /*
  * GetAttr
  */
@@ -675,7 +728,7 @@
       if (prop_type_map[i].quark == self->property->type_quark)
         return prop_type_map[i].propget(self->property);
     if (0 == (PROP_FLAG_WIDGET_ONLY & self->property->descr->flags))
-      g_warning ("No handler for type '%s'", self->property->type);
+      g_debug ("No handler for type '%s'", self->property->type);
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -711,7 +764,7 @@
       prop_list_free (plist);
       return 0;
     } else {
-      g_warning("PyDiaProperty_ApplyToObject : no property conversion %s -> %s",
+      g_debug("PyDiaProperty_ApplyToObject : no property conversion %s -> %s",
 	             inprop->type, prop->type);
     }
   } else {
@@ -720,14 +773,14 @@
     for (i = 0; i < G_N_ELEMENTS(prop_type_map); i++) {
       if (prop_type_map[i].quark == prop->type_quark) {
 	if (!prop_type_map[i].propset)
-	  g_warning("Setter for '%s' not implemented.", prop_type_map[i].type);
+	  g_debug("Setter for '%s' not implemented.", prop_type_map[i].type);
 	else if (0 == prop_type_map[i].propset(prop, val))
 	  ret = 0;
 	break;
       }
     }
     if (ret != 0)
-      g_warning("PyDiaProperty_ApplyToObject : no conversion %s -> %s",
+      g_debug("PyDiaProperty_ApplyToObject : no conversion %s -> %s",
 	             key, prop->type);
   }
 

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Sun Feb  1 17:58:11 2009
@@ -54,6 +54,7 @@
 lib/newgroup.c
 lib/object_defaults.c
 lib/plug-ins.c
+lib/prop_dict.c
 lib/prop_inttypes.c
 lib/prop_text.c
 lib/prop_widgets.c



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