Changeset 159
- Timestamp:
- 05/28/04 06:20:30 (4 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 1 removed
- 3 modified
-
common/idle.cpp (added)
-
common/sleepy.py (modified) (4 diffs)
-
Makefile (added)
-
Messages/fr/LC_MESSAGES/gajim.mo (deleted)
-
plugins/gtkgui/config.py (modified) (6 diffs)
-
plugins/gtkgui/gtkgui.py (modified) (6 diffs)
-
setup.py (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/sleepy.py
r58 r159 3 3 4 4 import time 5 import idle 5 6 from string import find, lower 6 7 … … 17 18 def __init__(self, interval1 = 60, interval2 = 120, devices = ['keyboard', 'mouse', 'ts'] ): 18 19 19 self.devices = devices 20 self.time_marker = time.time() 21 self.interval = self.interval_orig = interval1 22 self.interval_orig2 = interval2 23 self.last_proc_vals = {} 24 for dev in self.devices: self.last_proc_vals[dev] = 0 25 20 self.interval1 = interval1 21 self.interval2 = interval2 26 22 self.state = STATE_AWAKE ## assume were awake to stake with 27 23 try: 28 self.proc_int_fh = open("/proc/interrupts",'r')24 idle.init() 29 25 except: 30 26 NOT_SUPPORTED = 1 31 27 self.state = STATE_UNKNOWN 32 self.proc_int_fh.close()33 34 28 35 29 def poll(self): … … 37 31 now = time.time() 38 32 39 changed = 0 ## figure out if we have recieved interupts 40 for dev in self.devices: ## any of the selected devices 41 proc_val = self._read_proc(dev) 42 changed = changed or ( self.last_proc_vals[dev] != proc_val ) 43 self.last_proc_vals[dev] = proc_val 44 45 if changed: 46 ## we are awake :) 47 self.time_marker = time.time() ## reset marker 48 self.state = STATE_AWAKE 49 self.interval = self.interval_orig 50 else: 51 if (now - self.time_marker >= self.interval): 52 ## we are asleep 53 if self.state == STATE_AWAKE: 54 self.state = STATE_AWAY 55 self.interval = self.interval_orig2 #second interval 56 else: 57 self.state = STATE_XAWAY 33 idleTime = idle.getIdleSec() 34 if idleTime > self.interval2: 35 self.state = STATE_XAWAY 36 elif idleTime > self.interval1: 37 self.state = STATE_AWAY 38 else: 39 self.state = STATE_AWAKE 58 40 return 1 59 41 … … 64 46 self.state = val 65 47 66 def _read_proc(self, device = 'mouse'):67 proc_int_fh = open("/proc/interrupts",'r')68 info = proc_int_fh.readlines()69 ## ignore first line70 for line in info[1:]:71 cols = line.strip().split()72 if (find(lower(cols[-1]),device) != -1):73 proc_int_fh.close()74 return int(cols[1])75 proc_int_fh.close()76 return 177 78 48 if __name__ == '__main__': 79 49 s = Sleepy(10) 80 50 while s.poll(): 81 51 print "state is %s" % s.getState() 82 time.sleep( 10)52 time.sleep(5) -
trunk/plugins/gtkgui/config.py
r145 r159 24 24 import gtk.glade,gobject 25 25 import os,string 26 import common.sleepy 26 27 from common import i18n 27 28 _ = i18n._ … … 217 218 if self.plugin.sleeper: 218 219 self.plugin.sleeper = common.sleepy.Sleepy(\ 219 self.plugin['autoawaytime']*60, self.plugin['autoxatime']*60) 220 self.plugin.config['autoawaytime']*60, \ 221 self.plugin.config['autoxatime']*60) 220 222 self.plugin.send('CONFIG', None, ('GtkGui', self.plugin.config)) 221 223 self.plugin.roster.draw_roster() … … 307 309 st = self.plugin.config['autoaway'] 308 310 self.chk_autoaway.set_active(st) 309 self.chk_autoaway.set_sensitive(0)310 311 311 312 #Autoawaytime … … 314 315 st = self.plugin.config['autoawaytime'] 315 316 self.spin_autoawaytime.set_value(st) 316 self.spin_autoawaytime.set_sensitive(0)317 317 318 318 #Autoxa … … 321 321 st = self.plugin.config['autoxa'] 322 322 self.chk_autoxa.set_active(st) 323 self.chk_autoxa.set_sensitive(0)324 323 325 324 #Autoxatime … … 328 327 st = self.plugin.config['autoxatime'] 329 328 self.spin_autoxatime.set_value(st) 330 self.spin_autoxatime.set_sensitive(0)331 329 332 330 self.xml.signal_connect('gtk_widget_destroy', self.delete_event) -
trunk/plugins/gtkgui/gtkgui.py
r157 r159 786 786 txt = status 787 787 self.plugin.send('STATUS', account, (status, txt)) 788 if status == 'online': 789 self.plugin.sleeper_state[account] = 1 788 790 789 791 def on_optionmenu_changed(self, widget): … … 806 808 for acct in accounts: 807 809 self.plugin.send('STATUS', acct, (status, txt)) 810 if status == 'online': 811 self.plugin.sleeper_state[acct] = 1 808 812 809 813 def set_optionmenu(self): … … 834 838 self.chg_user_status(user, 'offline', 'Disconnected', account) 835 839 elif self.plugin.connected[account] == 0: 836 self.plugin.sleeper = None#common.sleepy.Sleepy(\ 837 #self.plugin.config['autoawaytime']*60, \ 838 #self.plugin.config['autoxatime']*60) 840 if (self.plugin.config['autoaway'] or self.plugin.config['autoxa']): 841 self.plugin.sleeper = common.sleepy.Sleepy(\ 842 self.plugin.config['autoawaytime']*60, \ 843 self.plugin.config['autoxatime']*60) 839 844 self.plugin.connected[account] = statuss.index(status) 840 845 self.set_optionmenu() … … 1350 1355 def read_sleepy(self): 1351 1356 """Check if we are idle""" 1352 if self.sleeper and (self.config['autoaway'] or self.config['autoxa'])\ 1353 and (self.roster.optionmenu.get_history()==0 or \ 1354 self.sleeper_state!=common.sleepy.STATE_AWAKE): 1357 if self.sleeper: 1355 1358 self.sleeper.poll() 1356 1359 state = self.sleeper.getState() 1357 if state != self.sleeper_state: 1358 if state == common.sleepy.STATE_AWAKE: 1359 #we go online 1360 self.roster.optionmenu.set_history(0) 1361 self.send('STATUS', None, ('online', '')) 1362 elif state == common.sleepy.STATE_AWAY and self.config['autoaway']: 1363 #we go away 1364 self.roster.optionmenu.set_history(1) 1365 self.send('STATUS', None, ('away', 'auto away (idle)')) 1366 elif state == common.sleepy.STATE_XAWAY and self.config['autoxa']: 1367 #we go extended away 1368 self.roster.optionmenu.set_history(2) 1369 self.send('STATUS',('xa', 'auto away (idel)')) 1370 self.sleeper_state = state 1360 for account in self.accounts.keys(): 1361 if self.sleeper_state[account]: 1362 if state == common.sleepy.STATE_AWAKE and \ 1363 self.connected[account] > 1: 1364 #we go online 1365 self.send('STATUS', account, ('online', '')) 1366 elif state == common.sleepy.STATE_AWAY and \ 1367 self.connected[account] == 1 and \ 1368 self.config['autoaway']: 1369 #we go away 1370 self.send('STATUS', account, ('away', 'auto away (idle)')) 1371 elif state == common.sleepy.STATE_XAWAY and \ 1372 self.connected[account] == 2 and \ 1373 self.config['autoxa']: 1374 #we go extended away 1375 self.send('STATUS', account, ('xa', 'auto away (idle)')) 1371 1376 return 1 1372 1377 … … 1393 1398 self.connected = {} 1394 1399 self.nicks = {} 1400 self.sleeper_state = {} #whether we pass auto away / xa or not 1395 1401 for a in self.accounts.keys(): 1396 1402 self.windows[a] = {} … … 1400 1406 self.connected[a] = 0 1401 1407 self.nicks[a] = self.accounts[a]['name'] 1408 self.sleeper_state[a] = 0 1402 1409 self.roster = roster_Window(self) 1403 1410 gtk.timeout_add(100, self.read_queue) 1404 1411 gtk.timeout_add(1000, self.read_sleepy) 1405 1412 self.sleeper = None 1406 self.sleeper_state = None1407 1413 gtk.main() 1408 1414 gtk.threads_leave()
