def test_tkinter_schedule_action(self): scheduler = TkinterScheduler(root) ran = [False] def action(scheduler, state): ran[0] = True scheduler.schedule(action) def done(): assert ran[0] == True root.quit() root.after_idle(done) root.mainloop()
def test_tkinter_schedule_action_cancel(self): ran = [False] scheduler = TkinterScheduler(root) def action(scheduler, state): ran[0] = True d = scheduler.schedule_relative(0.1, action) d.dispose() def done(): root.quit() assert (not ran[0]) root.after(300, done) root.mainloop()
def test_tkinter_schedule_action(self): scheduler = TkinterScheduler(root) ran = False def action(scheduler, state): nonlocal ran ran = True scheduler.schedule(action) def done(): assert ran is True root.quit() root.after_idle(done) root.mainloop()
def test_tkinter_schedule_action_due(self): scheduler = TkinterScheduler(root) starttime = datetime.utcnow() endtime = [None] def action(scheduler, state): endtime[0] = datetime.utcnow() scheduler.schedule_relative(0.2, action) def done(): root.quit() diff = endtime[0] - starttime assert diff > timedelta(milliseconds=180) root.after(300, done) root.mainloop()
def test_tkinter_schedule_action_periodic(self): scheduler = TkinterScheduler(root) period = 0.050 counter = [3] def action(state): if state: counter[0] -= 1 return state - 1 scheduler.schedule_periodic(period, action, counter[0]) def done(): root.quit() assert counter[0] == 0 root.after(300, done) root.mainloop()
def test_tkinter_schedule_action_due(self): scheduler = TkinterScheduler(root) starttime = default_now() endtime = None def action(scheduler, state): nonlocal endtime endtime = default_now() scheduler.schedule_relative(0.2, action) def done(): root.quit() assert endtime is not None diff = endtime - starttime assert diff > timedelta(milliseconds=180) root.after(300, done) root.mainloop()
def main(): root = Tk() root.title("Rx for Python rocks") scheduler = TkinterScheduler(root) mousemove = Subject() frame = Frame(root, width=600, height=600) frame.bind("<Motion>", mousemove.on_next) text = 'TIME FLIES LIKE AN ARROW' def on_next(info): label, ev, i = info label.place(x=ev.x + i*12 + 15, y=ev.y) def handle_label(label, i): label.config(dict(borderwidth=0, padx=0, pady=0)) mapper = ops.map(lambda ev: (label, ev, i)) delayer = ops.delay(i*0.1) return mousemove.pipe( delayer, mapper ) labeler = ops.flat_map_indexed(handle_label) mapper = ops.map(lambda c: Label(frame, text=c)) rx.from_(text).pipe( mapper, labeler ).subscribe(on_next, on_error=print, scheduler=scheduler) frame.pack() root.mainloop()
def test_tkinter_schedule_now(self): scheduler = TkinterScheduler(root) res = scheduler.now - datetime.utcnow() assert res < timedelta(seconds=1)
def test_qt_schedule_now_units(self): scheduler = TkinterScheduler(root) diff = scheduler.now sleep(0.1) diff = scheduler.now - diff assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
def test_tkinter_schedule_now(self): scheduler = TkinterScheduler(root) res = scheduler.now - default_now() assert abs(res) < timedelta(milliseconds=1)