[dia] bindings: reduce bit rot



commit 85c8c24ad4ede5adc7af8fa757bbdbfdde2d6e0c
Author: Hans Breuer <hans breuer org>
Date:   Sun Jan 19 11:57:54 2014 +0100

    bindings: reduce bit rot
    
     - adjust test.py for some function renaming
     - implement dia.message() and dia:group_create()
     - use DiaContext in dia::ObjectType::save()
     - disable dia::ObjectType::get_defaults()
     - fix typos

 bindings/dia-diagramdata.h |    8 ++++----
 bindings/dia-extra.cpp     |   32 ++++++++++++++++++++++++++++++++
 bindings/dia-extra.h       |    8 +++++++-
 bindings/dia-object.cpp    |    7 ++++++-
 bindings/dia-object.h      |    2 ++
 bindings/dia.swig          |   23 ++++++++++++++++++++++-
 bindings/makefile.msc      |    2 +-
 bindings/test.py           |   11 +++++------
 8 files changed, 79 insertions(+), 14 deletions(-)
---
diff --git a/bindings/dia-diagramdata.h b/bindings/dia-diagramdata.h
index 60f91b1..84b3168 100644
--- a/bindings/dia-diagramdata.h
+++ b/bindings/dia-diagramdata.h
@@ -24,7 +24,7 @@ class Object;
 class Objects
 {
 public :
-    //! dont use
+    //! don't use
     Objects () : list(0) {}
 
     //! construct from Object owning objects list
@@ -74,11 +74,11 @@ private :
     Objects* _found; //< backing store for find_objects_in_rectangle
 };
 
-//! \brief container for layer, needed du to msvc6 lacking partial specialization
+//! \brief container for layer, needed due to msvc6 lacking partial specialization
 class Layers
 {
 public :
-    //! dont use
+    //! don't use
     Layers () : list(0) {}
     //! construct from Dia's container
     Layers (GPtrArray** os) : list(os) {}
@@ -106,7 +106,7 @@ public :
           // error: uninitialized member 'dia::DiagramData::extents' with 'const' type 'const Rectangle'
 #endif
     ::Rectangle extents;
-    //! trying ot be compatible, read-only
+    //! trying to be compatible, read-only
     const Layer* active_layer;
     //! the read-only list of layers, \todo typemap it in SWIG
     const Layers* layers;
diff --git a/bindings/dia-extra.cpp b/bindings/dia-extra.cpp
index 7f09aa3..92da4a7 100644
--- a/bindings/dia-extra.cpp
+++ b/bindings/dia-extra.cpp
@@ -33,6 +33,10 @@
 #include "plug-ins.h"
 #include "dialib.h"
 
+#include "dia-object.h" // for group_create impl.
+#include "dia-diagramdata.h" // for Objects
+#include "group.h"
+
 /*!
  * 
  *
@@ -49,3 +53,31 @@ void dia::register_plugins ()
 
     dia_register_plugins ();
 }
+
+void dia::message (int severity, const char* msg)
+{
+    g_print ("%s: %s\n", severity <= 0 ? "Info" : severity == 1 ? "Warning" : "Error", msg);
+}
+
+/*!
+ * \brief factory function for Group
+ * 
+ * Dia's group_create eats the given list, so this should to do the same,
+ * i.e. passing ownership of the Object in in objects.
+ * But 
+ */
+dia::Object*
+dia::group_create (Objects* objects)
+{
+    GList *list = NULL;
+    int i;
+
+    g_return_val_if_fail (objects->len() > 0, NULL);
+
+    for (i = 0; i < objects->len(); ++i) {
+       Object *o = objects->getitem(i);
+       if (o) // paranoid
+           list = g_list_append (list, o->Self());
+    }
+    return new dia::Object (::group_create (list));
+}
diff --git a/bindings/dia-extra.h b/bindings/dia-extra.h
index 29cf004..b908e17 100644
--- a/bindings/dia-extra.h
+++ b/bindings/dia-extra.h
@@ -4,8 +4,14 @@
  * Copyright 2007, Hans Breuer, GPL, see COPYING
  */
 
-
 namespace dia {
+  class Object;
+  class Objects;
+
   //! register plug-ins, beware of double bindings
   void register_plugins (void);
+  //! simplified message dialog
+  void message (int severity, const char* msg);
+  //! SWIG can't wrap the original directly, lets try this one
+  Object* group_create (Objects* objects);
 }
diff --git a/bindings/dia-object.cpp b/bindings/dia-object.cpp
index 7b4e714..83fee17 100644
--- a/bindings/dia-object.cpp
+++ b/bindings/dia-object.cpp
@@ -63,8 +63,12 @@ void
 dia::ObjectType::save (Object* o, ObjectNode node, const char* filename) const
 {
     assert (self);
-    self->ops->save (o->Self(), node, filename);
+    DiaContext *ctx = dia_context_new ("Object save");
+    self->ops->save (o->Self(), node, ctx);
+    dia_context_reset (ctx);
+    dia_context_release (ctx);
 }
+#if 0
 //! OPTIONAL: opens the defaults dialog
 GtkWidget* 
 dia::ObjectType::get_defaults () const
@@ -74,6 +78,7 @@ dia::ObjectType::get_defaults () const
         return 0;
     return self->ops->get_defaults ();
 }
+#endif
 //! OPTIONAL: apply changed defaults
 void 
 dia::ObjectType::apply_defaults ()
