コード例 #1
0
	def append(self, callback):
		"""Just like list.append, except it can also handle lists and discards None-values"""
		if callback is None:
			pass
		elif callable(callback):
			list.append(self, WeakMethod(callback))
		elif isinstance(callback, list, tuple):
			for i in callback:
				self.append(i)
		else:
			assert False
コード例 #2
0
ファイル: clock.py プロジェクト: bernt/pymt
class _Event(object):

    def __init__(self, loop, callback, timeout, starttime):
        self.loop = loop
        self.callback = WeakMethod(callback)
        self.timeout = timeout
        self._last_dt = starttime
        self._dt = 0.

    def do(self, dt):
        if self.callback.is_dead():
            return False
        self.callback()(dt)

    def tick(self, curtime):
        # timeout happen ?
        if curtime - self._last_dt < self.timeout:
            return True

        # calculate current timediff for this event
        self._dt = curtime - self._last_dt
        self._last_dt = curtime

        # call the callback
        if self.callback.is_dead():
            return False
        ret = self.callback()(self._dt)

        # if it's a once event, don't care about the result
        # just remove the event
        if not self.loop:
            return False

        # if user return an explicit false,
        # remove the event
        if ret == False:
            return False

        return True
コード例 #3
0
ファイル: clock.py プロジェクト: bernt/pymt
 def __init__(self, loop, callback, timeout, starttime):
     self.loop = loop
     self.callback = WeakMethod(callback)
     self.timeout = timeout
     self._last_dt = starttime
     self._dt = 0.
コード例 #4
0
	def __contains__(self, elem):
		if isinstance(elem, WeakMethod):
			return list.__contains__(self, elem)
		else:
			return WeakMethod(elem) in self
コード例 #5
0
	def remove(self, elem):
		if not isinstance(elem, WeakMethod):
			elem = WeakMethod(elem)
		list.remove(self, elem)