Changeset 7829 for branches/gajim_0.11/src/common/sleepy.py
- Timestamp:
- 01/13/07 23:35:41 (23 months ago)
- Files:
-
- 1 modified
-
branches/gajim_0.11/src/common/sleepy.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/gajim_0.11/src/common/sleepy.py
r7787 r7829 2 2 ## 3 3 ## Contributors for this file: 4 ## - Yann Le Boulanger <asterix@lagaule.org>5 ## - Nikos Kouremenos <kourem@gmail.com>4 ## - Yann Le Boulanger <asterix@lagaule.org> 5 ## - Nikos Kouremenos <kourem@gmail.com> 6 6 ## 7 7 ## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org> 8 ## Vincent Hanquez <tab@snarc.org>8 ## Vincent Hanquez <tab@snarc.org> 9 9 ## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org> 10 ## Nikos Kouremenos <kourem@gmail.com>10 ## Nikos Kouremenos <kourem@gmail.com> 11 11 ## 12 12 ## This program is free software; you can redistribute it and/or modify … … 27 27 STATE_XA = 'extended away' 28 28 STATE_AWAY = 'away' 29 STATE_AWAKE = 'awake'29 STATE_AWAKE = 'awake' 30 30 31 31 SUPPORTED = True 32 32 try: 33 if os.name == 'nt':34 import ctypes33 if os.name == 'nt': 34 import ctypes 35 35 36 GetTickCount = ctypes.windll.kernel32.GetTickCount37 GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo36 GetTickCount = ctypes.windll.kernel32.GetTickCount 37 GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo 38 38 39 class LASTINPUTINFO(ctypes.Structure): 40 _fields_ = [('cbSize', ctypes.c_uint), 41 ('dwTime', ctypes.c_uint)] 39 class LASTINPUTINFO(ctypes.Structure): 40 _fields_ = [('cbSize', ctypes.c_uint), ('dwTime', ctypes.c_uint)] 42 41 43 lastInputInfo = LASTINPUTINFO()44 lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo)42 lastInputInfo = LASTINPUTINFO() 43 lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo) 45 44 46 else: # unix47 import idle45 else: # unix 46 import idle 48 47 except: 49 48 gajim.log.debug('Unable to load idle module') … … 51 50 52 51 class SleepyWindows: 53 def __init__(self, away_interval = 60, xa_interval = 120):52 def __init__(self, away_interval = 60, xa_interval = 120): 54 53 self.away_interval = away_interval 55 54 self.xa_interval = xa_interval 56 55 self.state = STATE_AWAKE # assume we are awake 57 56 58 def getIdleSec(self):59 GetLastInputInfo(ctypes.byref(lastInputInfo))60 idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 100061 return idleDelta57 def getIdleSec(self): 58 GetLastInputInfo(ctypes.byref(lastInputInfo)) 59 idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 1000 60 return idleDelta 62 61 63 62 def poll(self): 64 63 '''checks to see if we should change state''' 64 if not SUPPORTED: 65 return False 66 65 67 idleTime = self.getIdleSec() 66 68 67 69 # xa is stronger than away so check for xa first 68 70 if idleTime > self.xa_interval: … … 81 83 82 84 class SleepyUnix: 83 84 85 def __init__(self, away_interval = 60, xa_interval = 120): 85 86 self.away_interval = away_interval … … 92 93 self.state = STATE_UNKNOWN 93 94 94 def getIdleSec(self):95 return idle.getIdleSec()95 def getIdleSec(self): 96 return idle.getIdleSec() 96 97 97 98 def poll(self): … … 101 102 102 103 idleTime = self.getIdleSec() 103 104 104 105 # xa is stronger than away so check for xa first 105 106 if idleTime > self.xa_interval: … … 118 119 119 120 if os.name == 'nt': 120 Sleepy = SleepyWindows121 Sleepy = SleepyWindows 121 122 else: 122 Sleepy = SleepyUnix123 Sleepy = SleepyUnix
