1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2015 Yann Lanthony
# Copyright (c) 2017-2018 Spyder Project Contributors
#
# Licensed under the terms of the MIT License
# (See LICENSE.txt for details)
# -----------------------------------------------------------------------------
# Standard library imports
from os.path import dirname, join, normpath
import os
import time
PROJECT_DIR = normpath(dirname(dirname(__file__)))
EXAMPLES_DIR = normpath(join(PROJECT_DIR, 'examples'))
def example(*paths):
"""Get path to an example."""
return normpath(join(dirname(__file__), '..', 'examples', *paths))
def touch(file):
"""Touch a file."""
with open(str(file), 'a'):
os.utime(str(file), None)
def await_condition(condition, timeout=20, qt_app=None):
"""Return True if a condition is met in the given timeout period"""
for _ in range(timeout):
if qt_app:
# pump event loop while waiting for condition
qt_app.processEvents()
if condition():
return True
time.sleep(0.1)
return False
|