summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2020-07-19 21:54:40 +0200
committerjaseg <code@jaseg.net>2020-07-19 21:54:40 +0200
commit583f12ed6334eb6deac767a726f5ac6f9e7be9be (patch)
tree0cf14760a939565ce7e04c3f8a4cee583d2a5fcf
parent632a87af49d9a568103e6f0013b5f8a7988b2fb3 (diff)
downloadpython-mpv-583f12ed6334eb6deac767a726f5ac6f9e7be9be.tar.gz
python-mpv-583f12ed6334eb6deac767a726f5ac6f9e7be9be.tar.bz2
python-mpv-583f12ed6334eb6deac767a726f5ac6f9e7be9be.zip
mpv.py: add prepare_and_wait_for_property
-rw-r--r--mpv.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/mpv.py b/mpv.py
index f2d63c6..8421972 100644
--- a/mpv.py
+++ b/mpv.py
@@ -916,6 +916,15 @@ class MPV(object):
properties such as ``idle_active`` indicating the player is done with regular playback and just idling around.
Raises a ShutdownError when the core is shutdown while waiting.
"""
+ with self.prepare_and_wait_for_property(name, cond, level_sensitive):
+ pass
+
+ @contextmanager
+ def prepare_and_wait_for_property(self, name, cond=lambda val: val, level_sensitive=True):
+ """Context manager that waits until ``cond`` evaluates to a truthy value on the named property. See
+ prepare_and_wait_for_event for usage.
+ Raises a ShutdownError when the core is shutdown while waiting.
+ """
sema = threading.Semaphore(value=0)
def observer(name, val):
@@ -927,6 +936,7 @@ class MPV(object):
def shutdown_handler(event):
sema.release()
+ yield
if not level_sensitive or not cond(getattr(self, name.replace('-', '_'))):
sema.acquire()