1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2008 Alen Bou-Haidar <alencool@gmail.com>
5
# Elloquence Messenger is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# Elloquence Messenger is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>
18
from __future__ import division
23
class DelayedEvent(object):
24
def __init__(self, call_back, delay=200):
26
self._milliseconds = float(delay)
27
self._call_back = call_back
28
self._call_time = time.time()
32
call_time = self._call_time
33
now_time = time.time()
34
if (now_time - call_time) >= (self._milliseconds/1000):
35
self._call_back(*self._params)
41
def call_event(self, *params):
43
self._call_time = time.time()
44
if not self._event_id:
45
interval = int(self._milliseconds/2)
46
self._event_id = gobject.timeout_add(interval, self._time_out)