mirror of https://github.com/kivy/kivy.git
Merge branch 'clock-compat' into clock-compat2
This commit is contained in:
commit
b80cdaff04
|
@ -216,6 +216,7 @@ from kivy.context import register_context
|
||||||
from kivy.weakmethod import WeakMethod
|
from kivy.weakmethod import WeakMethod
|
||||||
from kivy.config import Config
|
from kivy.config import Config
|
||||||
from kivy.logger import Logger
|
from kivy.logger import Logger
|
||||||
|
from kivy.compat import clock as _default_time
|
||||||
import time
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -238,12 +239,9 @@ try:
|
||||||
self._timer, ctypes.byref(delay), 0,
|
self._timer, ctypes.byref(delay), 0,
|
||||||
ctypes.c_void_p(), ctypes.c_void_p(), False)
|
ctypes.c_void_p(), ctypes.c_void_p(), False)
|
||||||
_kernel32.WaitForSingleObject(self._timer, 0xffffffff)
|
_kernel32.WaitForSingleObject(self._timer, 0xffffffff)
|
||||||
|
|
||||||
_default_time = time.clock
|
|
||||||
else:
|
else:
|
||||||
if platform == 'darwin':
|
if platform == 'darwin':
|
||||||
_libc = ctypes.CDLL('libc.dylib')
|
_libc = ctypes.CDLL('libc.dylib')
|
||||||
_default_time = time.time
|
|
||||||
else:
|
else:
|
||||||
from ctypes.util import find_library
|
from ctypes.util import find_library
|
||||||
_libc = ctypes.CDLL(find_library('c'), use_errno=True)
|
_libc = ctypes.CDLL(find_library('c'), use_errno=True)
|
||||||
|
@ -291,7 +289,6 @@ except (OSError, ImportError, AttributeError):
|
||||||
# OSError: if the libc cannot be readed (like with buildbot: invalid ELF
|
# OSError: if the libc cannot be readed (like with buildbot: invalid ELF
|
||||||
# header)
|
# header)
|
||||||
|
|
||||||
_default_time = time.time
|
|
||||||
_default_sleep = time.sleep
|
_default_sleep = time.sleep
|
||||||
|
|
||||||
class _ClockBase(object):
|
class _ClockBase(object):
|
||||||
|
@ -673,8 +670,7 @@ class ClockBase(_ClockBase):
|
||||||
|
|
||||||
time = staticmethod(partial(_default_time))
|
time = staticmethod(partial(_default_time))
|
||||||
|
|
||||||
ClockBase.time.__doc__ = '''Proxy method for time.time() or time.clock(),
|
ClockBase.time.__doc__ = '''Proxy method for :func:`~kivy.compat.clock`. '''
|
||||||
whichever is more suitable for the running OS'''
|
|
||||||
|
|
||||||
|
|
||||||
def mainthread(func):
|
def mainthread(func):
|
||||||
|
|
|
@ -7,6 +7,7 @@ __all__ = ('PY2', 'string_types', 'queue', 'iterkeys',
|
||||||
'itervalues', 'iteritems')
|
'itervalues', 'iteritems')
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
try:
|
try:
|
||||||
import queue
|
import queue
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -14,6 +15,10 @@ except ImportError:
|
||||||
|
|
||||||
#: True if Python 2 intepreter is used
|
#: True if Python 2 intepreter is used
|
||||||
PY2 = sys.version_info[0] == 2
|
PY2 = sys.version_info[0] == 2
|
||||||
|
'''True, if the version of python running is 2.x. '''
|
||||||
|
|
||||||
|
clock = None
|
||||||
|
'''A clock with the highest available resolution. '''
|
||||||
|
|
||||||
#: String types that can be used for checking if a object is a string
|
#: String types that can be used for checking if a object is a string
|
||||||
string_types = None
|
string_types = None
|
||||||
|
@ -38,3 +43,12 @@ else:
|
||||||
iterkeys = lambda d: iter(d.keys())
|
iterkeys = lambda d: iter(d.keys())
|
||||||
itervalues = lambda d: iter(d.values())
|
itervalues = lambda d: iter(d.values())
|
||||||
iteritems = lambda d: iter(d.items())
|
iteritems = lambda d: iter(d.items())
|
||||||
|
|
||||||
|
|
||||||
|
if PY2:
|
||||||
|
if sys.platform in ('win32', 'cygwin'):
|
||||||
|
clock = time.clock
|
||||||
|
else:
|
||||||
|
clock = time.time
|
||||||
|
else:
|
||||||
|
clock = time.perf_counter
|
||||||
|
|
Loading…
Reference in New Issue