diff -urN sugar/shell/model/devices/battery.py NEWsugar/shell/model/devices/battery.py
|
old
|
new
|
|
| 24 | 24 | _LEVEL_PROP = 'battery.charge_level.percentage' |
| 25 | 25 | _CHARGING_PROP = 'battery.rechargeable.is_charging' |
| 26 | 26 | _DISCHARGING_PROP = 'battery.rechargeable.is_discharging' |
| | 27 | _PRESENT_PROP = 'battery.present' |
| 27 | 28 | |
| 28 | 29 | class Device(device.Device): |
| 29 | 30 | __gproperties__ = { |
| … |
… |
|
| 32 | 33 | 'charging' : (bool, None, None, False, |
| 33 | 34 | gobject.PARAM_READABLE), |
| 34 | 35 | 'discharging' : (bool, None, None, False, |
| | 36 | gobject.PARAM_READABLE), |
| | 37 | 'present' : (bool, None, None, False, |
| 35 | 38 | gobject.PARAM_READABLE) |
| 36 | 39 | } |
| 37 | 40 | |
| … |
… |
|
| 50 | 53 | self._level = self._get_level() |
| 51 | 54 | self._charging = self._get_charging() |
| 52 | 55 | self._discharging = self._get_discharging() |
| | 56 | self._present = self._get_present() |
| 53 | 57 | |
| 54 | 58 | def _get_level(self): |
| 55 | 59 | try: |
| | 60 | if not self._get_present(): |
| | 61 | return 0 |
| 56 | 62 | return self._battery.GetProperty(_LEVEL_PROP) |
| 57 | 63 | except dbus.DBusException: |
| 58 | 64 | logging.error('Cannot access %s' % _LEVEL_PROP) |
| … |
… |
|
| 60 | 66 | |
| 61 | 67 | def _get_charging(self): |
| 62 | 68 | try: |
| | 69 | if not self._get_present(): |
| | 70 | return False |
| 63 | 71 | return self._battery.GetProperty(_CHARGING_PROP) |
| 64 | 72 | except dbus.DBusException: |
| 65 | 73 | logging.error('Cannot access %s' % _CHARGING_PROP) |
| … |
… |
|
| 67 | 75 | |
| 68 | 76 | def _get_discharging(self): |
| 69 | 77 | try: |
| | 78 | if not self._get_present(): |
| | 79 | return False |
| 70 | 80 | return self._battery.GetProperty(_DISCHARGING_PROP) |
| 71 | 81 | except dbus.DBusException: |
| 72 | 82 | logging.error('Cannot access %s' % _DISCHARGING_PROP) |
| 73 | 83 | return False |
| 74 | 84 | |
| | 85 | def _get_present(self): |
| | 86 | try: |
| | 87 | return self._battery.GetProperty(_PRESENT_PROP) |
| | 88 | except dbus.DBusException: |
| | 89 | logging.error('Cannot access %s' % _PRESENT_PROP) |
| | 90 | return False |
| | 91 | |
| 75 | 92 | def do_get_property(self, pspec): |
| 76 | 93 | if pspec.name == 'level': |
| 77 | 94 | return self._level |
| … |
… |
|
| 79 | 96 | return self._charging |
| 80 | 97 | if pspec.name == 'discharging': |
| 81 | 98 | return self._discharging |
| | 99 | if pspec.name == 'present': |
| | 100 | return self._present |
| 82 | 101 | |
| 83 | 102 | def get_type(self): |
| 84 | 103 | return 'battery' |
| … |
… |
|
| 94 | 113 | elif change[0] == _DISCHARGING_PROP: |
| 95 | 114 | self._discharging = self._get_discharging() |
| 96 | 115 | self.notify('discharging') |
| | 116 | elif change[0] == _PRESENT_PROP: |
| | 117 | self._present = self._get_present() |
| | 118 | self.notify('present') |
diff -urN sugar/shell/view/devices/battery.py NEWsugar/shell/view/devices/battery.py
|
old
|
new
|
|
| 29 | 29 | _STATUS_CHARGING = 0 |
| 30 | 30 | _STATUS_DISCHARGING = 1 |
| 31 | 31 | _STATUS_FULLY_CHARGED = 2 |
| | 32 | _STATUS_NOT_PRESENT = 3 |
| 32 | 33 | |
| 33 | 34 | class DeviceView(CanvasIcon): |
| 34 | 35 | def __init__(self, model): |
| … |
… |
|
| 41 | 42 | model.connect('notify::level', self._battery_status_changed_cb) |
| 42 | 43 | model.connect('notify::charging', self._battery_status_changed_cb) |
| 43 | 44 | model.connect('notify::discharging', self._battery_status_changed_cb) |
| | 45 | model.connect('notify::present', self._battery_status_changed_cb) |
| 44 | 46 | self._update_info() |
| 45 | 47 | |
| 46 | 48 | def _update_info(self): |
| … |
… |
|
| 48 | 50 | self.props.icon_name = name |
| 49 | 51 | |
| 50 | 52 | # Update palette |
| 51 | | if self._model.props.charging: |
| | 53 | if not self._model.props.present: |
| | 54 | status = _STATUS_NOT_PRESENT |
| | 55 | self.props.badge_name = None |
| | 56 | elif self._model.props.charging: |
| 52 | 57 | status = _STATUS_CHARGING |
| 53 | 58 | self.props.badge_name = 'emblem-charging' |
| 54 | 59 | elif self._model.props.discharging: |
| … |
… |
|
| 96 | 101 | charge_text = _('Battery discharging') + percent_string |
| 97 | 102 | elif status == _STATUS_FULLY_CHARGED: |
| 98 | 103 | charge_text = _('Battery fully charged') |
| | 104 | elif status == _STATUS_NOT_PRESENT: |
| | 105 | charge_text = _('Battery not present') |
| 99 | 106 | |
| 100 | 107 | self._status_label.set_text(charge_text) |