def test_gtk_schedule_action_absolute(self): scheduler = GtkScheduler() gate = threading.Semaphore(0) starttime = default_now() endtime = None def action(scheduler, state): nonlocal endtime endtime = default_now() due = scheduler.now + timedelta(milliseconds=100) scheduler.schedule_absolute(due, action) def done(data): Gtk.main_quit() gate.release() return False GLib.timeout_add(200, done, None) Gtk.main() gate.acquire() assert endtime is not None diff = endtime - starttime assert diff > timedelta(milliseconds=80)
def test_gtk_schedule_action(self): scheduler = GtkScheduler() ran = [False] def action(scheduler, state): ran[0] = True scheduler.schedule(action) def done(data): Gtk.main_quit() assert ran[0] return False GLib.timeout_add(50, done, None) Gtk.main()
def test_gtk_schedule_action_cancel(self): ran = [False] scheduler = GtkScheduler() def action(scheduler, state): ran[0] = True d = scheduler.schedule_relative(100, action) d.dispose() def done(data): Gtk.main_quit() assert not ran[0] return False GLib.timeout_add(300, done, None) Gtk.main()
def test_gtk_schedule_action_periodic(self): scheduler = GtkScheduler() period = 50 counter = [3] def action(state): if state: counter[0] -= 1 return state - 1 scheduler.schedule_periodic(period, action, counter[0]) def done(data): Gtk.main_quit() assert counter[0] == 0 return False GLib.timeout_add(300, done, None) Gtk.main()
def test_gtk_schedule_action_due(self): scheduler = GtkScheduler() starttime = datetime.utcnow() endtime = [None] def action(scheduler, state): endtime[0] = datetime.utcnow() scheduler.schedule_relative(200, action) def done(data): Gtk.main_quit() assert endtime[0] diff = endtime[0] - starttime assert diff > timedelta(milliseconds=180) return False GLib.timeout_add(300, done, None) Gtk.main()
def test_gtk_schedule_action(self): scheduler = GtkScheduler() gate = threading.Semaphore(0) ran = False def action(scheduler, state): nonlocal ran ran = True scheduler.schedule(action) def done(data): Gtk.main_quit() gate.release() GLib.timeout_add(50, done, None) Gtk.main() gate.acquire() assert ran is True
def test_gtk_schedule_action(self): scheduler = GtkScheduler() gate = threading.Semaphore(0) ran = False def action(scheduler, state): nonlocal ran ran = True scheduler.schedule(action) def done(data): Gtk.main_quit() gate.release() return False GLib.timeout_add(50, done, None) Gtk.main() gate.acquire() assert ran is True
def test_gtk_schedule_action_cancel(self): ran = False scheduler = GtkScheduler() gate = threading.Semaphore(0) def action(scheduler, state): nonlocal ran ran = True d = scheduler.schedule_relative(0.1, action) d.dispose() def done(data): Gtk.main_quit() gate.release() GLib.timeout_add(200, done, None) Gtk.main() gate.acquire() assert ran is False
def test_gtk_schedule_action_cancel(self): ran = False scheduler = GtkScheduler() gate = threading.Semaphore(0) def action(scheduler, state): nonlocal ran ran = True d = scheduler.schedule_relative(0.1, action) d.dispose() def done(data): Gtk.main_quit() gate.release() return False GLib.timeout_add(200, done, None) Gtk.main() gate.acquire() assert ran is False
def test_gtk_schedule_action_relative(self): scheduler = GtkScheduler() gate = threading.Semaphore(0) starttime = datetime.utcnow() endtime = None def action(scheduler, state): nonlocal endtime endtime = datetime.utcnow() scheduler.schedule_relative(0.1, action) def done(data): Gtk.main_quit() gate.release() GLib.timeout_add(200, done, None) Gtk.main() gate.acquire() assert endtime is not None diff = endtime - starttime assert diff > timedelta(milliseconds=80)
def test_gtk_schedule_action_periodic(self): scheduler = GtkScheduler() gate = threading.Semaphore(0) period = 0.05 counter = 3 def action(state): nonlocal counter if state: counter -= 1 return state - 1 scheduler.schedule_periodic(period, action, counter) def done(data): Gtk.main_quit() gate.release() GLib.timeout_add(300, done, None) Gtk.main() gate.acquire() assert counter == 0
def test_gtk_schedule_action_periodic(self): scheduler = GtkScheduler() gate = threading.Semaphore(0) period = 0.05 counter = 3 def action(state): nonlocal counter if state: counter -= 1 return state - 1 scheduler.schedule_periodic(period, action, counter) def done(data): Gtk.main_quit() gate.release() return False GLib.timeout_add(300, done, None) Gtk.main() gate.acquire() assert counter == 0
def main(): scheduler = GtkScheduler() scrolled_window = Gtk.ScrolledWindow() window = Window() window.connect("delete-event", Gtk.main_quit) container = Gtk.Fixed() scrolled_window.add(container) window.add(scrolled_window) text = 'TIME FLIES LIKE AN ARROW' def on_next(info): label, (x, y), i = info container.move(label, x + i * 12 + 15, y) label.show() def handle_label(label, i): delayer = ops.delay(i * 0.100) mapper = ops.map(lambda xy: (label, xy, i)) return window.mousemove.pipe( delayer, mapper, ) def make_label(char): label = Gtk.Label(label=char) container.put(label, 0, 0) label.hide() return label mapper = ops.map(make_label) labeler = ops.flat_map_indexed(handle_label) rx.from_(text).pipe( mapper, labeler, ).subscribe(on_next, on_error=print, scheduler=scheduler) window.show_all() Gtk.main()
def test_gtk_schedule_now_units(self): scheduler = GtkScheduler() diff = scheduler.now sleep(0.1) diff = scheduler.now - diff assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
def test_gtk_schedule_now(self): scheduler = GtkScheduler() diff = scheduler.now - default_now() assert abs(diff) < timedelta(milliseconds=1)
def test_gtk_schedule_now(self): scheduler = GtkScheduler() res = scheduler.now - datetime.utcnow() assert (res < timedelta(seconds=1))