William
William

Reputation: 155

How to resize window in Gtk+ 3 with Revealer-like transition?

With PyGObject, obtaining a window that expands with a Revealer transition is possible as exemplified by the snippet of code below found here: http://learngtk.org/tutorials/python_gtk3_tutorial/html/revealer.html.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gi.repository import Gtk

def reveal_child(button):
    if revealer.get_reveal_child():
        revealer.set_reveal_child(False)
    else:
        revealer.set_reveal_child(True)

window = Gtk.Window()
window.connect("destroy", Gtk.main_quit)

grid = Gtk.Grid()
window.add(grid)

revealer = Gtk.Revealer()
revealer.set_reveal_child(False)
grid.attach(revealer, 0, 1, 1, 1)

label = Gtk.Label("Label contained in a Revealer widget")
revealer.add(label)

button = Gtk.Button("Reveal")
button.connect("clicked", reveal_child)
grid.attach(button, 0, 0, 1, 1)

window.show_all()

Gtk.main()

How can the reverse effect of having the window shrink back (with transition) be obtained? Right now revealer.set_reveal_child(False) leaves visible the expanded space used for the original reveal.

The effect sought is the same as the Expander class' set_resize_toplevel(True) effect.

Upvotes: 2

Views: 1161

Answers (1)

taupist
taupist

Reputation: 11

I tried to post this as a comment, but I don't have enough reputation points. This answer is really too short (in my opinion) to be an answer by itself. Anyway, try setting the visibility of the child, like this "revealer.get_reveal_child().set_visible(False)" This seems to do what, I think, you want. You would have to toggle visibility of the child when you toggle the reveal.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gi.repository import Gtk

def reveal_child(button):
    if revealer.get_reveal_child():
        revealer.set_reveal_child(False)
        # this line was a mistake
        #revealer.get_reveal_child().set_visible(False)
        revealer.set_visible(False)
    else:
        revealer.set_reveal_child(True)
        # this line was a mistake
        #revealer.get_reveal_child().set_visible(True)
        revealer.set_visible(True)

window = Gtk.Window()
window.connect("destroy", Gtk.main_quit)

grid = Gtk.Grid()
window.add(grid)

revealer = Gtk.Revealer()
revealer.set_reveal_child(False)
grid.attach(revealer, 0, 1, 1, 1)

label = Gtk.Label("Label contained in a Revealer widget")
revealer.add(label)

button = Gtk.Button("Reveal")
button.connect("clicked", reveal_child)
grid.attach(button, 0, 0, 1, 1)

window.show_all()

Gtk.main()

Edited to correct: The first time, I set visible on the wrong widget.

Upvotes: 1

Related Questions