diff --git a/shell/model/devices/battery.py b/shell/model/devices/battery.py index 3e8d434c..a4f37f1d 100644 --- a/shell/model/devices/battery.py +++ b/shell/model/devices/battery.py @@ -1,11 +1,20 @@ +import gobject + from model.devices import device class Device(device.Device): + __gproperties__ = { + 'level' : (int, None, None, 0, 100, 0, + gobject.PARAM_READABLE) + } + def __init__(self): device.Device.__init__(self) + self._level = 0 + + def do_get_property(self, pspec): + if pspec.name == 'level': + return self._level def get_type(self): return 'battery' - - def get_level(self): - return 0 diff --git a/shell/model/devices/devicesmodel.py b/shell/model/devices/devicesmodel.py index 735b063c..df5e6fa0 100644 --- a/shell/model/devices/devicesmodel.py +++ b/shell/model/devices/devicesmodel.py @@ -21,7 +21,7 @@ class DevicesModel(gobject.GObject): gobject.GObject.__init__(self) self._devices = {} - #self.add_device(battery.Device()) + self.add_device(battery.Device()) self._observe_network_manager() diff --git a/shell/view/devices/battery.py b/shell/view/devices/battery.py index 520f94c2..6a667a86 100644 --- a/shell/view/devices/battery.py +++ b/shell/view/devices/battery.py @@ -7,5 +7,14 @@ class DeviceView(canvasicon.CanvasIcon): canvasicon.CanvasIcon.__init__(self) self._model = model - icon_name = canvasicon.get_icon_state(_ICON_NAME, 60) - self.props.icon_name = icon_name + model.connect('notify::strength', self._level_changed_cb) + + self._update_level() + + def _update_level(self): + self.props.icon_name = canvasicon.get_icon_state( + _ICON_NAME, self._model.props.level) + + def _level_changed_cb(self, pspec): + self._update_level() +