aluntzer / gtknodes

A GTK-based library to create functional flow graphs with the ability to pass arbitrary data between connected elements.
Other
92 stars 10 forks source link

Fix problem with gtkbuild (loader has been including duplicated childs) #11

Closed anmaped closed 3 years ago

anmaped commented 3 years ago
diff --git a/src/gtknodeview.c b/src/gtknodeview.c
index a176263..67829ce 100644
--- a/src/gtknodeview.c
+++ b/src/gtknodeview.c
@@ -1530,7 +1530,7 @@ gboolean
 gtk_nodes_node_view_load (GtkNodesNodeView *node_view,
                           const gchar      *filename)
 {
-   GtkBuilder* builder;
+  GtkBuilder* builder;
   GError *error = NULL;
   GSList *l;

@@ -1555,19 +1555,22 @@ gtk_nodes_node_view_load (GtkNodesNodeView *node_view,

   l = gtk_builder_get_objects(builder);

-   while (l)
+  while (l)
     {
-        GObject *n = l->data;
+      GObject *n = l->data;

-      l = l->next;
-        gtk_container_add(GTK_CONTAINER(node_view), GTK_WIDGET(n));
-    }
+      l = l->next;
+      if (gtk_widget_get_parent(GTK_WIDGET(n)) == NULL)
+        {
+          gtk_container_add(GTK_CONTAINER(node_view), GTK_WIDGET(n));
+        }
+    }

-   gtk_builder_connect_signals_full (builder,
-                                    gtk_nodes_node_view_connection_mapper,
-                                    node_view);
+    gtk_builder_connect_signals_full (builder,
+                                      gtk_nodes_node_view_connection_mapper,
+                                      node_view);

-   gtk_widget_show_all(GTK_WIDGET (node_view));
+  gtk_widget_show_all(GTK_WIDGET (node_view));

   return TRUE;
 }
anmaped commented 3 years ago

For python, it does the trick.

class (...)
    def do_add_child(self, builder, child, t):
        if child.get_name() != "GtkComboBoxText":      # just an example with a ComboBox Widget
            self.add(child)

    def do_get_internal_child(self, builder, childname):
        if childname == "combobox":                    # use with '<child internal-child="combobox"></child>'
            return self.combobox;
        else:
            return None
aluntzer commented 3 years ago

thank you, fixed!