U vi @sddlZddlZddlmZmZmZddlmZmZddlm Z ddl m Z ddl m Z ddlmZed Zed ZGd d d e ZdS) N)AnyOptionalTypeVar)abctyping) PriorityQueue) DELTA_ZERO)PeriodicScheduler) ScheduledItem_TStateZRxcseZdZdZedfdd Zdejee ee j dddZ dej ejee ee j d d d Zdejejee ee j d d d ZddddZZS)PyGameSchedulerzA scheduler that schedules works for PyGame. Note that this class expects the caller to invoke run() repeatedly. http://www.pygame.org/docs/ref/time.html http://www.pygame.org/docs/ref/event.html)pygamecs&t||_t|_t|_dS)zCreate a new PyGameScheduler. Args: pygame: The PyGame module to use; typically, you would get this by import pygame N)super__init__Z_pygame threadingLock_lockr_queue)selfr __class__]/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/mainloop/pygamescheduler.pyrs  zPyGameScheduler.__init__N)actionstatereturncCstd||j|j||dS)a!Schedules an action to be executed. Args: action: Action to be executed. state: [Optional] state to be given to the action function. Returns: The disposable object used to cancel the scheduled action (best effort). z"PyGameScheduler.schedule(state=%s)r)logdebugschedule_absolutenow)rrrrrrschedule&s zPyGameScheduler.schedule)duetimerrrcCs&tt||}|j|j|||dS)atSchedules an action to be executed after duetime. Args: duetime: Relative time after which to execute the action. action: Action to be executed. state: [Optional] state to be given to the action function. Returns: The disposable object used to cancel the scheduled action (best effort). r)maxrZ to_timedeltar r!)rr#rrrrrschedule_relative7sz!PyGameScheduler.schedule_relativec Cs<||}t||||}|j|j|W5QRX|jS)aoSchedules an action to be executed at duetime. Args: duetime: Absolute time at which to execute the action. action: Action to be executed. state: [Optional] state to be given to the action function. Returns: The disposable object used to cancel the scheduled action (best effort). ) to_datetimer rrenqueueZ disposable)rr#rrsirrrr Ks  z!PyGameScheduler.schedule_absolute)rc Csb|jr^|j:|j}|j|j}|tkr8W5QRq^|j}W5QRX|s|qdS)N) rrpeekr#r!rdequeueZ is_cancelledZinvoke)ritemdiffrrrrunes   zPyGameScheduler.run)N)N)N)__name__ __module__ __qualname____doc__rrrZScheduledActionr rrZDisposableBaser"Z RelativeTimer%Z AbsoluteTimer r- __classcell__rrrrr s.   r )loggingrrrrrZ reactivexrZreactivex.internalrZreactivex.internal.constantsrZperiodicschedulerr Z scheduleditemr r getLoggerrr rrrrs