root/branches/gajim_0.6.1/common/sleepy.py

Revision 359, 1.6 kB (checked in by asterix, 4 years ago)

update my email adress
update copyright
add missing headers

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Line 
1##      common/sleepy.py
2##
3## Gajim Team:
4##      - Yann Le Boulanger <asterix@lagaule.org>
5##      - Vincent Hanquez <tab@snarc.org>
6##
7##      Copyright (C) 2003-2005 Gajim Team
8##
9## This program is free software; you can redistribute it and/or modify
10## it under the terms of the GNU General Public License as published
11## by the Free Software Foundation; version 2 only.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18
19import time
20from string import find, lower
21
22
23STATE_UNKNOWN  = "OS probably not supported"
24STATE_XAWAY   = "extanted away"
25STATE_AWAY   = "away"
26STATE_AWAKE    = "awake"
27
28SUPPORTED = 1
29try:
30        import idle
31except:
32        SUPPORTED = 0
33
34class Sleepy:
35
36        def __init__(self, interval1 = 60, interval2 = 120):
37
38                self.interval1 = interval1
39                self.interval2 = interval2
40                self.state         = STATE_AWAKE ## assume were awake to stake with
41                try:
42                        idle.init()
43                except:
44                        SUPPORTED = 0
45                        self.state = STATE_UNKNOWN
46
47        def poll(self):
48                if not SUPPORTED: return 0
49
50                idleTime = idle.getIdleSec()
51                if idleTime > self.interval2:
52                        self.state = STATE_XAWAY
53                elif idleTime > self.interval1:
54                        self.state = STATE_AWAY
55                else:
56                        self.state = STATE_AWAKE
57                return 1
58
59        def getState(self):
60                return self.state
61
62        def setState(self,val):
63                self.state = val
64           
65if __name__ == '__main__':
66        s = Sleepy(10)
67        while s.poll():
68                print "state is %s" % s.getState() 
69                time.sleep(5)
Note: See TracBrowser for help on using the browser.