import signal
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gtk


ui = """
<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkToolbar" id="bar">
    <property name="visible">True</property>
    <property name="show-arrow">False</property>
    <child>
      <object class="GtkToolButton" id="toolbutton">
        <property name="visible">False</property>
        <property name="icon_name">window-close</property>
      </object>
    </child>
  </object>
</interface>
"""


builder = Gtk.Builder()
builder.add_from_string(ui)

w = Gtk.Window()
w.add(builder.get_object('bar'))
w.show()
w.connect('delete-event', lambda *x: Gtk.main_quit())


def visibility_change(*args):
    toolbutton = builder.get_object('toolbutton')
    toolbutton.set_visible(True)
GLib.idle_add(visibility_change)

GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT,
                     lambda *args: Gtk.main_quit(), None)
Gtk.main()
