Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorEduardo Silva <edsiper@monotop.(none)>2007-03-12 15:02:36 (GMT)
committer Eduardo Silva <edsiper@monotop.(none)>2007-03-12 15:02:36 (GMT)
commit84f6bdd0c91229af8c08d7958c7a3ebb3b57ae5e (patch)
tree5e70b32a92aab9a3406f2bebab7e608494ad87de /shell
parentacaac29906f5f921b2978b04e0fda52b51094a03 (diff)
Battery status update
Diffstat (limited to 'shell')
-rw-r--r--shell/model/devices/battery.py29
-rw-r--r--shell/view/devices/battery.py4
2 files changed, 31 insertions, 2 deletions
diff --git a/shell/model/devices/battery.py b/shell/model/devices/battery.py
index a4f37f1..0244b24 100644
--- a/shell/model/devices/battery.py
+++ b/shell/model/devices/battery.py
@@ -10,7 +10,9 @@ class Device(device.Device):
def __init__(self):
device.Device.__init__(self)
+
self._level = 0
+ self._timeout_id = gobject.timeout_add(2000, self._check_battery_level)
def do_get_property(self, pspec):
if pspec.name == 'level':
@@ -18,3 +20,30 @@ class Device(device.Device):
def get_type(self):
return 'battery'
+
+ def _check_battery_level(self):
+ new_level = self._get_battery_level()
+
+ if new_level != self._level:
+ self._level = new_level
+ self.notify('level')
+
+ return True
+
+ def _get_battery_level(self):
+ battery_class_path = '/sys/class/battery/psu_0/'
+
+ capacity_path = battery_class_path + 'capacity_percentage'
+ try:
+ f = open(capacity_path, 'r')
+ val = f.read().split('\n')
+ level = int(val[0])
+ f.close()
+ except:
+ level = 0
+
+ return level
+
+ def __del__(self):
+ gobject.source_remove(self._timeout_id)
+ self._timeout_id = 0
diff --git a/shell/view/devices/battery.py b/shell/view/devices/battery.py
index 6a667a8..56e3ffb 100644
--- a/shell/view/devices/battery.py
+++ b/shell/view/devices/battery.py
@@ -7,7 +7,7 @@ class DeviceView(canvasicon.CanvasIcon):
canvasicon.CanvasIcon.__init__(self)
self._model = model
- model.connect('notify::strength', self._level_changed_cb)
+ model.connect('notify::level', self._level_changed_cb)
self._update_level()
@@ -15,6 +15,6 @@ class DeviceView(canvasicon.CanvasIcon):
self.props.icon_name = canvasicon.get_icon_state(
_ICON_NAME, self._model.props.level)
- def _level_changed_cb(self, pspec):
+ def _level_changed_cb(self, pspec, param):
self._update_level()