Ticket #1759: 0001-Showing-Errors-Pallete-Mockup-V4.patch
File 0001-Showing-Errors-Pallete-Mockup-V4.patch, 16.6 KB (added by Dcastelo, 14 years ago) |
---|
-
extensions/deviceicon/network.py
From a9172970939c6a94456031652a2d1dae4555b2c2 Mon Sep 17 00:00:00 2001 From: latu <latu@localhost.localdomain> Date: Tue, 9 Mar 2010 16:40:33 -0200 Subject: [PATCH] Showing Errors Pallete Mockup V4 --- extensions/deviceicon/network.py | 183 ++++++++++++++++++++++++++------------ src/jarabe/model/network.py | 34 +++++--- 2 files changed, 148 insertions(+), 69 deletions(-) diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py index 94a4293..995446c 100644
a b from sugar.graphics.tray import TrayIcon 39 39 from sugar.graphics import xocolor 40 40 from sugar.util import unique_id 41 41 from sugar import profile 42 from sugar.graphics.icon import Icon 43 from sugar.graphics.menuitem import MenuItem 42 44 43 45 from jarabe.model import network 44 46 from jarabe.model.network import Settings … … _GSM_STATE_NOT_READY = 0 63 65 _GSM_STATE_DISCONNECTED = 1 64 66 _GSM_STATE_CONNECTING = 2 65 67 _GSM_STATE_CONNECTED = 3 66 _GSM_STATE_ NEED_AUTH= 468 _GSM_STATE_FAILED = 4 67 69 68 70 def frequency_to_channel(frequency): 69 71 ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4, … … class WiredPalette(Palette): 214 216 ip_address_text = "" 215 217 self._ip_address_label.set_text(ip_address_text) 216 218 219 217 220 class GsmPalette(Palette): 218 221 __gtype_name__ = 'SugarGsmPalette' 219 222 … … class GsmPalette(Palette): 227 230 def __init__(self): 228 231 229 232 Palette.__init__(self, label=_('Wireless modem')) 230 231 233 self._current_state = None 234 self._alert = False 232 235 233 self._toggle_state_item = gtk.MenuItem('')236 self._toggle_state_item = MenuItem('') 234 237 self._toggle_state_item.connect('activate', self.__toggle_state_cb) 235 238 self.menu.append(self._toggle_state_item) 236 239 self._toggle_state_item.show() 237 240 238 self.set_state(_GSM_STATE_NOT_READY)239 240 241 self.info_box = gtk.VBox() 241 242 self.data_label = gtk.Label() 243 self.data_label.props.xalign = 0.0 244 label_alignment = self._add_widget_with_padding(self.data_label) 245 self.info_box.pack_start(label_alignment) 246 self.data_label.show() 242 self.connection_info_box = gtk.HBox() 243 244 icon = Icon(icon_name='data-upload', icon_size=gtk.ICON_SIZE_MENU) 245 self.connection_info_box.pack_start(icon) 246 icon.show() 247 self._data_label_up = gtk.Label() 248 self._data_label_up.props.xalign = 0.0 249 label_alignment = self._add_widget_with_padding(self._data_label_up) 250 self.connection_info_box.pack_start(label_alignment) 251 self._data_label_up.show() 247 252 label_alignment.show() 248 253 249 self.connection_time_label = gtk.Label() 250 self.connection_time_label.props.xalign = 0.0 251 label_alignment = self._add_widget_with_padding( \ 252 self.connection_time_label) 253 self.info_box.pack_start(label_alignment) 254 self.connection_time_label.show() 254 icon = Icon(icon_name='data-download', icon_size=gtk.ICON_SIZE_MENU) 255 self.connection_info_box.pack_start(icon) 256 icon.show() 257 self._data_label_down = gtk.Label() 258 self._data_label_down.props.xalign = 0.0 259 label_alignment = self._add_widget_with_padding(self._data_label_down) 260 self.connection_info_box.pack_start(label_alignment) 261 self._data_label_down.show() 255 262 label_alignment.show() 263 264 self.info_box.pack_start(self.connection_info_box) 256 265 266 self._error_accept_item = MenuItem('') 267 self._error_accept_item.connect('activate', self.__error_accept_cb) 268 self.menu.append(self._error_accept_item) 269 257 270 self.info_box.show() 258 271 self.set_content(self.info_box) 259 272 273 self.set_state(_GSM_STATE_NOT_READY) 274 260 275 def _add_widget_with_padding(self, child, xalign=0, yalign=0.5): 261 276 alignment = gtk.Alignment(xalign=xalign, yalign=yalign, 262 277 xscale=1, yscale=0.33) … … class GsmPalette(Palette): 267 282 alignment.add(child) 268 283 return alignment 269 284 270 def set_state(self, state ):285 def set_state(self, state, reason=0): 271 286 self._current_state = state 272 self._update_label_and_text( )287 self._update_label_and_text(reason) 273 288 274 def _update_label_and_text(self): 289 def _update_label_and_text(self, reason=0): 290 275 291 if self._current_state == _GSM_STATE_NOT_READY: 276 292 self._toggle_state_item.get_child().set_label('...') 277 293 self.props.secondary_text = _('Please wait...') 278 294 279 295 elif self._current_state == _GSM_STATE_DISCONNECTED: 280 296 self._toggle_state_item.get_child().set_label(_('Connect')) 281 self.props.secondary_text = _('Disconnected') 282 297 if not self._alert: 298 self.props.secondary_text = _('Disconnected') 299 icon = Icon(icon_name='dialog-ok', \ 300 icon_size=gtk.ICON_SIZE_MENU) 301 self._toggle_state_item.set_image(icon) 302 283 303 elif self._current_state == _GSM_STATE_CONNECTING: 284 304 self._toggle_state_item.get_child().set_label(_('Cancel')) 285 305 self.props.secondary_text = _('Connecting...') 306 icon = Icon(icon_name='dialog-cancel', \ 307 icon_size=gtk.ICON_SIZE_MENU) 308 self._toggle_state_item.set_image(icon) 286 309 287 310 elif self._current_state == _GSM_STATE_CONNECTED: 288 311 self._toggle_state_item.get_child().set_label(_('Disconnect')) 289 self.props.secondary_text = _('Connected') 290 291 elif self._current_state == _GSM_STATE_NEED_AUTH: 292 self._toggle_state_item.get_child().set_label(_('Sim requires Pin/Puk')) 293 self.props.secondary_text = _('Authentication Error') 312 self.update_connection_time() 313 icon = Icon(icon_name='media-eject', \ 314 icon_size=gtk.ICON_SIZE_MENU) 315 self._toggle_state_item.set_image(icon) 316 317 elif self._current_state == _GSM_STATE_FAILED: 318 self.add_alert(_('Connection Error'), \ 319 self._get_error_by_nm_reason(reason)) 294 320 295 321 else: 296 322 raise ValueError('Invalid GSM state while updating label and ' \ 297 323 'text, %s' % str(self._current_state)) 298 324 325 def add_alert(self, title, message): 326 self._alert = True 327 self.props.secondary_text = title 328 self._error_accept_item.get_child().set_label(message) 329 self._error_accept_item.show() 330 self._toggle_state_item.set_sensitive(False) 331 332 333 def __error_accept_cb(self, alert): 334 self._alert = False 335 self._update_label_and_text() 336 self._error_accept_item.get_child().set_label('') 337 self._error_accept_item.hide() 338 self._toggle_state_item.set_sensitive(True) 339 self._full_request = [0, 0] 340 341 def update_connection_time(self, connection_time=None): 342 if (connection_time is not None): 343 self.props.secondary_text = _('Connected for ' + \ 344 connection_time.strftime('%H:%M:%S')) 345 else: 346 self.props.secondary_text = _('Connected for ' \ 347 + '00:00:00') 348 349 def update_stats(self, in_bytes, out_bytes): 350 in_KBytes = in_bytes / 1024 351 out_KBytes = out_bytes / 1024 352 self._data_label_up.set_text(_("%d KB") % (out_KBytes)) 353 self._data_label_down.set_text(_("%d KB") % (in_KBytes)) 354 355 def _get_error_by_nm_reason(self, reason): 356 if reason in [network.NM_DEVICE_STATE_REASON_NO_SECRETS, network.NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED]: 357 message = _('The Pin/Puk configuration is not valid.') 358 elif reason in [network.NM_DEVICE_STATE_REASON_PPP_DISCONNECT, network.NM_DEVICE_STATE_REASON_PPP_FAILED]: 359 message = _('Check the APN configuration.') 360 elif reason in [network.NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER]: 361 message = _('Check the tel number configuration.') 362 elif reason in [network.NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT]: 363 message = _('Time out. Check the tel configuration') 364 else: 365 message = _('Unexpected error.') 366 return message 367 299 368 def __toggle_state_cb(self, menuitem): 300 369 if self._current_state == _GSM_STATE_NOT_READY: 301 370 pass … … class GsmPalette(Palette): 305 374 self.emit('gsm-disconnect') 306 375 elif self._current_state == _GSM_STATE_CONNECTED: 307 376 self.emit('gsm-disconnect') 308 elif self._current_state == _GSM_STATE_NEED_AUTH:309 self.emit('gsm-disconnect')310 377 else: 311 378 raise ValueError('Invalid GSM state while emitting signal, %s' % \ 312 379 str(self._current_state)) 313 380 314 381 315 382 class WirelessDeviceView(ToolButton): 316 383 … … class GsmDeviceView(TrayIcon): 747 814 signal_name='PppStats', 748 815 path=self._device.object_path, 749 816 dbus_interface=_NM_SERIAL_IFACE) 817 750 818 def create_palette(self): 751 819 palette = GsmPalette() 752 820 … … class GsmDeviceView(TrayIcon): 774 842 '/', 775 843 reply_handler=self.__connect_cb, 776 844 error_handler=self.__connect_error_cb) 845 else: 846 self._palette.add_alert(_('Connection Error'), \ 847 _('There is no gsm connection available')) 777 848 778 849 def __connect_cb(self, active_connection): 779 850 logging.debug('Connected successfully to gsm device, %s', … … class GsmDeviceView(TrayIcon): 807 878 808 879 def __state_changed_cb(self, new_state, old_state, reason): 809 880 logging.debug('State: %s to %s, reason %s', old_state, new_state, reason) 810 self._update_state(int(new_state) )881 self._update_state(int(new_state), int(old_state), int(reason)) 811 882 812 883 def __current_state_check_cb(self, properties): 813 self._update_state(int(properties['State']) )884 self._update_state(int(properties['State']), 0, 0) 814 885 815 886 def __current_state_check_error_cb(self, error): 816 887 raise RuntimeError('Error when checking gsm device state, %s' % error) 817 888 818 def _update_state(self, state ):889 def _update_state(self, state, old_state, reason): 819 890 gsm_state = None 820 891 821 892 if state is network.DEVICE_STATE_ACTIVATED: … … class GsmDeviceView(TrayIcon): 823 894 connection = network.find_gsm_connection() 824 895 if connection is not None: 825 896 connection.set_connected() 826 self._connection_timestamp = 897 self._connection_timestamp = time.time() - \ 827 898 connection.get_settings().connection.timestamp 828 899 self._connection_time_handler = gobject.timeout_add_seconds( \ 829 900 1, self.__connection_timecount_cb) 830 self._update_stats(0, 0) 831 self._update_connection_time() 832 self._palette.info_box.show() 901 self._palette.update_connection_time() 902 self._palette.update_stats(0, 0) 903 if self._palette is not None: 904 self._palette.connection_info_box.show() 833 905 834 906 elif state is network.DEVICE_STATE_DISCONNECTED: 835 907 gsm_state = _GSM_STATE_DISCONNECTED 836 908 self._connection_timestamp = 0 837 909 if self._connection_time_handler is not None: 838 910 gobject.source_remove(self._connection_time_handler) 839 self._palette.info_box.hide() 911 if self._palette is not None: 912 self._palette.connection_info_box.hide() 840 913 841 914 elif state in [network.DEVICE_STATE_UNMANAGED, 842 915 network.DEVICE_STATE_UNAVAILABLE, … … class GsmDeviceView(TrayIcon): 845 918 846 919 elif state in [network.DEVICE_STATE_PREPARE, 847 920 network.DEVICE_STATE_CONFIG, 848 network.DEVICE_STATE_IP_CONFIG]: 921 network.DEVICE_STATE_IP_CONFIG, 922 network.DEVICE_STATE_NEED_AUTH]: 849 923 gsm_state = _GSM_STATE_CONNECTING 850 851 elif state in [network.DEVICE_STATE_NEED_AUTH]:852 gsm_state = _GSM_STATE_ NEED_AUTH924 925 elif state == network.DEVICE_STATE_FAILED: 926 gsm_state = _GSM_STATE_FAILED 853 927 854 928 if self._palette is not None: 855 self._palette.set_state(gsm_state )929 self._palette.set_state(gsm_state, reason) 856 930 857 931 def disconnect(self): 858 932 self._bus.remove_signal_receiver(self.__state_changed_cb, … … class GsmDeviceView(TrayIcon): 861 935 dbus_interface=_NM_DEVICE_IFACE) 862 936 863 937 def __ppp_stats_changed_cb(self, in_bytes, out_bytes): 864 self._update_stats(in_bytes, out_bytes) 865 866 def _update_stats(self, in_bytes, out_bytes): 867 in_KBytes = in_bytes / 1024 868 out_KBytes = out_bytes / 1024 869 text = _("Data sent %d KB / received %d KB") % (out_KBytes, in_KBytes) 870 self._palette.data_label.set_text(text) 938 self._palette.update_stats(in_bytes, out_bytes) 871 939 872 940 def __connection_timecount_cb(self): 873 941 self._connection_timestamp = self._connection_timestamp + 1 874 self._update_connection_time() 942 connection_time = \ 943 datetime.datetime.fromtimestamp(self._connection_timestamp) 944 self._palette.update_connection_time(connection_time) 875 945 return True 876 946 877 def _update_connection_time(self):878 connection_time = datetime.datetime.fromtimestamp( \879 self._connection_timestamp)880 text = _("Connection time ") + connection_time.strftime('%H : %M : %S')881 self._palette.connection_time_label.set_text(text)882 947 948 883 949 class WirelessDeviceObserver(object): 884 950 def __init__(self, device, tray, device_type): 885 951 self._device = device … … class WiredDeviceObserver(object): 950 1016 del self._device_view 951 1017 self._device_view = None 952 1018 1019 953 1020 class GsmDeviceObserver(object): 954 1021 def __init__(self, device, tray): 955 1022 self._device = device -
src/jarabe/model/network.py
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py index 3a949da..579ed8d 100644
a b NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0 54 54 NM_ACTIVE_CONNECTION_STATE_ACTIVATING = 1 55 55 NM_ACTIVE_CONNECTION_STATE_ACTIVATED = 2 56 56 57 NM_DEVICE_STATE_REASON_NO_SECRETS = 7 58 NM_DEVICE_STATE_REASON_PPP_DISCONNECT = 13 59 NM_DEVICE_STATE_REASON_PPP_FAILED = 14 60 NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER = 25 61 NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT = 26 62 NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED = 34 63 57 64 NM_802_11_AP_FLAGS_NONE = 0x00000000 58 65 NM_802_11_AP_FLAGS_PRIVACY = 0x00000001 59 66 … … class NMSettingsConnection(dbus.service.Object): 444 451 def GetSecrets(self, setting_name, hints, request_new, reply, error): 445 452 logging.debug('Secrets requested for connection %s request_new=%s', 446 453 self.path, request_new) 447 if request_new or self._secrets is None: 448 # request_new is for example the case when the pw on the AP changes 449 response = SecretsResponse(self, reply, error) 450 try: 451 self.secrets_request.send(self, response=response) 452 except Exception: 453 logging.exception('Error requesting the secrets via dialog') 454 else: 455 reply(self._secrets.get_dict()) 456 457 454 if self._settings.connection.type is not 'gsm': 455 if request_new or self._secrets is None: 456 # request_new is for example the case when the pw on the AP changes 457 response = SecretsResponse(self, reply, error) 458 try: 459 self.secrets_request.send(self, response=response) 460 except Exception: 461 logging.exception('Error requesting the secrets via dialog') 462 else: 463 reply(self._secrets.get_dict()) 464 else: 465 if not request_new: 466 reply(self._secrets.get_dict()) 467 else: 468 raise Exception('The stored GSM secret has already been supplied ') 469 458 470 class AccessPoint(gobject.GObject): 459 471 __gsignals__ = { 460 472 'props-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,