#! /usr/bin/env python3

from gi.repository import Gtk, GLib

win1 = Gtk.Window()
win2 = Gtk.Window()

def before_resume_events(*args):
    print("before resume events")

def flush_events(*args):
    print('flush events')
    GLib.idle_add(before_resume_events, priority=-100)
    win1.destroy()

def resume_events(*args):
    print('resume events')


def start_test(*args):
    print('start_test')
    frame_clock = win1.get_frame_clock()

    frame_clock.connect('flush-events', flush_events)
    frame_clock.connect('resume-events', resume_events)

    win1.queue_draw()


btn1 = Gtk.Button(label="Make it stop working")
btn2 = Gtk.Button(label="Quit App")


btn1.connect('clicked', start_test)
btn2.connect('clicked', lambda *args: Gtk.main_quit())


win1.add(btn1)
win1.show_all()

win2.add(btn2)
win2.show_all()

Gtk.main()

