indent with tabs, and prevent TB when ctypes modules is not found.
This commit is contained in:
parent
3567a8c20f
commit
0b035ee6cc
|
@ -1,13 +1,13 @@
|
||||||
## common/sleepy.py
|
## common/sleepy.py
|
||||||
##
|
##
|
||||||
## Contributors for this file:
|
## Contributors for this file:
|
||||||
## - Yann Le Boulanger <asterix@lagaule.org>
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
||||||
## - Nikos Kouremenos <kourem@gmail.com>
|
## - Nikos Kouremenos <kourem@gmail.com>
|
||||||
##
|
##
|
||||||
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
|
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
|
||||||
## Vincent Hanquez <tab@snarc.org>
|
## Vincent Hanquez <tab@snarc.org>
|
||||||
## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org>
|
## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org>
|
||||||
## Nikos Kouremenos <kourem@gmail.com>
|
## Nikos Kouremenos <kourem@gmail.com>
|
||||||
##
|
##
|
||||||
## This program is free software; you can redistribute it and/or modify
|
## This program is free software; you can redistribute it and/or modify
|
||||||
## it under the terms of the GNU General Public License as published
|
## it under the terms of the GNU General Public License as published
|
||||||
|
@ -26,44 +26,46 @@ import os
|
||||||
STATE_UNKNOWN = 'OS probably not supported'
|
STATE_UNKNOWN = 'OS probably not supported'
|
||||||
STATE_XA = 'extended away'
|
STATE_XA = 'extended away'
|
||||||
STATE_AWAY = 'away'
|
STATE_AWAY = 'away'
|
||||||
STATE_AWAKE = 'awake'
|
STATE_AWAKE = 'awake'
|
||||||
|
|
||||||
SUPPORTED = True
|
SUPPORTED = True
|
||||||
try:
|
try:
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
GetTickCount = ctypes.windll.kernel32.GetTickCount
|
GetTickCount = ctypes.windll.kernel32.GetTickCount
|
||||||
GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo
|
GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo
|
||||||
|
|
||||||
class LASTINPUTINFO(ctypes.Structure):
|
class LASTINPUTINFO(ctypes.Structure):
|
||||||
_fields_ = [('cbSize', ctypes.c_uint),
|
_fields_ = [('cbSize', ctypes.c_uint), ('dwTime', ctypes.c_uint)]
|
||||||
('dwTime', ctypes.c_uint)]
|
|
||||||
|
|
||||||
lastInputInfo = LASTINPUTINFO()
|
lastInputInfo = LASTINPUTINFO()
|
||||||
lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo)
|
lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo)
|
||||||
|
|
||||||
else: # unix
|
else: # unix
|
||||||
import idle
|
import idle
|
||||||
except:
|
except:
|
||||||
gajim.log.debug('Unable to load idle module')
|
gajim.log.debug('Unable to load idle module')
|
||||||
SUPPORTED = False
|
SUPPORTED = False
|
||||||
|
|
||||||
class SleepyWindows:
|
class SleepyWindows:
|
||||||
def __init__(self, away_interval = 60, xa_interval = 120):
|
def __init__(self, away_interval = 60, xa_interval = 120):
|
||||||
self.away_interval = away_interval
|
self.away_interval = away_interval
|
||||||
self.xa_interval = xa_interval
|
self.xa_interval = xa_interval
|
||||||
self.state = STATE_AWAKE # assume we are awake
|
self.state = STATE_AWAKE # assume we are awake
|
||||||
|
|
||||||
def getIdleSec(self):
|
def getIdleSec(self):
|
||||||
GetLastInputInfo(ctypes.byref(lastInputInfo))
|
GetLastInputInfo(ctypes.byref(lastInputInfo))
|
||||||
idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 1000
|
idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 1000
|
||||||
return idleDelta
|
return idleDelta
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
'''checks to see if we should change state'''
|
'''checks to see if we should change state'''
|
||||||
|
if not SUPPORTED:
|
||||||
|
return False
|
||||||
|
|
||||||
idleTime = self.getIdleSec()
|
idleTime = self.getIdleSec()
|
||||||
|
|
||||||
# xa is stronger than away so check for xa first
|
# xa is stronger than away so check for xa first
|
||||||
if idleTime > self.xa_interval:
|
if idleTime > self.xa_interval:
|
||||||
self.state = STATE_XA
|
self.state = STATE_XA
|
||||||
|
@ -80,7 +82,6 @@ class SleepyWindows:
|
||||||
self.state = val
|
self.state = val
|
||||||
|
|
||||||
class SleepyUnix:
|
class SleepyUnix:
|
||||||
|
|
||||||
def __init__(self, away_interval = 60, xa_interval = 120):
|
def __init__(self, away_interval = 60, xa_interval = 120):
|
||||||
self.away_interval = away_interval
|
self.away_interval = away_interval
|
||||||
self.xa_interval = xa_interval
|
self.xa_interval = xa_interval
|
||||||
|
@ -91,8 +92,8 @@ class SleepyUnix:
|
||||||
SUPPORTED = False
|
SUPPORTED = False
|
||||||
self.state = STATE_UNKNOWN
|
self.state = STATE_UNKNOWN
|
||||||
|
|
||||||
def getIdleSec(self):
|
def getIdleSec(self):
|
||||||
return idle.getIdleSec()
|
return idle.getIdleSec()
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
'''checks to see if we should change state'''
|
'''checks to see if we should change state'''
|
||||||
|
@ -100,7 +101,7 @@ class SleepyUnix:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
idleTime = self.getIdleSec()
|
idleTime = self.getIdleSec()
|
||||||
|
|
||||||
# xa is stronger than away so check for xa first
|
# xa is stronger than away so check for xa first
|
||||||
if idleTime > self.xa_interval:
|
if idleTime > self.xa_interval:
|
||||||
self.state = STATE_XA
|
self.state = STATE_XA
|
||||||
|
@ -117,6 +118,6 @@ class SleepyUnix:
|
||||||
self.state = val
|
self.state = val
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
Sleepy = SleepyWindows
|
Sleepy = SleepyWindows
|
||||||
else:
|
else:
|
||||||
Sleepy = SleepyUnix
|
Sleepy = SleepyUnix
|
||||||
|
|
Loading…
Reference in New Issue