Example #1
0
    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()
Example #2
0
    def test_tkinter_schedule_action_cancel(self):
        ran = [False]
        scheduler = TkinterScheduler(root)

        def action(scheduler, state):
            ran[0] = True
        d = scheduler.schedule_relative(100, action)
        d.dispose()

        def done():
            root.quit()
            assert(not ran[0])
            
        root.after(300, done)
        root.mainloop()
Example #3
0
    def test_tkinter_schedule_action_cancel(self):
        ran = [False]
        scheduler = TkinterScheduler(root)

        def action(scheduler, state):
            ran[0] = True
        d = scheduler.schedule_relative(100, action)
        d.dispose()

        def done():
            root.quit()
            assert(not ran[0])

        root.after(300, done)
        root.mainloop()
Example #4
0
def main():
    root = Tk()
    root.title("Rx for Python rocks")
    scheduler = TkinterScheduler(root)

    mousemove = Subject()

    frame = Frame(root, width=600, height=600)

    def move(event):
        mousemove.on_next(event)
    frame.bind("<Motion>", move)

    text = 'TIME FLIES LIKE AN ARROW'
    labels = [Label(frame, text=c) for c in text]

    def handle_label(i, label):
        label.config(dict(borderwidth=0, padx=0, pady=0))

        def on_next(ev):
            label.place(x=ev.x + i*12 + 15, y=ev.y)
        mousemove.delay(i*100).subscribe_(on_next, scheduler=scheduler)

    for i, label in enumerate(labels):
        handle_label(i, label)

    frame.pack()
    root.mainloop()
Example #5
0
    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(200, action)

        def done():
            root.quit()
            diff = endtime[0] - starttime
            assert (diff > timedelta(milliseconds=180))

        root.after(300, done)
        root.mainloop()
Example #6
0
    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(200, action)

        def done():
            root.quit()
            diff = endtime[0]-starttime
            assert(diff > timedelta(milliseconds=180))

        root.after(300, done)
        root.mainloop()
Example #7
0
 def _stream(self):
     # pool_scheduler = ThreadPoolScheduler(2)
     scheduler = TkinterScheduler(self.master)
     self.service_subscription = self.service.as_observable() \
         .map(lambda frame: self._convert_frame_to_pil_image(frame)) \
         .observe_on(scheduler) \
         .subscribe(
             on_next = lambda pil_image: self.master.after(0, lambda: self.update_image(pil_image)),
             on_error=print)
Example #8
0
    def test_tkinter_schedule_action_periodic(self):
        scheduler = TkinterScheduler(root)
        period = 50
        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()
Example #9
0
    def test_tkinter_schedule_action_periodic(self):
        scheduler = TkinterScheduler(root)
        period = 50
        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()
Example #10
0
    def _start_stream(self):
        # setup source
        # pool_scheduler = ThreadPoolScheduler(2)
        ui_scheduler = TkinterScheduler(self.master)
        # self.service_subscription = self.service.as_observable()

        self.service_subscription = self.service.as_observable() \
            .map(self._convert_frame_to_pil_image) \
            .observe_on(ui_scheduler) \
            .subscribe(
                on_next = lambda pil: self.master.after(0, lambda: self.update_image(pil)),
                on_error=print)

        self.api_subscription = self.service.api_stream() \
            .subscribe(
                on_next = lambda rst: self.master.after(0, lambda: self.update_text(json.dumps(rst))),
                on_error=print
            )
Example #11
0
 def test_tkinter_schedule_now(self):
     scheduler = TkinterScheduler(root)
     res = scheduler.now() - datetime.utcnow()
     assert (res < timedelta(seconds=1))
Example #12
0
 def test_tkinter_schedule_now(self):
     scheduler = TkinterScheduler(root)
     res = scheduler.now() - datetime.utcnow()
     assert(res < timedelta(seconds=1))
Example #13
-2
    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()