Changeset 159

Show
Ignore:
Timestamp:
05/28/04 06:20:30 (4 years ago)
Author:
asterix
Message:

- idle in a C module, auto away / xa feature is back
- no need to store .mo files : they are now created by make

Location:
trunk
Files:
3 added
1 removed
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/common/sleepy.py

    r58 r159  
    33 
    44import time 
     5import idle 
    56from string import find, lower 
    67 
     
    1718    def __init__(self, interval1 = 60, interval2 = 120, devices = ['keyboard', 'mouse', 'ts'] ): 
    1819 
    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 
    2622        self.state         = STATE_AWAKE ## assume were awake to stake with 
    2723        try: 
    28             self.proc_int_fh = open("/proc/interrupts",'r') 
     24            idle.init() 
    2925        except: 
    3026            NOT_SUPPORTED = 1 
    3127            self.state = STATE_UNKNOWN 
    32         self.proc_int_fh.close() 
    33          
    3428 
    3529    def poll(self): 
     
    3731        now = time.time() 
    3832 
    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 
    5840        return 1 
    5941 
     
    6446        self.state = val 
    6547             
    66     def _read_proc(self, device = 'mouse'): 
    67         proc_int_fh = open("/proc/interrupts",'r') 
    68         info = proc_int_fh.readlines() 
    69         ## ignore first line 
    70         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 1 
    77  
    7848if __name__ == '__main__': 
    7949    s = Sleepy(10) 
    8050    while s.poll(): 
    8151        print "state is %s" % s.getState()  
    82         time.sleep(10) 
     52        time.sleep(5) 
  • trunk/plugins/gtkgui/config.py

    r145 r159  
    2424import gtk.glade,gobject 
    2525import os,string 
     26import common.sleepy 
    2627from common import i18n 
    2728_ = i18n._ 
     
    217218                if self.plugin.sleeper: 
    218219                        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) 
    220222                self.plugin.send('CONFIG', None, ('GtkGui', self.plugin.config)) 
    221223                self.plugin.roster.draw_roster() 
     
    307309                        st = self.plugin.config['autoaway'] 
    308310                self.chk_autoaway.set_active(st) 
    309                 self.chk_autoaway.set_sensitive(0) 
    310311 
    311312                #Autoawaytime 
     
    314315                        st = self.plugin.config['autoawaytime'] 
    315316                self.spin_autoawaytime.set_value(st) 
    316                 self.spin_autoawaytime.set_sensitive(0) 
    317317 
    318318                #Autoxa 
     
    321321                        st = self.plugin.config['autoxa'] 
    322322                self.chk_autoxa.set_active(st) 
    323                 self.chk_autoxa.set_sensitive(0) 
    324323 
    325324                #Autoxatime 
     
    328327                        st = self.plugin.config['autoxatime'] 
    329328                self.spin_autoxatime.set_value(st) 
    330                 self.spin_autoxatime.set_sensitive(0) 
    331329 
    332330                self.xml.signal_connect('gtk_widget_destroy', self.delete_event) 
  • trunk/plugins/gtkgui/gtkgui.py

    r157 r159  
    786786                        txt = status 
    787787                        self.plugin.send('STATUS', account, (status, txt)) 
     788                        if status == 'online': 
     789                                self.plugin.sleeper_state[account] = 1 
    788790 
    789791        def on_optionmenu_changed(self, widget): 
     
    806808                for acct in accounts: 
    807809                        self.plugin.send('STATUS', acct, (status, txt)) 
     810                        if status == 'online': 
     811                                self.plugin.sleeper_state[acct] = 1 
    808812         
    809813        def set_optionmenu(self): 
     
    834838                                        self.chg_user_status(user, 'offline', 'Disconnected', account) 
    835839                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) 
    839844                self.plugin.connected[account] = statuss.index(status) 
    840845                self.set_optionmenu() 
     
    13501355        def read_sleepy(self):   
    13511356                """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: 
    13551358                        self.sleeper.poll() 
    13561359                        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)')) 
    13711376                return 1 
    13721377 
     
    13931398                self.connected = {} 
    13941399                self.nicks = {} 
     1400                self.sleeper_state = {} #whether we pass auto away / xa or not 
    13951401                for a in self.accounts.keys(): 
    13961402                        self.windows[a] = {} 
     
    14001406                        self.connected[a] = 0 
    14011407                        self.nicks[a] = self.accounts[a]['name'] 
     1408                        self.sleeper_state[a] = 0 
    14021409                self.roster = roster_Window(self) 
    14031410                gtk.timeout_add(100, self.read_queue) 
    14041411                gtk.timeout_add(1000, self.read_sleepy) 
    14051412                self.sleeper = None 
    1406                 self.sleeper_state = None 
    14071413                gtk.main() 
    14081414                gtk.threads_leave()