~ubuntu-branches/ubuntu/precise/emesene/precise-201203200543

« back to all changes in this revision

Viewing changes to DelayedEvent.py

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2009-10-20 16:48:42 UTC
  • mfrom: (1.1.4 upstream) (5.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091020164842-p6r1w6wr9x6gkk08
Tags: 1.5.1-1
* New upstream release.
  - debian/rules,
    debian/copyright:
    + uuid.py is not shipped upstream anymore, don't remove it it rules
      and don't mention it in copyright.
* debian/bin/emesene,
  debian/rules,
  debian/links:
  - Don't install a wrapper script in /usr/bin, install the upstream
    script together with the python modules and symlink it to /usr/bin
    instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
3
 
# Copyright (C) 2008 Alen Bou-Haidar <alencool@gmail.com>
4
 
#
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.
9
 
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.
14
 
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/>
17
 
 
18
 
from __future__ import division
19
 
 
20
 
import time
21
 
import gobject
22
 
 
23
 
class DelayedEvent(object):
24
 
    def __init__(self, call_back, delay=200):
25
 
        self._event_id = None
26
 
        self._milliseconds = float(delay)
27
 
        self._call_back = call_back
28
 
        self._call_time = time.time()
29
 
        self._params = ()
30
 
        
31
 
    def _time_out(self):
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)
36
 
            self._event_id = None
37
 
            return False
38
 
        else:
39
 
            return True
40
 
          
41
 
    def call_event(self, *params):
42
 
        self._params = 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)