Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added pygtk patch, removed gaphor/tree/treemodel stuff

git-svn-id: file:///Users/arjan/backup/gaphor/trunk/gaphor@48 a8418922-720d-0410-834f-a69b97ada669
  • Loading branch information...
commit 340148f5fbb2a150d87cd672c51fbd6dafeaf787 1 parent e6edb79
@amolenaar authored
View
8 README
@@ -1,9 +1,15 @@
Gaphor - A UML CASE tool.
-This is to become a CASE tool what uses GNOME (GTK-2.0) for visualiization.
+This is to become a CASE tool what uses GNOME (GTK-2.0) for visualization.
Gaphor is mainly written in Python, which makes it very easy to use and
very easy to extend.
+NOTE: If you compile Gaphor yourself, you might want to patch your sources
+ of PyGTK too. This will avoid reference leak (resulting in memory
+ leaks) from objects referenced by a gtk.GenericTreeModel object.
+ I know it is not a nice solution, but it makes things work as long
+ as PyGTK itself does not solve the problem...
+
- Arjan Molenaar <arjanmolenaar@hetnet.nl>
View
3  gaphor/UML/__init__.py
@@ -16,6 +16,9 @@
Namespace._attrdef['ownedElement'] = ( Sequence, ModelElement, 'namespace' )
ModelElement._attrdef['namespace'] = ( None, Namespace, 'ownedElement' )
+Association._attrdef['connection'] = ( Sequence, AssociationEnd, 'association' )
+AssociationEnd._attrdef['association'] = ( None, Association, 'connection' )
+
ClassifierRole._attrdef['message'] = ( Sequence, Message )
#Message._attrdef['receiver'] = ( None, ClassifierRole )
#Message._attrdef['sender'] = ( None, ClassifierRole )
View
1  gaphor/diagram/Makefile.am
@@ -1,7 +1,6 @@
AUTOMAKE_OPTIONS = 1.5
INCLUDES = $(DIACANVAS2_CFLAGS) $(PYTHON_INCLUDES) $(PYGTK_CFLAGS)
-LDADD = $(DIACANVAS2_LIBS)
PYGTK_DEFSDIR = @PYGTK_DEFSDIR@
View
29 gaphor/tree/Makefile.am
@@ -3,32 +3,3 @@ EXTRA_DIST = __init__.py namespace.py
CLEANFILES = *.pyc *.pyo
-INCLUDES = $(GTK_CFLAGS) $(PYTHON_INCLUDES) $(PYGTK_CFLAGS)
-LDADD = $(GTK_LIBS)
-
-treemodeldir = $(pythondir)
-treemodelexecdir = $(pyexecdir)
-
-treemodelexec_LTLIBRARIES = treemodelmodule.la
-treemodelmodule_la_LDFLAGS = -module -avoid-version -export-symbols-regex inittreemodel
-treemodelmodule_la_LIBADD = $(DIACANVAS_LIBS)
-treemodelmodule_la_SOURCES = treemodel.c treemodelmodule.c
-nodist_treemodelmodule_la_SOURCES = pytreemodel.c
-
-pytreemodel.c: pytreemodel.defs pytreemodel.override
-
-all-local:
- test -f $(srcdir)/treemodelmodule.so || $(LN_S) $(srcdir)/.libs/treemodelmodule.so $(srcdir)
- (cd .. && $(PYTHON) -c "import tree.treemodel")
-
-.defs.c:
- (cd $(srcdir) \
- && $(PYGTK_CODEGEN) \
- --register $(PYGTK_DEFSDIR)/pango-types.defs \
- --register $(PYGTK_DEFSDIR)/gdk-types.defs \
- --register $(PYGTK_DEFSDIR)/gtk-types.defs \
- --override $*.override \
- --prefix $* $*.defs) > gen-$*.c \
- && cp gen-$*.c $*.c \
- && rm -f gen-$*.c
-
View
8 gaphor/tree/namespace.py
@@ -8,9 +8,8 @@
import gobject
import types
import UML
-import tree.treemodel
-class NamespaceModel(tree.TreeModel):
+class NamespaceModel(gtk.GenericTreeModel):
''' The node is defined by a instance. We can reach the parent
by <object>.namespace. The children can be found in the
<object>.ownerElement list.'''
@@ -28,12 +27,13 @@ def __init__(self, model):
self.model = model;
# Init parent:
gtk.GenericTreeModel.__init__(self)
- self.set_property ('leak_references', gtk.FALSE);
+ self.set_property ('leak_references', 0)
#self.connect ('dispose', self.__destroy)
# TODO: connect to 'name' and 'unlink' and 'namespace' signal from
# the data objects.
# Removed signals when finalized.
# How can I notify views in a proper way if something changed.
+
def dump(self):
'''Dump the static structure of the model to stdout.'''
def doit(node, depth):
@@ -90,7 +90,7 @@ def on_get_value(self, node, column):
'''returns the value stored in a particular column for the node'''
assert column == 0
assert isinstance (node, UML.Namespace)
- #print "on_get_value", node.name
+ print "on_get_value", node.name
return '<<' + str(node.__class__.__name__) + '>> ' + node.name
def on_iter_next(self, node):
View
20 gaphor/tree/pytreemodel.defs
@@ -1,20 +0,0 @@
-;; TreeModel
-
-(define-object TreeModel
- (parent "GObject")
- (c-name "TreeModel")
- (gtype-id "_TYPE_TREE_MODEL")
-; (implements "GtkTreeModel")
-)
-
-(define-function tree_model_get_type
- (c-name "tree_model_get_type")
- (return-type "GtkType")
-)
-
-(define-function tree_model_new
- (c-name "tree_model_new")
- (is-constructor-of TreeModel)
- (return-type "TreeModel*")
-)
-
View
9 gaphor/tree/pytreemodel.override
@@ -1,9 +0,0 @@
-%%
-headers
-#include <gtk/gtk.h>
-#include <pygobject.h>
-#include <pygtk/pygtk.h>
-#include "treemodel.h"
-%%
-import gobject.GObject as PyGObject_Type
-%%
View
585 gaphor/tree/treemodel.c
@@ -1,585 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4 -*- */
-
-#include "treemodel.h"
-#include <Python.h>
-#include "pygobject.h"
-
-/* define this to print out debug messages */
-#undef DEBUG_TREE_MODEL
-
-#ifndef _
-# define _(s) (s)
-#endif
-
-static void tree_model_class_init(TreeModelClass *klass);
-static void tree_model_init(TreeModel *self);
-static void tree_model_iface_init(GtkTreeModelIface *iface);
-
-static void tree_model_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
-static void tree_model_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
-
-GType
-tree_model_get_type(void)
-{
- static GType object_type = 0;
-
- if (!object_type) {
- static const GTypeInfo object_info = {
- sizeof(TreeModelClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) tree_model_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof(TreeModel),
- 0, /* n_preallocs */
- (GInstanceInitFunc) tree_model_init,
- };
- static const GInterfaceInfo tree_model_info = {
- (GInterfaceInitFunc) tree_model_iface_init,
- NULL,
- NULL,
- };
-
- object_type = g_type_register_static(G_TYPE_OBJECT,
- "TreeModel",
- &object_info, 0);
- g_type_add_interface_static(object_type,
- GTK_TYPE_TREE_MODEL,
- &tree_model_info);
- }
- return object_type;
-}
-
-static void
-tree_model_class_init(TreeModelClass *klass)
-{
- GObjectClass *object_class = (GObjectClass*) klass;
-
- object_class->get_property = tree_model_get_property;
- object_class->set_property = tree_model_set_property;
-}
-
-static guint tree_model_get_flags(GtkTreeModel *tree_model);
-static gint tree_model_get_n_columns(GtkTreeModel *tree_model);
-static GType tree_model_get_column_type(GtkTreeModel *tree_model,
- gint index);
-static gboolean tree_model_get_iter(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- GtkTreePath *path);
-static GtkTreePath *tree_model_get_path(GtkTreeModel *tree_model,
- GtkTreeIter *iter);
-static void tree_model_get_value(GtkTreeModel*tree_model,
- GtkTreeIter *iter,
- gint column, GValue *value);
-static gboolean tree_model_iter_next(GtkTreeModel *tree_model,
- GtkTreeIter *iter);
-static gboolean tree_model_iter_children(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- GtkTreeIter *parent);
-static gboolean tree_model_iter_has_child(GtkTreeModel *tree_model,
- GtkTreeIter *iter);
-static gint tree_model_iter_n_children(GtkTreeModel *tree_model,
- GtkTreeIter *iter);
-static gboolean tree_model_iter_nth_child(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- GtkTreeIter *parent,
- gint n);
-static gboolean tree_model_iter_parent(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- GtkTreeIter *child);
-
-static void
-tree_model_iface_init(GtkTreeModelIface *iface)
-{
- iface->get_flags = tree_model_get_flags;
- iface->get_n_columns = tree_model_get_n_columns;
- iface->get_column_type = tree_model_get_column_type;
- iface->get_iter = tree_model_get_iter;
- iface->get_path = tree_model_get_path;
- iface->get_value = tree_model_get_value;
- iface->iter_next = tree_model_iter_next;
- iface->iter_children = tree_model_iter_children;
- iface->iter_has_child = tree_model_iter_has_child;
- iface->iter_n_children = tree_model_iter_n_children;
- iface->iter_nth_child = tree_model_iter_nth_child;
- iface->iter_parent = tree_model_iter_parent;
-}
-
-static void
-tree_model_init(TreeModel *self)
-{
-}
-
-static void
-tree_model_set_property (GObject *object, guint property_id,
- const GValue *value, GParamSpec *pspec)
-{
- switch (property_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
-static void
-tree_model_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
-{
- switch (property_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
-TreeModel *
-tree_model_new(void)
-{
- return TREE_MODEL(g_object_new(TYPE_TREE_MODEL, NULL));
-}
-
-static PyObject *
-tree_path_to_pyobject(GtkTreePath *path)
-{
- gint len, i, *indices;
- PyObject *ret;
-
- len = gtk_tree_path_get_depth(path);
- indices = gtk_tree_path_get_indices(path);
- ret = PyTuple_New(len);
- for (i = 0; i < len; i++)
- PyTuple_SetItem(ret, i, PyInt_FromLong(indices[i]));
- return ret;
-}
-
-static GtkTreePath *
-tree_path_from_pyobject(PyObject *object)
-{
- if (PyTuple_Check(object)) {
- GtkTreePath *path;
- guint len, i;
-
- len = PyTuple_Size(object);
- if (len < 1)
- return NULL;
- path = gtk_tree_path_new();
- for (i = 0; i < len; i++) {
- PyObject *item = PyTuple_GetItem(object, i);
- gint index = PyInt_AsLong(item);
- if (PyErr_Occurred()) {
- gtk_tree_path_free(path);
- PyErr_Clear();
- return NULL;
- }
- gtk_tree_path_append_index(path, index);
- }
- return path;
- }
- return NULL;
-}
-
-/* format of GtkTreeIter's for TreeModel:
- * user_data == python object
- * user_data2 == floating reference?
- *
- * I haven't worked out how everything should work. For now I will
- * leak references.
- */
-
-#define METHOD_PREFIX "on_"
-
-static guint
-tree_model_get_flags(GtkTreeModel *tree_model)
-{
- PyObject *self, *py_ret;
-
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), 0);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("get_flags()");
-#endif
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "get_flags", "");
- if (py_ret) {
- guint ret = PyInt_AsLong(py_ret);
-
- Py_DECREF(py_ret);
- return ret;
- } else {
- PyErr_Print();
- PyErr_Clear();
- return 0;
- }
-}
-
-static gint
-tree_model_get_n_columns(GtkTreeModel *tree_model)
-{
- PyObject *self, *py_ret;
-
- g_return_val_if_fail(tree_model != NULL, 0);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), 0);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("get_n_columns()");
-#endif
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "get_n_columns", "");
- if (py_ret) {
- gint ret = PyInt_AsLong(py_ret);
-
- Py_DECREF(py_ret);
- return ret;
- } else {
- PyErr_Print();
- PyErr_Clear();
- return 0;
- }
-}
-
-static GType
-tree_model_get_column_type(GtkTreeModel *tree_model, gint index)
-{
- PyObject *self, *py_ret;
-
- g_return_val_if_fail(tree_model != NULL, G_TYPE_INVALID);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), G_TYPE_INVALID);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("get_column_type(%d)", index);
-#endif
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "get_column_type",
- "(i)", index);
- if (py_ret) {
- GType ret = pyg_type_from_object(py_ret);
-
- Py_DECREF(py_ret);
- return ret;
- } else {
- PyErr_Print();
- PyErr_Clear();
- return G_TYPE_INVALID;
- }
-}
-
-static gboolean
-tree_model_get_iter(GtkTreeModel *tree_model,
- GtkTreeIter *iter, GtkTreePath *path)
-{
- PyObject *self, *py_path, *py_ret;
-
- g_return_val_if_fail(tree_model != NULL, FALSE);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), FALSE);
- g_return_val_if_fail(iter != NULL, FALSE);
- g_return_val_if_fail(path != NULL, FALSE);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("get_tree_iter(%p)", path);
-#endif
- py_path = tree_path_to_pyobject(path);
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "get_iter",
- "(O)", py_path);
- Py_DECREF(py_path);
-
- if (py_ret) {
- if (py_ret != Py_None) {
- iter->user_data = py_ret;
- Py_DECREF (py_ret);
- return TRUE;
- } else {
- iter->user_data = NULL;
- Py_DECREF(py_ret);
- return FALSE;
- }
- } else {
- PyErr_Print();
- PyErr_Clear();
- iter->user_data = NULL;
- return FALSE;
- }
-}
-
-static GtkTreePath *
-tree_model_get_path(GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- PyObject *self, *py_ret;
-
- g_return_val_if_fail(tree_model != NULL, NULL);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), NULL);
- g_return_val_if_fail(iter != NULL, NULL);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("get_tree_path(%p)", iter);
-#endif
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "get_tree_path",
- "(O)", (PyObject *)iter->user_data);
- if (py_ret) {
- GtkTreePath *path = tree_path_from_pyobject(py_ret);
-
- Py_DECREF(py_ret);
- return path;
- } else {
- PyErr_Print();
- PyErr_Clear();
- return NULL;
- }
-}
-
-static void
-tree_model_get_value(GtkTreeModel*tree_model, GtkTreeIter *iter,
- gint column, GValue *value)
-{
- PyObject *self, *py_value;
-
- g_return_if_fail(tree_model != NULL);
- g_return_if_fail(IS_TREE_MODEL(tree_model));
- g_return_if_fail(iter != NULL);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("get_value(%p, %d)", iter, column);
- _PyObject_Dump (iter->user_data);
-#endif
- /* init value to column type */
- g_value_init(value, tree_model_get_column_type(tree_model, column));
-
-
- py_value = PyObject_CallMethod(self, METHOD_PREFIX "get_value",
- "(Oi)", (PyObject *)iter->user_data, column);
-
- if (py_value) {
- pyg_value_from_pyobject(value, py_value);
- Py_DECREF(py_value);
- } else {
- PyErr_Print();
- PyErr_Clear();
- }
-}
-
-static gboolean
-tree_model_iter_next(GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- PyObject *self, *py_ret;
-
- g_return_val_if_fail(tree_model != NULL, FALSE);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), FALSE);
- g_return_val_if_fail(iter != NULL, FALSE);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("iter_next(%p)", iter);
-#endif
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_next",
- "(O)", (PyObject *)iter->user_data);
- if (py_ret) {
- if (py_ret != Py_None) {
- /* XXXX handle reference counting here */
- if (iter->user_data) {
- Py_DECREF ((PyObject*) iter->user_data);
- }
- iter->user_data = py_ret;
- Py_DECREF(py_ret);
- return TRUE;
- } else {
- iter->user_data = NULL;
- Py_DECREF(py_ret);
- return FALSE;
- }
- } else {
- iter->user_data = NULL;
- PyErr_Print();
- PyErr_Clear();
- return FALSE;
- }
-}
-
-static gboolean
-tree_model_iter_children(GtkTreeModel *tree_model, GtkTreeIter *iter,
- GtkTreeIter *parent)
-{
- PyObject *self, *py_ret, *py_parent = Py_None;
-
- g_return_val_if_fail(tree_model != NULL, FALSE);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), FALSE);
- g_return_val_if_fail(iter != NULL, FALSE);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("iter_children(%p, %p)", iter, parent);
-#endif
- if (parent && parent->user_data)
- py_parent = (PyObject *)parent->user_data;
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_children",
- "(O)", py_parent);
- if (py_ret) {
- if (py_ret != Py_None) {
- /* XXXX handle reference counting here */
- iter->user_data = py_ret;
- Py_DECREF(py_ret);
- return TRUE;
- } else {
- iter->user_data = NULL;
- Py_DECREF(py_ret);
- return FALSE;
- }
- } else {
- iter->user_data = NULL;
- PyErr_Print();
- PyErr_Clear();
- return FALSE;
- }
-}
-
-static gboolean
-tree_model_iter_has_child(GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- PyObject *self, *py_ret;
-
- g_return_val_if_fail(tree_model != NULL, FALSE);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), FALSE);
- g_return_val_if_fail(iter != NULL, FALSE);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("iter_has_child(%p)", iter);
-#endif
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_has_child",
- "(O)", (PyObject *)iter->user_data);
- if (py_ret) {
- gboolean ret = PyObject_IsTrue(py_ret);
-
- Py_DECREF(py_ret);
- return ret;
- } else {
- PyErr_Print();
- PyErr_Clear();
- return FALSE;
- }
-}
-
-static gint
-tree_model_iter_n_children(GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- PyObject *self, *py_ret;
-
- g_return_val_if_fail(tree_model != NULL, FALSE);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), FALSE);
- g_return_val_if_fail(iter != NULL, FALSE);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("iter_n_children(%p)", iter);
-#endif
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_n_children",
- "(O)", (PyObject *)iter->user_data);
- if (py_ret) {
- gint ret = PyInt_AsLong(py_ret);
-
- Py_DECREF(py_ret);
- return ret;
- } else {
- PyErr_Print();
- PyErr_Clear();
- return 0;
- }
-}
-
-static gboolean
-tree_model_iter_nth_child(GtkTreeModel *tree_model, GtkTreeIter *iter,
- GtkTreeIter *parent, gint n)
-{
- PyObject *self, *py_ret, *py_parent = Py_None;
-
- g_return_val_if_fail(tree_model != NULL, FALSE);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), FALSE);
- g_return_val_if_fail(iter != NULL, FALSE);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("iter_nth_child(%p, %p (%p), %d)", iter, parent, parent ? parent->user_data : NULL, n);
-#endif
- if (parent && parent->user_data)
- py_parent = (PyObject *)parent->user_data;
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_nth_child",
- "(Oi)", py_parent, n);
- if (py_ret) {
- if (py_ret != Py_None) {
- /* XXXX handle reference counting here */
- iter->user_data = py_ret;
- Py_DECREF(py_ret);
- return TRUE;
- } else {
- iter->user_data = NULL;
- Py_DECREF(py_ret);
- return FALSE;
- }
- } else {
- iter->user_data = NULL;
- PyErr_Print();
- PyErr_Clear();
- return FALSE;
- }
-}
-
-static gboolean
-tree_model_iter_parent(GtkTreeModel *tree_model, GtkTreeIter *iter,
- GtkTreeIter *child)
-{
- PyObject *self, *py_ret, *py_child = Py_None;
-
- g_return_val_if_fail(tree_model != NULL, FALSE);
- g_return_val_if_fail(IS_TREE_MODEL(tree_model), FALSE);
- g_return_val_if_fail(iter != NULL, FALSE);
- /* this call finds the wrapper for this GObject */
- self = pygobject_new((GObject *)tree_model);
-
-#ifdef DEBUG_TREE_MODEL
- g_message("iter_parent(%p, %p)", iter, child);
-#endif
- if (child && child->user_data)
- py_child = (PyObject *)child->user_data;
- py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_parent",
- "(O)", py_child);
- if (py_ret) {
- if (py_ret != Py_None) {
- /* XXXX handle reference counting here */
- if (iter->user_data) {
- Py_DECREF ((PyObject*) iter->user_data);
- }
- iter->user_data = py_ret;
- Py_DECREF(py_ret);
- return TRUE;
- } else {
- iter->user_data = NULL;
- Py_DECREF(py_ret);
- return FALSE;
- }
- } else {
- iter->user_data = NULL;
- PyErr_Print();
- PyErr_Clear();
- return FALSE;
- }
-}
-
View
28 gaphor/tree/treemodel.h
@@ -1,28 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4 -*- */
-#include <gtk/gtk.h>
-
-#define TYPE_TREE_MODEL (tree_model_get_type())
-#define TREE_MODEL(object) (G_TYPE_CHECK_INSTANCE_CAST((object), TYPE_TREE_MODEL, TreeModel))
-#define TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_TREE_MODEL, TreeModelClass))
-#define IS_TREE_MODEL(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), TYPE_TREE_MODEL))
-#define IS_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_TREE_MODEL))
-#define TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_TREE_MODEL, TreeModelClass))
-
-#define _TYPE_TREE_MODEL TYPE_TREE_MODEL
-#define _TREE_MODEL TREE_MODEL
-
-typedef struct _TreeModel TreeModel;
-typedef struct _TreeModelClass TreeModelClass;
-
-struct _TreeModel {
- GObject parent_instance;
-};
-
-struct _TreeModelClass {
- GObjectClass parent_class;
-
-};
-
-GType tree_model_get_type(void);
-
-TreeModel *tree_model_new(void);
View
26 gaphor/tree/treemodelmodule.c
@@ -1,26 +0,0 @@
-/* include this first, before NO_IMPORT_PYGOBJECT is defined */
-#include <pygobject.h>
-#include <pygtk/pygtk.h>
-
-void pytreemodel_register_classes (PyObject *d);
-
-extern PyMethodDef pytreemodel_functions[];
-
-
-DL_EXPORT(void)
-inittreemodel (void)
-{
- PyObject *m, *d;
-
- init_pygobject ();
- init_pygtk ();
-
- m = Py_InitModule ("treemodel", pytreemodel_functions);
- d = PyModule_GetDict (m);
-
- pytreemodel_register_classes (d);
-
- if (PyErr_Occurred ())
- Py_FatalError ("can't initialise module treemodel");
-}
-
View
218 pygtk.patch
@@ -0,0 +1,218 @@
+Index: gtk/pygtktreemodel.c
+===================================================================
+RCS file: /cvs/gnome/gnome-python/pygtk/gtk/pygtktreemodel.c,v
+retrieving revision 1.6
+diff -u -r1.6 pygtktreemodel.c
+--- gtk/pygtktreemodel.c 2001/10/09 04:05:33 1.6
++++ gtk/pygtktreemodel.c 2002/02/27 07:50:25
+@@ -11,10 +11,27 @@
+ /* define this to print out debug messages */
+ #undef DEBUG_TREE_MODEL
+
++#ifndef _
++# define _(s) (s)
++#endif
++
++enum {
++ PROP_LEAK_REFERENCES = 1
++};
++
+ static void pygtk_generic_tree_model_class_init(PyGtkGenericTreeModelClass *klass);
+ static void pygtk_generic_tree_model_init(PyGtkGenericTreeModel *self);
+ static void pygtk_generic_tree_model_iface_init(GtkTreeModelIface *iface);
+
++static void pygtk_generic_tree_model_set_property (GObject *object,
++ guint property_id,
++ const GValue *value,
++ GParamSpec *pspec);
++static void pygtk_generic_tree_model_get_property (GObject *object,
++ guint property_id,
++ GValue *value,
++ GParamSpec *pspec);
++
+ GType
+ pygtk_generic_tree_model_get_type(void)
+ {
+@@ -51,6 +68,22 @@
+ static void
+ pygtk_generic_tree_model_class_init(PyGtkGenericTreeModelClass *klass)
+ {
++ GObjectClass *object_class = (GObjectClass*) klass;
++
++ object_class->get_property = pygtk_generic_tree_model_get_property;
++ object_class->set_property = pygtk_generic_tree_model_set_property;
++
++ g_object_class_install_property (object_class,
++ PROP_LEAK_REFERENCES,
++ g_param_spec_boolean ("leak_references",
++ _("Leak references"),
++ _("Enable referencing iterator "
++ "objects (this will cause a memory leak or at least a reference "
++ "counting leak). You might need it though, if you return newly "
++ "created objects."),
++ TRUE,
++ G_PARAM_READWRITE));
++
+ }
+
+ static guint pygtk_generic_tree_model_get_flags(GtkTreeModel *tree_model);
+@@ -102,8 +135,38 @@
+ static void
+ pygtk_generic_tree_model_init(PyGtkGenericTreeModel *self)
+ {
++ self->leak_references = TRUE;
++}
++
++static void
++pygtk_generic_tree_model_set_property (GObject *object, guint property_id,
++ const GValue *value, GParamSpec *pspec)
++{
++ switch (property_id) {
++ case PROP_LEAK_REFERENCES:
++ PYGTK_GENERIC_TREE_MODEL (object)->leak_references = g_value_get_boolean (value);
++ break;
++ default:
++ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
++ break;
++ }
+ }
+
++static void
++pygtk_generic_tree_model_get_property (GObject *object, guint property_id,
++ GValue *value, GParamSpec *pspec)
++{
++ switch (property_id) {
++ case PROP_LEAK_REFERENCES:
++ g_value_set_boolean (value,
++ PYGTK_GENERIC_TREE_MODEL (object)->leak_references);
++ break;
++ default:
++ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
++ break;
++ }
++}
++
+ PyGtkGenericTreeModel *
+ pygtk_generic_tree_model_new(void)
+ {
+@@ -224,6 +287,9 @@
+ if (py_ret) {
+ if (py_ret != Py_None) {
+ iter->user_data = py_ret;
++ if (!((PyGtkGenericTreeModel*) tree_model)->leak_references) {
++ Py_DECREF (py_ret);
++ }
+ return TRUE;
+ } else {
+ iter->user_data = NULL;
+@@ -280,12 +346,14 @@
+
+ #ifdef DEBUG_TREE_MODEL
+ g_message("get_value(%p, %d)", iter, column);
++ _PyObject_Dump (iter->user_data);
+ #endif
+ /* init value to column type */
+ g_value_init(value, pygtk_generic_tree_model_get_column_type(tree_model, column));
+
++
+ py_value = PyObject_CallMethod(self, METHOD_PREFIX "get_value",
+- "(Oi)", (PyObject *)iter->user_data,column);
++ "(Oi)", (PyObject *)iter->user_data, column);
+
+ if (py_value) {
+ pyg_value_from_pyobject(value, py_value);
+@@ -315,7 +383,14 @@
+ if (py_ret) {
+ if (py_ret != Py_None) {
+ /* XXXX handle reference counting here */
++ if (iter->user_data
++ && ((PyGtkGenericTreeModel*) tree_model)->leak_references) {
++ Py_DECREF ((PyObject*) iter->user_data);
++ }
+ iter->user_data = py_ret;
++ if (!((PyGtkGenericTreeModel*) tree_model)->leak_references) {
++ Py_DECREF(py_ret);
++ }
+ return TRUE;
+ } else {
+ iter->user_data = NULL;
+@@ -345,13 +420,17 @@
+ #ifdef DEBUG_TREE_MODEL
+ g_message("iter_children(%p, %p)", iter, parent);
+ #endif
+- if (parent) py_parent = (PyObject *)parent->user_data;
++ if (parent && parent->user_data)
++ py_parent = (PyObject *)parent->user_data;
+ py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_children",
+ "(O)", py_parent);
+ if (py_ret) {
+ if (py_ret != Py_None) {
+ /* XXXX handle reference counting here */
+ iter->user_data = py_ret;
++ if (!((PyGtkGenericTreeModel*) tree_model)->leak_references) {
++ Py_DECREF(py_ret);
++ }
+ return TRUE;
+ } else {
+ iter->user_data = NULL;
+@@ -435,15 +514,19 @@
+ self = pygobject_new((GObject *)tree_model);
+
+ #ifdef DEBUG_TREE_MODEL
+- g_message("iter_nth_child(%p, %p, %d)", iter, parent, n);
++ g_message("iter_nth_child(%p, %p (%p), %d)", iter, parent, parent ? parent->user_data : NULL, n);
+ #endif
+- if (parent) py_parent = (PyObject *)parent->user_data;
++ if (parent && parent->user_data)
++ py_parent = (PyObject *)parent->user_data;
+ py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_nth_child",
+ "(Oi)", py_parent, n);
+ if (py_ret) {
+ if (py_ret != Py_None) {
+ /* XXXX handle reference counting here */
+ iter->user_data = py_ret;
++ if (!((PyGtkGenericTreeModel*) tree_model)->leak_references) {
++ Py_DECREF(py_ret);
++ }
+ return TRUE;
+ } else {
+ iter->user_data = NULL;
+@@ -473,13 +556,21 @@
+ #ifdef DEBUG_TREE_MODEL
+ g_message("iter_parent(%p, %p)", iter, child);
+ #endif
+- if (child) py_child = (PyObject *)child->user_data;
++ if (child && child->user_data)
++ py_child = (PyObject *)child->user_data;
+ py_ret = PyObject_CallMethod(self, METHOD_PREFIX "iter_parent",
+ "(O)", py_child);
+ if (py_ret) {
+ if (py_ret != Py_None) {
+ /* XXXX handle reference counting here */
++ if (iter->user_data
++ && ((PyGtkGenericTreeModel*) tree_model)->leak_references) {
++ Py_DECREF ((PyObject*) iter->user_data);
++ }
+ iter->user_data = py_ret;
++ if (!((PyGtkGenericTreeModel*) tree_model)->leak_references) {
++ Py_DECREF(py_ret);
++ }
+ return TRUE;
+ } else {
+ iter->user_data = NULL;
+Index: gtk/pygtktreemodel.h
+===================================================================
+RCS file: /cvs/gnome/gnome-python/pygtk/gtk/pygtktreemodel.h,v
+retrieving revision 1.2
+diff -u -r1.2 pygtktreemodel.h
+--- gtk/pygtktreemodel.h 2001/10/09 04:05:33 1.2
++++ gtk/pygtktreemodel.h 2002/02/27 07:50:25
+@@ -13,6 +13,8 @@
+
+ struct _PyGtkGenericTreeModel {
+ GObject parent_instance;
++
++ gboolean leak_references;
+ };
+
+ struct _PyGtkGenericTreeModelClass {
Please sign in to comment.
Something went wrong with that request. Please try again.