autoaway support
This commit is contained in:
parent
bded2aeb2c
commit
1776cc4b45
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/env python
|
||||
"""A Quick class to tell if theres any activity on your machine"""
|
||||
|
||||
import time
|
||||
from string import find, lower
|
||||
|
||||
|
||||
STATE_UNKNOWN = "OS probably not supported"
|
||||
STATE_SLEEPING = "Going to sleep"
|
||||
STATE_ASLEEP = "asleep"
|
||||
STATE_WOKEN = "waking up"
|
||||
STATE_AWAKE = "awake"
|
||||
|
||||
NOT_SUPPORTED = 0
|
||||
|
||||
class Sleepy:
|
||||
|
||||
def __init__(self, interval = 60, devices = ['keyboard', 'mouse', 'ts'] ):
|
||||
|
||||
self.devices = devices
|
||||
self.time_marker = time.time()
|
||||
self.interval = self.interval_orig = interval
|
||||
self.last_proc_vals = {}
|
||||
for dev in self.devices: self.last_proc_vals[dev] = 0
|
||||
|
||||
self.state = STATE_AWAKE ## assume were awake to stake with
|
||||
try:
|
||||
self.proc_int_fh = open("/proc/interrupts",'r')
|
||||
except:
|
||||
NOT_SUPPORTED = 1
|
||||
self.state = STATE_UNKNOWN
|
||||
self.proc_int_fh.close()
|
||||
|
||||
|
||||
def poll(self):
|
||||
if NOT_SUPPORTED: return -1
|
||||
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
|
||||
|
||||
if changed:
|
||||
## 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
|
||||
if self.state == STATE_AWAKE or \
|
||||
self.state == STATE_WOKEN :
|
||||
self.state = STATE_SLEEPING
|
||||
## we increase the check time as catching activity
|
||||
## is now more important
|
||||
self.interval = 5
|
||||
else:
|
||||
self.state = STATE_ASLEEP
|
||||
return 1
|
||||
|
||||
def getState(self):
|
||||
return self.state
|
||||
|
||||
def setState(self,val):
|
||||
self.state = val
|
||||
|
||||
def _read_proc(self, device = 'mouse'):
|
||||
proc_int_fh = open("/proc/interrupts",'r')
|
||||
info = proc_int_fh.readlines()
|
||||
## ignore first line
|
||||
for line in info[1:]:
|
||||
cols = line.strip().split()
|
||||
if (find(lower(cols[-1]),device) != -1):
|
||||
proc_int_fh.close()
|
||||
return int(cols[1])
|
||||
proc_int_fh.close()
|
||||
return 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
s = Sleepy(10)
|
||||
while s.poll():
|
||||
print "state is %s" % s.getState()
|
||||
time.sleep(10)
|
|
@ -2971,9 +2971,100 @@ when NOT onlie</property>
|
|||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label40">
|
||||
<widget class="GtkFixed" id="fixed3">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Empty</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkFrame" id="frame4">
|
||||
<property name="width_request">250</property>
|
||||
<property name="height_request">142</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="label_yalign">0.5</property>
|
||||
<property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkTable" id="table3">
|
||||
<property name="visible">True</property>
|
||||
<property name="n_rows">3</property>
|
||||
<property name="n_columns">3</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="row_spacing">4</property>
|
||||
<property name="column_spacing">5</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_autoaway">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Auto 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">0</property>
|
||||
<property name="bottom_attach">1</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label47">
|
||||
<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">0</property>
|
||||
<property name="bottom_attach">1</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spin_autoawaytime">
|
||||
<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">10 1 100 1 10 10</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">0</property>
|
||||
<property name="bottom_attach">1</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label46">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Auto Status</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
|
@ -2984,6 +3075,17 @@ when NOT onlie</property>
|
|||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="type">label_item</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="x">0</property>
|
||||
<property name="y">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="tab_expand">False</property>
|
||||
<property name="tab_fill">True</property>
|
||||
|
@ -2993,7 +3095,7 @@ when NOT onlie</property>
|
|||
<child>
|
||||
<widget class="GtkLabel" id="label37">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">label37</property>
|
||||
<property name="label" translatable="yes">Presence</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
|
|
|
@ -22,13 +22,9 @@ import pygtk
|
|||
pygtk.require('2.0')
|
||||
import gtk
|
||||
from gtk import TRUE, FALSE
|
||||
import gtk.glade
|
||||
import gobject
|
||||
import os
|
||||
import string
|
||||
import time
|
||||
import Queue
|
||||
import common.optparser
|
||||
import gtk.glade,gobject
|
||||
import os,string,time,Queue
|
||||
import common.optparser,common.sleepy
|
||||
CONFPATH = "~/.gajimrc"
|
||||
Wbrowser = 0
|
||||
Waccounts = 0
|
||||
|
@ -111,6 +107,11 @@ class prefs:
|
|||
self.r.cfgParser.set('GtkGui', 'statusmsgcolor', colSt)
|
||||
for j in self.r.tab_messages.keys():
|
||||
self.r.tab_messages[j].tagStatus.set_property("foreground", colSt)
|
||||
#IconStyle
|
||||
ist = self.combo_iconstyle.entry.get_text()
|
||||
self.r.cfgParser.set('GtkGui', 'iconstyle', ist)
|
||||
self.r.iconstyle = ist
|
||||
self.r.mkpixbufs()
|
||||
#autopopup
|
||||
pp = self.chk_autopp.get_active()
|
||||
if pp == True:
|
||||
|
@ -119,11 +120,18 @@ class prefs:
|
|||
else:
|
||||
self.r.cfgParser.set('GtkGui', 'autopopup', '0')
|
||||
self.r.autopopup = 0
|
||||
#IconStyle
|
||||
ist = self.combo_iconstyle.entry.get_text()
|
||||
self.r.cfgParser.set('GtkGui', 'iconstyle', ist)
|
||||
self.r.iconstyle = ist
|
||||
self.r.mkpixbufs()
|
||||
#autoaway
|
||||
aw = self.chk_autoaway.get_active()
|
||||
if aw == True:
|
||||
self.r.cfgParser.set('GtkGui', 'autoaway', '1')
|
||||
self.r.plugin.autoaway = 1
|
||||
else:
|
||||
self.r.cfgParser.set('GtkGui', 'autoaway', '0')
|
||||
self.r.plugin.autoaway = 0
|
||||
aat = self.spin_autoawaytime.get_value_as_int()
|
||||
self.r.plugin.autoawaytime = aat
|
||||
self.r.cfgParser.set('GtkGui', 'autoawaytime', aat)
|
||||
self.r.plugin.sleeper = common.sleepy.Sleepy(self.r.plugin.autoawaytime*60)
|
||||
|
||||
self.r.cfgParser.writeCfgFile()
|
||||
self.r.cfgParser.parseCfgFile()
|
||||
|
@ -141,8 +149,10 @@ class prefs:
|
|||
self.da_in = self.xml.get_widget("drawing_in")
|
||||
self.da_out = self.xml.get_widget("drawing_out")
|
||||
self.da_status = self.xml.get_widget("drawing_status")
|
||||
self.chk_autopp = self.xml.get_widget("chk_autopopup")
|
||||
self.combo_iconstyle = self.xml.get_widget("combo_iconstyle")
|
||||
self.chk_autopp = self.xml.get_widget("chk_autopopup")
|
||||
self.chk_autoaway = self.xml.get_widget("chk_autoaway")
|
||||
self.spin_autoawaytime = self.xml.get_widget("spin_autoawaytime")
|
||||
|
||||
#Color for incomming messages
|
||||
colSt = self.r.cfgParser.GtkGui_inmsgcolor
|
||||
|
@ -168,13 +178,6 @@ class prefs:
|
|||
self.colorStatus = cmapStatus.alloc_color(colSt)
|
||||
self.da_status.window.set_background(self.colorStatus)
|
||||
|
||||
#Autopopup
|
||||
st = self.r.cfgParser.GtkGui_autopopup
|
||||
if not st:
|
||||
st = '0'
|
||||
pp = string.atoi(st)
|
||||
self.chk_autopp.set_active(pp)
|
||||
|
||||
#iconStyle
|
||||
list_style = os.listdir('plugins/gtkgui/icons/')
|
||||
l = []
|
||||
|
@ -187,6 +190,25 @@ class prefs:
|
|||
if self.r.iconstyle in l:
|
||||
self.combo_iconstyle.entry.set_text(self.r.iconstyle)
|
||||
|
||||
#Autopopup
|
||||
st = self.r.cfgParser.GtkGui_autopopup
|
||||
if not st:
|
||||
st = '0'
|
||||
pp = string.atoi(st)
|
||||
self.chk_autopp.set_active(pp)
|
||||
|
||||
#Autoaway
|
||||
st = self.r.cfgParser.GtkGui_autoaway
|
||||
if not st:
|
||||
st = '1'
|
||||
aw = string.atoi(st)
|
||||
self.chk_autoaway.set_active(aw)
|
||||
st = self.r.cfgParser.GtkGui_autoawaytime
|
||||
if not st:
|
||||
st = '10'
|
||||
ti = string.atoi(st)
|
||||
self.spin_autoawaytime.set_value(ti)
|
||||
|
||||
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_ok_clicked', self.on_ok)
|
||||
|
@ -638,10 +660,6 @@ class roster:
|
|||
self.add_user(self.l_contact[j]['user'])
|
||||
|
||||
def mklists(self, tab):
|
||||
""" l_contact = {jid:{'user':_, 'iter':[iter1, ...]] """
|
||||
self.l_contact = {}
|
||||
""" l_group = {name:iter} """
|
||||
self.l_group = {}
|
||||
for jid in tab.keys():
|
||||
#remove ressource from jid string
|
||||
ji = string.split(jid, '/')[0]
|
||||
|
@ -775,8 +793,13 @@ class roster:
|
|||
# if (not self.showOffline) and widget.name == 'offline':
|
||||
# self.treestore.clear()
|
||||
if widget.name == 'offline':
|
||||
self.connected = 0
|
||||
self.plugin.sleeper = None
|
||||
for j in self.l_contact.keys():
|
||||
self.chg_status(j, 'offline', 'Disconnected')
|
||||
else:
|
||||
self.connected = 1
|
||||
self.plugin.sleeper = common.sleepy.Sleepy(self.plugin.autoawaytime*60)
|
||||
|
||||
def on_prefs(self, widget):
|
||||
window = prefs(self)
|
||||
|
@ -795,6 +818,7 @@ class roster:
|
|||
def on_quit(self, widget):
|
||||
self.queueOUT.put(('QUIT',''))
|
||||
gtk.mainquit()
|
||||
# sys.exit(0)
|
||||
|
||||
def on_row_activated(self, widget, path, col=0):
|
||||
iter = self.treestore.get_iter(path)
|
||||
|
@ -862,9 +886,13 @@ class roster:
|
|||
self.xml = gtk.glade.XML('plugins/gtkgui/gtkgui.glade', 'Gajim')
|
||||
self.window = self.xml.get_widget('Gajim')
|
||||
self.tree = self.xml.get_widget('treeview')
|
||||
self.plug = plug
|
||||
self.plugin = plug
|
||||
#(icon, name, jid, editable, background color, show_icon)
|
||||
self.treestore = gtk.TreeStore(gtk.gdk.Pixbuf, str, str, gobject.TYPE_BOOLEAN, str, gobject.TYPE_BOOLEAN)
|
||||
#l_contact = {jid:{'user':_, 'iter':[iter1, ...]]
|
||||
self.l_contact = {}
|
||||
#l_group = {name:iter}
|
||||
self.l_group = {}
|
||||
self.iconstyle = self.cfgParser.GtkGui_iconstyle
|
||||
if not self.iconstyle:
|
||||
self.iconstyle = 'sun'
|
||||
|
@ -1047,13 +1075,49 @@ class plugin:
|
|||
Waccounts.init_accounts()
|
||||
return 1
|
||||
|
||||
def read_sleepy(self):
|
||||
if self.sleeper:
|
||||
state_pres = None
|
||||
self.sleeper.poll()
|
||||
state = self.sleeper.getState()
|
||||
if state != self.sleeper_state:
|
||||
accountsStr = self.r.cfgParser.Profile_accounts
|
||||
accounts = string.split(accountsStr, ' ')
|
||||
if state == common.sleepy.STATE_WOKEN:
|
||||
#on repasse online
|
||||
self.r.optionmenu.set_history(0)
|
||||
self.r.queueOUT.put(('STATUS',('online', accounts[0])))
|
||||
if state == common.sleepy.STATE_SLEEPING:
|
||||
#on passe away
|
||||
self.r.optionmenu.set_history(1)
|
||||
self.r.queueOUT.put(('STATUS',('away', accounts[0])))
|
||||
if state_pres:
|
||||
pass
|
||||
#self.send(state_pres)
|
||||
self.sleeper_state = state
|
||||
return 1
|
||||
|
||||
def __init__(self, quIN, quOUT):
|
||||
gtk.threads_init()
|
||||
gtk.threads_enter()
|
||||
self.queueIN = quIN
|
||||
self.r = roster(quOUT, self)
|
||||
st = self.r.cfgParser.GtkGui_autoaway
|
||||
if not st:
|
||||
st = '1'
|
||||
self.autoaway = string.atoi(st)
|
||||
st = self.r.cfgParser.GtkGui_autoawaytime
|
||||
if not st:
|
||||
st = '10'
|
||||
self.autoawaytime = string.atoi(st)
|
||||
self.time = gtk.timeout_add(200, self.read_queue)
|
||||
gtk.timeout_add(1000, self.read_sleepy)
|
||||
self.sleeper = None
|
||||
# self.sleeper = common.sleepy.Sleepy(10)
|
||||
self.sleeper_state = None
|
||||
gtk.main()
|
||||
# while 1:
|
||||
# while gtk.events_pending(): gtk.mainiteration()
|
||||
gtk.threads_leave()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue