0

As I am aware, I can subscribe to Gtk.Box signal "add child":

box.connect("add", self.__add_to_switch_list)

which will be called when I add child by box.add(child), and it's working.

But how I would do the same with box.pack_start() method?

likern
  • 3,744
  • 5
  • 36
  • 47

2 Answers2

1

There is no way.


"add" is only emitted when you call GtkContainer.add(). The first handler of this signal is subclass' method. For example, GtkBox does this :

/* gtk_box_class init: */
container_class->add = gtk_box_add;
...

static void
gtk_box_add (GtkContainer *container,
         GtkWidget    *widget)
{
  GtkBoxPrivate *priv = GTK_BOX (container)->priv;

  gtk_box_pack_start (GTK_BOX (container), widget,
                      priv->default_expand,
                      TRUE,
                      0);
}
Alexander Dmitriev
  • 2,483
  • 1
  • 15
  • 20
  • Thanks, yes I submitted a bug about that or adding this signal emission to GTK+. But it was closed / rejected . It's frustrating, because for dynamic widgets, which somehow visually change depending on number of childs, it's very desirable feature - to handle this in one place. – likern May 03 '18 at 17:32
0

In that very same bug report, @ebassi tells you that you can connect to the child widget's parent-set signal. If you can't know when a parent has a new child, you can know when a child has a new parent which is roughly the same thing.

liberforce
  • 11,189
  • 37
  • 48
  • Yes, this is workaround. But absolutely not the same. In terms of how things should be implemented and working correct. In case of box, I would have to handle this in just one place. And container is in response of emmiting this signal. If I working with "parent-set" child gets aware of parent. Or I have dynamically connect container method to "parent-set" of child, when child gets added to this container. – likern May 04 '18 at 14:08
  • But no worry, I've just implemented own Box with "child-added" and "child-removed" signals. – likern May 04 '18 at 14:09