def test_pyside2_schedule_periodic_cancel(self, app):

        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)
        period = 0.05
        counter = 3

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

        disp = scheduler.schedule_periodic(period, action, counter)

        def dispose():
            disp.dispose()

        QtCore.QTimer.singleShot(100, dispose)

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(300, done)
        app.exec_()

        gate.acquire()
        assert 0 < counter < 3
示例#2
0
    def test_qt5_schedule_periodic_cancel(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)
        period = 0.05
        counter = 3

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

        disp = scheduler.schedule_periodic(period, action, counter)

        def dispose():
            disp.dispose()

        QtCore.QTimer.singleShot(100, dispose)

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(300, done)
        app.exec_()

        gate.acquire()
        assert 0 < counter < 3
    def test_pyside2_schedule_action_periodic(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)
        period = 0.050
        counter = 3

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

        scheduler.schedule_periodic(period, action, counter)

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(300, done)
        app.exec_()

        gate.acquire()
        assert counter == 0
示例#4
0
    def test_qt5_schedule_action_due_absolute(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)
        starttime = default_now()
        endtime = None

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

        scheduler.schedule_absolute(starttime + timedelta(seconds=0.2), action)

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(300, done)
        app.exec_()

        gate.acquire()
        assert endtime is not None
        diff = endtime - starttime
        assert diff > timedelta(milliseconds=180)
示例#5
0
def main():
    app = QApplication(sys.argv)
    scheduler = QtScheduler(QtCore)

    window = Window()
    window.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 window.mousemove.pipe(
            delayer,
            mapper,
        )

    labeler = ops.flat_map_indexed(handle_label)
    mapper = ops.map(lambda c: QLabel(c, window))

    rx.from_(text).pipe(
        mapper,
        labeler,
    ).subscribe(on_next, on_error=print, scheduler=scheduler)

    sys.exit(app.exec_())
示例#6
0
    def test_qt_schedule_action(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        ran = [False]

        def action(scheduler, state):
            ran[0] = True
        scheduler.schedule(action)

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

        QtCore.QTimer.singleShot(50, done)
        app.exec_()
示例#7
0
    def test_qt_schedule_action_cancel(self):
        app = make_app()

        ran = [False]
        scheduler = QtScheduler(QtCore)

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

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

        QtCore.QTimer.singleShot(300, done)
        app.exec_()
示例#8
0
    def test_qt_schedule_action_due(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        starttime = datetime.utcnow()
        endtime = [None]

        def action(scheduler, state):
            endtime[0] = datetime.utcnow()

        scheduler.schedule_relative(0.2, action)

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

        QtCore.QTimer.singleShot(300, done)
        app.exec_()
    def test_qt_schedule_action_periodic(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        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():
            app.quit()
            assert counter[0] == 0

        QtCore.QTimer.singleShot(300, done)
        app.exec_()
示例#10
0
    def test_qt_schedule_action_periodic(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        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():
            app.quit()
            assert counter[0] == 0

        QtCore.QTimer.singleShot(300, done)
        app.exec_()
    def test_qt_schedule_action_due(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        starttime = datetime.utcnow()
        endtime = [None]

        def action(scheduler, state):
            endtime[0] = datetime.utcnow()

        scheduler.schedule_relative(0.2, action)

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

        QtCore.QTimer.singleShot(300, done)
        app.exec_()
示例#12
0
    def test_pyside2_schedule_action(self, app):

        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)
        ran = False

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

        scheduler.schedule(action)

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(50, done)
        app.exec_()

        gate.acquire()
        assert ran is True
示例#13
0
    def test_qt_schedule_action_due_absolute(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        starttime = datetime.utcnow()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = datetime.utcnow()

        scheduler.schedule_absolute(starttime + timedelta(seconds=0.2), action)

        def done():
            app.quit()
            assert endtime
            diff = endtime - starttime
            assert diff > timedelta(milliseconds=180)

        QtCore.QTimer.singleShot(300, done)
        app.exec_()
示例#14
0
    def test_qt5_schedule_action(self):
        app = make_app()

        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)
        ran = False

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

        scheduler.schedule(action)

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(50, done)
        app.exec_()

        gate.acquire()
        assert ran is True
示例#15
0
    def test_pyside2_schedule_action_cancel(self, app):

        ran = False
        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)

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

        d = scheduler.schedule_relative(0.1, action)
        d.dispose()

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(300, done)
        app.exec_()

        gate.acquire()
        assert ran is False
示例#16
0
    def test_qt5_schedule_action_cancel(self):
        app = make_app()

        ran = False
        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)

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

        d = scheduler.schedule_relative(0.1, action)
        d.dispose()

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(300, done)
        app.exec_()

        gate.acquire()
        assert ran is False
示例#17
0
    def test_pyside2_schedule_action_due_absolute(self, app):

        scheduler = QtScheduler(QtCore)
        gate = threading.Semaphore(0)
        starttime = default_now()
        endtime = None

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

        scheduler.schedule_absolute(starttime + timedelta(seconds=0.2), action)

        def done():
            app.quit()
            gate.release()

        QtCore.QTimer.singleShot(300, done)
        app.exec_()

        gate.acquire()
        assert endtime is not None
        diff = endtime - starttime
        assert diff > timedelta(milliseconds=180)
示例#18
0
 def test_qt_schedule_now(self):
     scheduler = QtScheduler(QtCore)
     res = scheduler.now - datetime.utcnow()
     assert res < timedelta(seconds=1)
示例#19
0
 def test_qt5_schedule_now_units(self):
     scheduler = QtScheduler(QtCore)
     diff = scheduler.now
     sleep(0.1)
     diff = scheduler.now - diff
     assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
示例#20
0
 def test_qt5_schedule_now(self):
     scheduler = QtScheduler(QtCore)
     diff = scheduler.now - default_now()
     assert abs(diff) < timedelta(milliseconds=1)