diff --git a/bindings/dia-object.h b/bindings/dia-object.h
index b6a4d62..4415bf7 100644
--- a/bindings/dia-object.h
+++ b/bindings/dia-object.h
@@ -37,8 +37,10 @@ public :
     Object* load (ObjectNode node, int version, DiaContext *ctx) const;
     //! save an object to file filename
     void save (Object* o, ObjectNode node, const char* filename) const;
+#if 0 // nothing useful
     //! OPTIONAL: open the defaults dialog
     GtkWidget* get_defaults () const;
+#endif
     //! OPTIONAL: apply changed defaults
     void apply_defaults ();
 private :
diff --git a/bindings/dia.swig b/bindings/dia.swig
index c43f5ec..d6af8e3 100755
--- a/bindings/dia.swig
+++ b/bindings/dia.swig
@@ -39,6 +39,8 @@ typedef char gchar;
 
 %ignore GEOMETRY_H;
 // and a bunch of other stuff not yet needed
+%ignore dia_acos;
+%ignore dia_asin;
 %ignore point_add;
 %ignore point_sub;
 %ignore point_dot;
@@ -298,6 +300,7 @@ PyObject* dia_IProperty_value_get (dia::IProperty* self) {
   // don't use 'export' as this produces nothing w/o warning
   void do_export (dia::DiagramData *dia, const gchar *filename) {
     DiaContext *ctx = dia_context_new ("Export");
+    dia_context_set_filename (ctx, filename);
     if (dia)
       self->export_func (dia->Self(), ctx, filename, filename, self->user_data);
     else
@@ -306,6 +309,8 @@ PyObject* dia_IProperty_value_get (dia::IProperty* self) {
   }
 };
 
+// don't generate a non-working binding
+%ignore dia::group_create;
 %include "dia-extra.h"
 
 %ignore _ot_item;
@@ -345,11 +350,27 @@ _ot_item (gpointer key,
 PyObject* registered_types () 
 {
     PyObject *dict = PyDict_New();
-    
+
     object_registry_foreach(_ot_item, dict);
 
     return dict;
 }
+//! overwrite group_create to work with a list of Python objects
+dia::Object* group_create (PyObject *list)
+{
+    if (PyList_Check(list)) {
+       GList *objs = NULL;
+       for (int i = 0; i < PyList_Size(list); ++i) {
+           PyObject* obj1 = PyList_GetItem(list, i);
+           void* o;
+           if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &o, SWIGTYPE_p_dia__Object, 0 )))
+               objs = g_list_append (objs, reinterpret_cast<dia::Object*>(o)->Self());
+       }
+       dia::Objects ow(&objs);
+       return dia::group_create (&ow);
+    }
+    return NULL;
+}
 %}
 #endif
 
diff --git a/bindings/makefile.msc b/bindings/makefile.msc
index b048376..3b77dca 100644
--- a/bindings/makefile.msc
+++ b/bindings/makefile.msc
@@ -76,7 +76,7 @@ dia-perl.cpp : $(INTERFACES)
        swig $(SWIG_FLAGS) -perl -c++ -o perl\$*.cpp dia.swig
 
 _dia.pyd : $(OBJECTS) dia-python.obj
-       $(CC) $(CFLAGS) -LD -Fe$@ $(OBJECTS) dia-python.obj $(LDFLAGS) $(EXTRALIBS) $(GLIB_LIBS)
+       $(CC) -nologo $(CFLAGS) -LD -Fe$@ $(OBJECTS) dia-python.obj $(LDFLAGS) $(EXTRALIBS) $(GLIB_LIBS)
 
 clean::
        del _dia.pyd dia.py dia.pyc $(GENERATED)
diff --git a/bindings/test.py b/bindings/test.py
index aa3db6d..67a613e 100644
--- a/bindings/test.py
+++ b/bindings/test.py
@@ -1,15 +1,14 @@
 import os, sys
 
 # a global object to make it changeable by main()
-format_extensions = ["svg", "png"]
+format_extensions = ["drs", "svg", "png"]
 
 if sys.platform == "win32" :
        print "Adjusting PATH ..."
        sys.path.insert(0, r'd:\graph\dia2\python')
        sys.path.insert(0, r'd:\graph\dia2\bin')
        sys.path.insert(0, r'..\plug-ins\python')
-       # format_extensions.prepend ("wmf")
-       format_extensions.insert (0, "wmf")
+       #format_extensions.insert (0, "wmf")
 else : # sorry only Linux and win32 tested ;)
        sys.path.insert (0, os.getcwd() + "/.libs")
        sys.path.insert(0, r'../plug-ins/python')
@@ -52,10 +51,10 @@ def Export (name, data) :
 def Import () :
        data = dia.DiagramData()
        import diasvg_import
-       diasvg_import.import_svg (r"D:\graph\dia2\render-test.svg", data)
+       diasvg_import.import_svg (r"D:\graph\dia2\samples\render-test.svg", data)
 
        filename = "render-test-swig.svg"
-       ef = dia.filter_get_by_name ("svg")
+       ef = dia.filter_export_get_by_name ("svg")
        if not ef :
                print "Guessing ..."
                ef = dia.filter_guess_export_filter ("dummy.png")
@@ -76,7 +75,7 @@ def Doc () :
        data = dia.DiagramData()
 
        import pydiadoc
-       res = pydiadoc.autodoc_cb (data, 1)
+       res = pydiadoc.autodoc_fresh_cb (data, 1)
        if res :
                data = res
        Export ("pydiadoc", data)


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