Aggiunta iconcina.

Leonardo Robol [2010-02-05 15:20]
Aggiunta iconcina.
Filename
BatteryMonitor.py
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 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="32"
+   height="32"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.47 r22583"
+   sodipodi:docname="clock.svg"
+   inkscape:export-filename="/home/leonardo/src/BatteryMonitor/clock.png"
+   inkscape:export-xdpi="67.5"
+   inkscape:export-ydpi="67.5">
+  <defs
+     id="defs4">
+    <inkscape:path-effect
+       effect="spiro"
+       id="path-effect3592"
+       is_visible="true" />
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 526.18109 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="744.09448 : 526.18109 : 1"
+       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+       id="perspective10" />
+    <inkscape:perspective
+       id="perspective3602"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
+    <inkscape:path-effect
+       effect="spiro"
+       id="path-effect3592-8"
+       is_visible="true" />
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="11.313708"
+     inkscape:cx="21.319376"
+     inkscape:cy="15.409863"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     inkscape:window-width="1280"
+     inkscape:window-height="728"
+     inkscape:window-x="0"
+     inkscape:window-y="25"
+     inkscape:window-maximized="1" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Livello 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(0,-1020.3622)">
+    <path
+       sodipodi:type="arc"
+       style="fill:#000000;fill-opacity:0.11382117000000000;stroke:#000000;stroke-width:1.82975344999999989;stroke-miterlimit:4;stroke-opacity:0.9186992;stroke-dasharray:none"
+       id="path2816"
+       sodipodi:cx="17.723215"
+       sodipodi:cy="18.875"
+       sodipodi:rx="12.1875"
+       sodipodi:ry="11.696428"
+       d="m 29.910715,18.875 c 0,6.459759 -5.45653,11.696428 -12.1875,11.696428 -6.73097,0 -12.1874999,-5.236669 -12.1874999,-11.696428 0,-6.459759 5.4565299,-11.6964283 12.1874999,-11.6964283 6.73097,0 12.1875,5.2366693 12.1875,11.6964283 z"
+       transform="matrix(0.84829595,0,0,0.87565059,0.8632807,1019.418)" />
+    <path
+       style="fill:none;stroke:#000000;stroke-width:0.77999997;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:0.86585364;stroke-dasharray:none"
+       d="m 14.798531,1036.0142 5.89,-6.1918"
+       id="path3590"
+       inkscape:path-effect="#path-effect3592"
+       inkscape:original-d="m 14.798531,1036.0142 c 5.13,-6.454 5.89,-6.1918 5.89,-6.1918" />
+    <path
+       style="fill:none;stroke:#000000;stroke-width:0.99699998;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:0.86585364;stroke-dasharray:none"
+       d="m 14.8485,1036.3051 4.06,1.9086"
+       id="path3590-8"
+       inkscape:path-effect="#path-effect3592-8"
+       inkscape:original-d="m 14.8485,1036.3051 c 4,1.2947 4.06,1.9086 4.06,1.9086" />
+  </g>
+</svg>
ViewGit