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
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_())
def __init__(self, protocol): # See comment in players.py. self._aio_scheduler = QtScheduler(QtCore) messages = protocol.register("game_info") self.new = messages.pipe( ops.flat_map(self._split_game_info), ops.observe_on(self._aio_scheduler), ops.flat_map(self._process_game), ops.observe_on(ImmediateScheduler()), ops.filter(lambda x: x is not None), )
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
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
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)
def test_pyqt5_schedule_action_periodic(self, 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
def __init__(self, protocol): # We use this scheduler so that we don't handle all player messages at # the same time at startup, as this hangs the UI for a few seconds. # With this, it's just a minor slowdown. # # One side effect is that games and players don't appear immediately # (as in, UI is available before they're all shown). This shouldn't be # a problem. self._aio_scheduler = QtScheduler(QtCore) messages = protocol.register("player_info") self.new = messages.pipe( ops.flat_map(self._split_player_info), ops.observe_on(self._aio_scheduler), ops.flat_map(self._handle_player_info), ops.observe_on(ImmediateScheduler()), )
time.sleep(1) if self.isCancelled(): return self.setProgress("Done...") import rx import rx.operators import rx.scheduler from rx.disposable import CompositeDisposable from rx.scheduler.mainloop import QtScheduler from fscore.observable import Disposable, MainLoopScheduler, Observable from fsui.qt import QtCore qtScheduler = QtScheduler(QtCore) import threading from typing import Any, List, Optional from rx.core.typing import Disposable as DisposableType from rx.core.typing import Observer as ObserverType from rx.core.typing import Scheduler as SchedulerType from rx.scheduler import CurrentThreadScheduler class Task2(Observable): def __init__(self): self.disposed = False def subscribe(observer, scheduler):
def test_pyside2_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)
def test_pyside2_schedule_now(self): scheduler = QtScheduler(QtCore) diff = scheduler.now - default_now() assert abs(diff) < timedelta(milliseconds=1)