|
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 | |
|---|
| 19 | import time |
|---|
| 20 | from string import find, lower |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | STATE_UNKNOWN = "OS probably not supported" |
|---|
| 24 | STATE_XAWAY = "extanted away" |
|---|
| 25 | STATE_AWAY = "away" |
|---|
| 26 | STATE_AWAKE = "awake" |
|---|
| 27 | |
|---|
| 28 | SUPPORTED = 1 |
|---|
| 29 | try: |
|---|
| 30 | import idle |
|---|
| 31 | except: |
|---|
| 32 | SUPPORTED = 0 |
|---|
| 33 | |
|---|
| 34 | class 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 | |
|---|
| 65 | if __name__ == '__main__': |
|---|
| 66 | s = Sleepy(10) |
|---|
| 67 | while s.poll(): |
|---|
| 68 | print "state is %s" % s.getState() |
|---|
| 69 | time.sleep(5) |
|---|