bugfix in autoaway + autoxa support
This commit is contained in:
parent
1776cc4b45
commit
dead744a92
3 changed files with 138 additions and 42 deletions
|
@ -6,20 +6,20 @@ from string import find, lower
|
||||||
|
|
||||||
|
|
||||||
STATE_UNKNOWN = "OS probably not supported"
|
STATE_UNKNOWN = "OS probably not supported"
|
||||||
STATE_SLEEPING = "Going to sleep"
|
STATE_XAWAY = "extanted away"
|
||||||
STATE_ASLEEP = "asleep"
|
STATE_AWAY = "away"
|
||||||
STATE_WOKEN = "waking up"
|
|
||||||
STATE_AWAKE = "awake"
|
STATE_AWAKE = "awake"
|
||||||
|
|
||||||
NOT_SUPPORTED = 0
|
NOT_SUPPORTED = 0
|
||||||
|
|
||||||
class Sleepy:
|
class Sleepy:
|
||||||
|
|
||||||
def __init__(self, interval = 60, devices = ['keyboard', 'mouse', 'ts'] ):
|
def __init__(self, interval1 = 60, interval2 = 120, devices = ['keyboard', 'mouse', 'ts'] ):
|
||||||
|
|
||||||
self.devices = devices
|
self.devices = devices
|
||||||
self.time_marker = time.time()
|
self.time_marker = time.time()
|
||||||
self.interval = self.interval_orig = interval
|
self.interval = self.interval_orig = interval1
|
||||||
|
self.interval_orig2 = interval2
|
||||||
self.last_proc_vals = {}
|
self.last_proc_vals = {}
|
||||||
for dev in self.devices: self.last_proc_vals[dev] = 0
|
for dev in self.devices: self.last_proc_vals[dev] = 0
|
||||||
|
|
||||||
|
@ -35,34 +35,26 @@ class Sleepy:
|
||||||
def poll(self):
|
def poll(self):
|
||||||
if NOT_SUPPORTED: return -1
|
if NOT_SUPPORTED: return -1
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if (now - self.time_marker >= self.interval):
|
|
||||||
|
|
||||||
self.time_marker = time.time() ## reset marker
|
changed = 0 ## figure out if we have recieved interupts
|
||||||
|
for dev in self.devices: ## any of the selected devices
|
||||||
|
proc_val = self._read_proc(dev)
|
||||||
|
changed = changed or ( self.last_proc_vals[dev] != proc_val )
|
||||||
|
self.last_proc_vals[dev] = proc_val
|
||||||
|
|
||||||
changed = 0 ## figure out if we have recieved interupts
|
if changed:
|
||||||
for dev in self.devices: ## any of the selected devices
|
## we are awake :)
|
||||||
proc_val = self._read_proc(dev)
|
self.time_marker = time.time() ## reset marker
|
||||||
changed = changed or ( self.last_proc_vals[dev] != proc_val )
|
self.state = STATE_AWAKE
|
||||||
self.last_proc_vals[dev] = proc_val
|
self.interval = self.interval_orig
|
||||||
|
else:
|
||||||
if changed:
|
if (now - self.time_marker >= self.interval):
|
||||||
## we are awake :)
|
|
||||||
if self.state == STATE_ASLEEP or \
|
|
||||||
self.state == STATE_SLEEPING :
|
|
||||||
self.state = STATE_WOKEN
|
|
||||||
self.interval = self.interval_orig
|
|
||||||
else:
|
|
||||||
self.state = STATE_AWAKE
|
|
||||||
else:
|
|
||||||
## we are asleep
|
## we are asleep
|
||||||
if self.state == STATE_AWAKE or \
|
if self.state == STATE_AWAKE:
|
||||||
self.state == STATE_WOKEN :
|
self.state = STATE_AWAY
|
||||||
self.state = STATE_SLEEPING
|
self.interval = self.interval_orig2 #second interval
|
||||||
## we increase the check time as catching activity
|
|
||||||
## is now more important
|
|
||||||
self.interval = 5
|
|
||||||
else:
|
else:
|
||||||
self.state = STATE_ASLEEP
|
self.state = STATE_XAWAY
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def getState(self):
|
def getState(self):
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
|
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
|
||||||
|
|
||||||
<glade-interface>
|
<glade-interface>
|
||||||
|
<requires lib="gnome"/>
|
||||||
|
|
||||||
<widget class="GtkWindow" id="Gajim">
|
<widget class="GtkWindow" id="Gajim">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -428,7 +429,6 @@
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||||
<signal name="clicked" handler="on_clear_button_clicked" last_modification_time="Thu, 01 Jan 2004 06:12:56 GMT"/>
|
|
||||||
|
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkAlignment" id="alignment5">
|
<widget class="GtkAlignment" id="alignment5">
|
||||||
|
@ -2976,7 +2976,7 @@ when NOT onlie</property>
|
||||||
|
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkFrame" id="frame4">
|
<widget class="GtkFrame" id="frame4">
|
||||||
<property name="width_request">250</property>
|
<property name="width_request">325</property>
|
||||||
<property name="height_request">142</property>
|
<property name="height_request">142</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="label_xalign">0</property>
|
<property name="label_xalign">0</property>
|
||||||
|
@ -3058,6 +3058,73 @@ when NOT onlie</property>
|
||||||
<property name="y_options"></property>
|
<property name="y_options"></property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
|
||||||
|
<child>
|
||||||
|
<widget class="GtkCheckButton" id="chk_autoxa">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="label" translatable="yes">Auto eXtanded Away After</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||||
|
<property name="active">False</property>
|
||||||
|
<property name="inconsistent">False</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="right_attach">1</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
<property name="bottom_attach">2</property>
|
||||||
|
<property name="x_options">fill</property>
|
||||||
|
<property name="y_options"></property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
<child>
|
||||||
|
<widget class="GtkSpinButton" id="spin_autoxatime">
|
||||||
|
<property name="width_request">50</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="climb_rate">1</property>
|
||||||
|
<property name="digits">0</property>
|
||||||
|
<property name="numeric">False</property>
|
||||||
|
<property name="update_policy">GTK_UPDATE_ALWAYS</property>
|
||||||
|
<property name="snap_to_ticks">False</property>
|
||||||
|
<property name="wrap">False</property>
|
||||||
|
<property name="adjustment">20 1 100 1 10 10</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="right_attach">2</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
<property name="bottom_attach">2</property>
|
||||||
|
<property name="y_options"></property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
<child>
|
||||||
|
<widget class="GtkLabel" id="label48">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="label" translatable="yes">Minutes</property>
|
||||||
|
<property name="use_underline">False</property>
|
||||||
|
<property name="use_markup">False</property>
|
||||||
|
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||||
|
<property name="wrap">False</property>
|
||||||
|
<property name="selectable">False</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
|
<property name="yalign">0.5</property>
|
||||||
|
<property name="xpad">0</property>
|
||||||
|
<property name="ypad">0</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">2</property>
|
||||||
|
<property name="right_attach">3</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
<property name="bottom_attach">2</property>
|
||||||
|
<property name="x_options">fill</property>
|
||||||
|
<property name="y_options"></property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
</child>
|
</child>
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,20 @@ class prefs:
|
||||||
aat = self.spin_autoawaytime.get_value_as_int()
|
aat = self.spin_autoawaytime.get_value_as_int()
|
||||||
self.r.plugin.autoawaytime = aat
|
self.r.plugin.autoawaytime = aat
|
||||||
self.r.cfgParser.set('GtkGui', 'autoawaytime', aat)
|
self.r.cfgParser.set('GtkGui', 'autoawaytime', aat)
|
||||||
self.r.plugin.sleeper = common.sleepy.Sleepy(self.r.plugin.autoawaytime*60)
|
#autoxa
|
||||||
|
xa = self.chk_autoxa.get_active()
|
||||||
|
if xa == True:
|
||||||
|
self.r.cfgParser.set('GtkGui', 'autoxa', '1')
|
||||||
|
self.r.plugin.autoxa = 1
|
||||||
|
else:
|
||||||
|
self.r.cfgParser.set('GtkGui', 'autoxa', '0')
|
||||||
|
self.r.plugin.autoxa = 0
|
||||||
|
axt = self.spin_autoxatime.get_value_as_int()
|
||||||
|
self.r.plugin.autoxatime = axt
|
||||||
|
self.r.cfgParser.set('GtkGui', 'autoxatime', axt)
|
||||||
|
if self.r.plugin.sleeper:
|
||||||
|
self.r.plugin.sleeper = common.sleepy.Sleepy(\
|
||||||
|
self.r.plugin.autoawaytime*60, self.r.plugin.autoxatime*60)
|
||||||
|
|
||||||
self.r.cfgParser.writeCfgFile()
|
self.r.cfgParser.writeCfgFile()
|
||||||
self.r.cfgParser.parseCfgFile()
|
self.r.cfgParser.parseCfgFile()
|
||||||
|
@ -153,6 +166,8 @@ class prefs:
|
||||||
self.chk_autopp = self.xml.get_widget("chk_autopopup")
|
self.chk_autopp = self.xml.get_widget("chk_autopopup")
|
||||||
self.chk_autoaway = self.xml.get_widget("chk_autoaway")
|
self.chk_autoaway = self.xml.get_widget("chk_autoaway")
|
||||||
self.spin_autoawaytime = self.xml.get_widget("spin_autoawaytime")
|
self.spin_autoawaytime = self.xml.get_widget("spin_autoawaytime")
|
||||||
|
self.chk_autoxa = self.xml.get_widget("chk_autoxa")
|
||||||
|
self.spin_autoxatime = self.xml.get_widget("spin_autoxatime")
|
||||||
|
|
||||||
#Color for incomming messages
|
#Color for incomming messages
|
||||||
colSt = self.r.cfgParser.GtkGui_inmsgcolor
|
colSt = self.r.cfgParser.GtkGui_inmsgcolor
|
||||||
|
@ -209,6 +224,18 @@ class prefs:
|
||||||
ti = string.atoi(st)
|
ti = string.atoi(st)
|
||||||
self.spin_autoawaytime.set_value(ti)
|
self.spin_autoawaytime.set_value(ti)
|
||||||
|
|
||||||
|
#Autoxa
|
||||||
|
st = self.r.cfgParser.GtkGui_autoxa
|
||||||
|
if not st:
|
||||||
|
st = '1'
|
||||||
|
xa = string.atoi(st)
|
||||||
|
self.chk_autoxa.set_active(xa)
|
||||||
|
st = self.r.cfgParser.GtkGui_autoxatime
|
||||||
|
if not st:
|
||||||
|
st = '20'
|
||||||
|
ti = string.atoi(st)
|
||||||
|
self.spin_autoxatime.set_value(ti)
|
||||||
|
|
||||||
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
|
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
|
||||||
self.xml.signal_connect('on_but_col_clicked', self.on_color_button_clicked)
|
self.xml.signal_connect('on_but_col_clicked', self.on_color_button_clicked)
|
||||||
self.xml.signal_connect('on_ok_clicked', self.on_ok)
|
self.xml.signal_connect('on_ok_clicked', self.on_ok)
|
||||||
|
@ -799,7 +826,8 @@ class roster:
|
||||||
self.chg_status(j, 'offline', 'Disconnected')
|
self.chg_status(j, 'offline', 'Disconnected')
|
||||||
else:
|
else:
|
||||||
self.connected = 1
|
self.connected = 1
|
||||||
self.plugin.sleeper = common.sleepy.Sleepy(self.plugin.autoawaytime*60)
|
self.plugin.sleeper = common.sleepy.Sleepy(\
|
||||||
|
self.plugin.autoawaytime*60, self.plugin.autoxatime*60)
|
||||||
|
|
||||||
def on_prefs(self, widget):
|
def on_prefs(self, widget):
|
||||||
window = prefs(self)
|
window = prefs(self)
|
||||||
|
@ -1076,24 +1104,26 @@ class plugin:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def read_sleepy(self):
|
def read_sleepy(self):
|
||||||
if self.sleeper:
|
if self.sleeper and (self.autoaway or self.autoxa) and \
|
||||||
state_pres = None
|
(self.r.optionmenu.get_history()==0 or \
|
||||||
|
self.sleeper_state!=common.sleepy.STATE_AWAKE):
|
||||||
self.sleeper.poll()
|
self.sleeper.poll()
|
||||||
state = self.sleeper.getState()
|
state = self.sleeper.getState()
|
||||||
if state != self.sleeper_state:
|
if state != self.sleeper_state:
|
||||||
accountsStr = self.r.cfgParser.Profile_accounts
|
accountsStr = self.r.cfgParser.Profile_accounts
|
||||||
accounts = string.split(accountsStr, ' ')
|
accounts = string.split(accountsStr, ' ')
|
||||||
if state == common.sleepy.STATE_WOKEN:
|
if state == common.sleepy.STATE_AWAKE:
|
||||||
#on repasse online
|
#on repasse online
|
||||||
self.r.optionmenu.set_history(0)
|
self.r.optionmenu.set_history(0)
|
||||||
self.r.queueOUT.put(('STATUS',('online', accounts[0])))
|
self.r.queueOUT.put(('STATUS',('online', accounts[0])))
|
||||||
if state == common.sleepy.STATE_SLEEPING:
|
if state == common.sleepy.STATE_AWAY and self.autoaway:
|
||||||
#on passe away
|
#on passe away
|
||||||
self.r.optionmenu.set_history(1)
|
self.r.optionmenu.set_history(1)
|
||||||
self.r.queueOUT.put(('STATUS',('away', accounts[0])))
|
self.r.queueOUT.put(('STATUS',('away', accounts[0])))
|
||||||
if state_pres:
|
if state == common.sleepy.STATE_XAWAY and self.autoxa:
|
||||||
pass
|
#on passe away
|
||||||
#self.send(state_pres)
|
self.r.optionmenu.set_history(2)
|
||||||
|
self.r.queueOUT.put(('STATUS',('xa', accounts[0])))
|
||||||
self.sleeper_state = state
|
self.sleeper_state = state
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -1110,10 +1140,17 @@ class plugin:
|
||||||
if not st:
|
if not st:
|
||||||
st = '10'
|
st = '10'
|
||||||
self.autoawaytime = string.atoi(st)
|
self.autoawaytime = string.atoi(st)
|
||||||
|
st = self.r.cfgParser.GtkGui_autoxa
|
||||||
|
if not st:
|
||||||
|
st = '1'
|
||||||
|
self.autoxa = string.atoi(st)
|
||||||
|
st = self.r.cfgParser.GtkGui_autoxatime
|
||||||
|
if not st:
|
||||||
|
st = '20'
|
||||||
|
self.autoxatime = string.atoi(st)
|
||||||
self.time = gtk.timeout_add(200, self.read_queue)
|
self.time = gtk.timeout_add(200, self.read_queue)
|
||||||
gtk.timeout_add(1000, self.read_sleepy)
|
gtk.timeout_add(1000, self.read_sleepy)
|
||||||
self.sleeper = None
|
self.sleeper = None
|
||||||
# self.sleeper = common.sleepy.Sleepy(10)
|
|
||||||
self.sleeper_state = None
|
self.sleeper_state = None
|
||||||
gtk.main()
|
gtk.main()
|
||||||
# while 1:
|
# while 1:
|
||||||
|
|
Loading…
Add table
Reference in a new issue