0

I am using a Gtk.Stack widget in PyGobject, and as i could not find any "tutorial" on how to use them, i supposed that each element of the Gtk.Stack has a name/tag.

And so i made a few elements and connected to the stack with:

add_named(element_to_add_to_stack, "Element_tag")

The fist of them was connected and successfully appeared, but whenever i set another as visible with:

set_visible_child_name("Element_tag")

Nothing happens, and after a retrieval of which elements are part of the stack:

stack.get_visible_child()

It simply returns

None

What is wrong? Is that way to use Gtk.Stack wrong?

Edit:

def main_content(self):
    right_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
    self.stack = Gtk.Stack()
    self.stack.get_style_context().add_class("main-container")
    self.stack.props.margin = 20
    self.stack.add_named(self.gen_page1(), "page1")
    self.stack.add_named(self.gen_page2(), "page2")
    self.stack.add_named(self.gen_page3(), "page3")
    #self.stack.set_visible_child_name("page2")
    #self.stack.set_visible_child_full("page2", 1)
    print((self.stack.get_visible_child()))

    right_box.pack_start(self.stack, True, True, 0)
    return right_box
SOMN
  • 351
  • 1
  • 3
  • 15

1 Answers1

3

The child widget needs to be visible (as in Widget.get_visible()) before it can be a 'visible child'. This is not the case at this point of your code (although it would just work when the window is actually shown), but if you just do my_child_widget.set_visible (True) before adding the child widgets to the stack, get_visible_child() should start working.

Not the greatest design really as the set_visible_child* functions fail totally silently...

Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54
  • Thanks. I though that every element was visible by default. In fact it could output something to sterr in case of such failure, it would be nice and save a lot of time. – SOMN Mar 04 '14 at 21:07
  • Yeah, widgets not being visible by default is an annoying legacy thing. For reference, the documentation was just fixed to say "Note that the @child widget has to be visible itself (see gtk_widget_show()) in order to become the visible child of @stack". – Jussi Kukkonen Mar 07 '14 at 08:47