Example #1
0
 def get_idle_time():
     """How long ago the user was last active (in ms).
     The *nix version uses the actmon module
     to get the time of the last input activity.
     """
     
     return actmon.get_idle_time()
Example #2
0
File: tsw.py Project: ahagmann/tsw
    def update(self):
        sum = 0
        for task in self.tasks.values():
            task.update()
            sum += task.get_value()

        self.status.setText("total: %d:%02d" % (sum/3600, (sum/60) % 60))

        active_task = None
        for t in self.tasks.values():
            if t.active:
                active_task = t
                break

        if active_task:
            self.sys_tray_icon.setIcon(self.active_icon)

            if actmon.get_idle_time() >= 15*60*1000:
                inactive_start_time = time.time() - 15*60
                value = QtGui.QMessageBox.question(self, "No Activity", "No activity since %s. Stop '%s'?" %
                    (time.strftime("%H:%M", time.localtime(inactive_start_time)), active_task.label.text()), "Yes", "No")
                if value == 0:
                    active_task.stop(inactive_start_time)
        else:
            self.sys_tray_icon.setIcon(self.inactive_icon)
Example #3
0
    def tick(self):
        if self.counter > 0:
            time = str( self.format_time(self.counter) )
            if self.time == "break":
                self.time_lbl.set_label( self.text_style.replace("%text%", time) )
            else:
                status_icon.set_tooltip_text("Next break in %s" % (time))
                builder.get_object('time_remaining').set_label(time)
            if actmon.get_idle_time() > self.idle_time*1000 and self.time == "work":
                self.timer_pause()
            else:
                self.timer_play()

            if self.timer_counting:
                self.counter -= 1
        else:
            if self.time == "break":
                self.start_work()
            else:
                self.start_break()
        return True
Example #4
0
    def tick(self):
        if self.counter > 0:
            time = str(self.format_time(self.counter))
            if self.time == "break":
                self.time_lbl.set_label(self.text_style.replace(
                    "%text%", time))
            else:
                status_icon.set_tooltip_text("Next break in %s" % (time))
                builder.get_object('time_remaining').set_label(time)
            if actmon.get_idle_time(
            ) > self.idle_time * 1000 and self.time == "work":
                self.timer_pause()
            else:
                self.timer_play()

            if self.timer_counting:
                self.counter -= 1
        else:
            if self.time == "break":
                self.start_work()
            else:
                self.start_break()
        return True
Example #5
0
    def poll(self):
        ms = actmon.get_idle_time()
        ctx = DEV['xidle/%s' % host]
        subj = URIRef("http://bigasterisk.com/host/%s/xidle" % host)
        masterGraph.patchObject(ctx, subj, ROOM['idleTimeMs'], Literal(ms))
        masterGraph.patchObject(ctx, subj, ROOM['idleTimeMinutes'],
                                Literal(ms / 1000 / 60))
        
        lastMinActive = ms < 60 * 1000
        now = int(time.time())
        if self.lastSent != lastMinActive or now > self.lastSentTime + 3600:
            self.points.append({"measurement": "presence",
                                "tags": {"host": host, "sensor": "xidle"},
                                "fields": {"value": 1 if lastMinActive else 0},
                                "time": now})
            self.lastSent = lastMinActive
            self.lastSentTime = now

            try:
                client.write_points(self.points, time_precision='s')
            except influxdb.exceptions.InfluxDBServerError as e:
                print repr(e)
                reactor.crash()
            self.points = []
Example #6
0
 def get(self):
     self.set_header('Content-type', 'application/json')
     self.write(json.dumps({"idleMs" : actmon.get_idle_time()}))
Example #7
0
 def get(self):
     actmon.get_idle_time() # fail if we can't get the display or something
     self.write('''
   Get the <a href="idle">X idle time</a> on %s.
   <a href="graph">rdf graph</a> available.''' % host)
Example #8
0
import actmon
# another option: http://thp.io/2007/09/x11-idle-time-and-focused-window-in.html

DEV = Namespace("http://projects.bigasterisk.com/device/")
ROOM = Namespace("http://projects.bigasterisk.com/room/")

sys.path.append('../../lib')
from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler

host = socket.gethostname()
client = InfluxDBClient('bang6', 9060, 'root', 'root', 'main')

os.environ['DISPLAY'] = ':0.0'

actmon.get_idle_time() # fail if we can't get the display or something

class Root(cyclone.web.RequestHandler):
    def get(self):
        actmon.get_idle_time() # fail if we can't get the display or something
        self.write('''
      Get the <a href="idle">X idle time</a> on %s.
      <a href="graph">rdf graph</a> available.''' % host)
        
class Idle(cyclone.web.RequestHandler):
    def get(self):
        self.set_header('Content-type', 'application/json')
        self.write(json.dumps({"idleMs" : actmon.get_idle_time()}))
        
class Poller(object):
    def __init__(self):
Example #9
0
def get_seconds_idle():
    return actmon.get_idle_time() / 1000
Example #10
0
  # Battery tasks
  if ac:
    iBatt = 0
  elif battery:
    time2empty = battery.time2empty()
    if time2empty:
      print("time2empty:", str(time2empty), iBatt)
      tasksBL = sorted(tasksBattLevel, cmp=lambda x, y: cmp(x[0], y[0]), reverse=True)
      for iBatt in range(iBatt, len(tasksBL)):
        t = tasksBL[iBatt]
        if time2empty > t[0]: break;
        t[1]()


  # Idle tasks
  idle = datetime.timedelta(milliseconds = actmon.get_idle_time())
  print("idle:", str(idle))
  
  if idle < idlePrev or ac != acPrev: iIdle = 0
  tasksIdle = sorted(( tasksIdleBatt, tasksIdleAC )[ac], cmp = lambda x, y: cmp(x[0], y[0]))

  for iIdle in range(iIdle, len(tasksIdle)):
    t = tasksIdle[iIdle]
    if idle < t[0]: break;
    t[1]()

  idlePrev = idle


  acPrev   = ac
  lidPrev  = lid