From 4c7e7176fcb331116fe1bd0931c908bc403f9869 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Fri, 5 Feb 2010 16:20:40 +0100 Subject: [PATCH] Aggiunta iconcina. --- BatteryMonitor.py | 17 +++++++-- clock.svg | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 2 deletions(-) mode change 100644 => 100755 BatteryMonitor.py create mode 100644 clock.svg diff --git a/BatteryMonitor.py b/BatteryMonitor.py old mode 100644 new mode 100755 index 8409451..5b2f505 --- a/BatteryMonitor.py +++ b/BatteryMonitor.py @@ -1,4 +1,7 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- import subprocess, re, gtk, gobject +from numpy.linalg import lstsq class BatteryMonitor(): @@ -40,7 +43,9 @@ class BatteryIcon(): def __init__(self): self.interval = 10000 - self.tray = gtk.status_icon_new_from_stock (gtk.STOCK_OPEN) + # self.tray = gtk.status_icon_new_from_stock (gtk.STOCK_OPEN) + + self.tray = gtk.status_icon_new_from_file ("clock.svg") self.tray.set_visible (True) self.bm = BatteryMonitor () @@ -70,6 +75,7 @@ class BatteryIcon(): if not self.bm.OnBattery (): self.energy = [] self.tray.set_tooltip ("Batteria non in uso") + self.ScheduleNext () return energy = self.bm.GetEnergy () @@ -83,7 +89,14 @@ class BatteryIcon(): elif (len(self.energy) > 100): del self.energy[0] - rate = (self.energy[0] - energy) * 1000 / (self.interval * (len(self.energy) - 1)) + times = [] + counter = 0 + for value in self.energy: + times.append( [ 1, counter ] ) + counter = counter + 10 + + rate = (-1) * lstsq(times, self.energy)[0][1] + time_to_discharge = energy / rate self.tray.set_tooltip("Tempo alla scarica: %s" % self.GetTimeString(time_to_discharge)) diff --git a/clock.svg b/clock.svg new file mode 100644 index 0000000..b1e83c8 --- /dev/null +++ b/clock.svg @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + -- 2.1.4