예제 #1
0
    def test_wx_schedule_action(self):
        app = wx.AppConsole()
        exit = AppExit(app)
        scheduler = WxScheduler(wx)
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        scheduler.schedule(action)
        exit.Start(100, wx.TIMER_ONE_SHOT)
        app.MainLoop()
        scheduler.cancel_all()

        assert ran is True
예제 #2
0
    def test_wx_schedule_action_cancel(self):
        app = wx.AppConsole()
        exit = AppExit(app)
        scheduler = WxScheduler(wx)
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        d = scheduler.schedule_relative(0.1, action)
        d.dispose()
        exit.Start(200, wx.TIMER_ONE_SHOT)
        app.MainLoop()
        scheduler.cancel_all()

        assert ran is False
예제 #3
0
    def test_wx_schedule_action_cancel(self):
        app = wx.AppConsole()
        exit = AppExit(app)
        scheduler = WxScheduler(wx)
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        d = scheduler.schedule_relative(0.1, action)
        d.dispose()
        exit.Start(200, wx.TIMER_ONE_SHOT)
        app.MainLoop()
        scheduler.cancel_all()

        assert ran is False
예제 #4
0
    def test_wx_schedule_action_relative(self):
        app = wx.AppConsole()
        exit = AppExit(app)
        scheduler = WxScheduler(wx)
        starttime = default_now()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = default_now()

        scheduler.schedule_relative(0.1, action)
        exit.Start(200, wx.TIMER_ONE_SHOT)
        app.MainLoop()
        scheduler.cancel_all()

        assert endtime is not None
        diff = endtime - starttime
        assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
예제 #5
0
    def test_wx_schedule_action_periodic(self):
        app = wx.AppConsole()
        exit = AppExit(app)
        scheduler = WxScheduler(wx)
        period = 0.05
        counter = 3

        def action(state):
            nonlocal counter
            if state:
                counter -= 1
                return state - 1

        scheduler.schedule_periodic(period, action, counter)
        exit.Start(500, wx.TIMER_ONE_SHOT)
        app.MainLoop()
        scheduler.cancel_all()

        assert counter == 0
예제 #6
0
def main():
    app = wx.App()
    scheduler = WxScheduler(wx)

    app.TopWindow = frame = Frame()
    frame.Show()

    text = 'TIME FLIES LIKE AN ARROW'

    def on_next(info):
        label, (x, y), i = info
        label.Move(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 frame.mousemove.pipe(
            delayer,
            mapper,
        )

    def make_label(char):
        label = wx.StaticText(frame, label=char)
        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)

    frame.Bind(wx.EVT_CLOSE, lambda e: (scheduler.cancel_all(), e.Skip()))
    app.MainLoop()
예제 #7
0
def main():
    app = wx.App()
    scheduler = WxScheduler(wx)

    app.TopWindow = frame = Frame()
    frame.Show()

    text = 'TIME FLIES LIKE AN ARROW'

    def on_next(info):
        label, (x, y), i = info
        label.Move(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 frame.mousemove.pipe(
            delayer,
            mapper,
            )

    def make_label(char):
        label = wx.StaticText(frame, label=char)
        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)

    frame.Bind(wx.EVT_CLOSE, lambda e: (scheduler.cancel_all(), e.Skip()))
    app.MainLoop()
예제 #8
0
    def test_wx_schedule_action(self):
        app = wx.AppConsole()
        exit = AppExit(app)
        scheduler = WxScheduler(wx)
        ran = False

        def action(scheduler, state):
            nonlocal ran
            ran = True

        scheduler.schedule(action)
        exit.Start(100, wx.TIMER_ONE_SHOT)
        app.MainLoop()
        scheduler.cancel_all()

        assert ran is True
예제 #9
0
    def test_wx_schedule_action_relative(self):
        app = wx.AppConsole()
        exit = AppExit(app)
        scheduler = WxScheduler(wx)
        starttime = default_now()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = default_now()

        scheduler.schedule_relative(0.1, action)
        exit.Start(200, wx.TIMER_ONE_SHOT)
        app.MainLoop()
        scheduler.cancel_all()

        assert endtime is not None
        diff = endtime - starttime
        assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
예제 #10
0
    def test_wx_schedule_action_periodic(self):
        app = wx.AppConsole()
        exit = AppExit(app)
        scheduler = WxScheduler(wx)
        period = 0.05
        counter = 3

        def action(state):
            nonlocal counter
            if state:
                counter -= 1
                return state - 1

        scheduler.schedule_periodic(period, action, counter)
        exit.Start(500, wx.TIMER_ONE_SHOT)
        app.MainLoop()
        scheduler.cancel_all()

        assert counter == 0
예제 #11
0
 def test_wx_schedule_now_units(self):
     scheduler = WxScheduler(wx)
     diff = scheduler.now
     sleep(0.1)
     diff = scheduler.now - diff
     assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
예제 #12
0
 def test_wx_schedule_now(self):
     scheduler = WxScheduler(wx)
     diff = scheduler.now - default_now()
     assert abs(diff) < timedelta(milliseconds=1)