diff options
author | Fran Rogers <fran@dumetella.net> | 2011-05-12 07:31:23 (GMT) |
---|---|---|
committer | Fran Rogers <fran@dumetella.net> | 2011-05-12 07:31:23 (GMT) |
commit | 2504bd40427a465e1c181a9370f74446df04b2dd (patch) | |
tree | 472a2a024f8bbd50f5f568e3786681a3fa6824d0 | |
parent | 1bb0cbe6847e7bd8544ba4090a9866cd8e2689c7 (diff) |
Added rudimentary error dialogs
-rw-r--r-- | vnc.py | 103 |
1 files changed, 86 insertions, 17 deletions
@@ -51,6 +51,7 @@ class VNCActivity(activity.Activity): self.max_participants = 1 + self._vnc = None self.host = None self.password = None @@ -108,13 +109,17 @@ class VNCActivity(activity.Activity): self.set_canvas(self._vnc) def __vnc_connected_cb(self, widget): - pass # TODO + self.connected = True # TODO def __vnc_initialized_cb(self, widget): pass # TODO def __vnc_disconnected_cb(self, widget): - pass # TODO + if self.connected: + self.connected = False + self.show_error(_("Disconnected")) + else: + self.show_error(_("Unable to connect to %s") % (self.host,)) def __vnc_auth_credential(self, widget, creds): if creds == [gtkvnc.CREDENTIAL_PASSWORD]: @@ -128,15 +133,17 @@ class VNCActivity(activity.Activity): self.set_canvas(self._password_dialog) self._password_dialog.grab_focus() - def __vnc_auth_failure(self, widget): - pass # TODO + def __vnc_auth_failure(self, widget, error): + self.show_error("Authentication failure: %s" % (error,)) - def __vnc_auth_unsupported(self, widget): - pass # TODO + def __vnc_auth_unsupported(self, widget, error_code): + self.show_error("Authentication method not supported: %s" % + (str(error_code),)) def vnc_connect(self, host, password=None): self.host = host self.password = password + self.connected = False if ':' in host: colon = host.rindex(':') @@ -145,7 +152,7 @@ class VNCActivity(activity.Activity): try: display = int(host[colon+1:]) except: - return # TODO + hostname = host if hostname == "": hostname = "127.0.0.1" else: @@ -165,6 +172,8 @@ class VNCActivity(activity.Activity): self._vnc.open_host(hostname, str(5900 + display)) def show_connect_dialog(self): + if self._vnc != None: + self._vnc.close() self._vnc = None self._connect_dialog = VNCActivityConnectDialog() self._connect_dialog.connect('activated', self.__connect_clicked_cb) @@ -172,6 +181,19 @@ class VNCActivity(activity.Activity): self.set_canvas(self._connect_dialog) self._connect_dialog.grab_focus() + def __error_back_cb(self, widget): + self.show_connect_dialog() + + def show_error(self, message): + if self._vnc != None: + self._vnc.close() + self._vnc = None + self._error_dialog = VNCActivityErrorDialog(message) + self._error_dialog.connect('activated', self.__error_back_cb) + self._error_dialog.show() + self.set_canvas(self._error_dialog) + self._error_dialog.grab_focus() + def read_file(self, file_path): if self.metadata['mime_type'] != 'text/plain': return @@ -230,11 +252,12 @@ class VNCActivityConnectDialog(hippo.Canvas): root_box.append(opts_box, hippo.PACK_EXPAND) button_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL) + connect_canvas_button = hippo.CanvasButton(text=_('Connect')) + self._connect_button = connect_canvas_button.props.widget + self._connect_button.set_image(Icon(icon_name='go-right')) + connect_canvas_button.connect('activated', self._activated_cb) button_box.append(hippo.CanvasBox(), hippo.PACK_EXPAND) - self._connect_button = hippo.CanvasButton(text=_('Connect')) - self._connect_button.props.widget.set_image(Icon(icon_name='go-right')) - self._connect_button.connect('activated', self._connect_activated_cb) - button_box.append(self._connect_button) + button_box.append(connect_canvas_button) root_box.append(button_box) self.set_root(root_box) @@ -253,7 +276,7 @@ class VNCActivityConnectDialog(hippo.Canvas): self.activate() return True - def _connect_activated_cb(self, item): + def _activated_cb(self, item): self.activate() def activate(self): @@ -289,11 +312,12 @@ class VNCActivityPasswordDialog(hippo.Canvas): root_box.append(opts_box, hippo.PACK_EXPAND) button_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL) + next_canvas_button = hippo.CanvasButton(text=_('Continue')) + self._next_button = next_canvas_button.props.widget + self._next_button.set_image(Icon(icon_name='go-right')) + next_canvas_button.connect('activated', self._activated_cb) button_box.append(hippo.CanvasBox(), hippo.PACK_EXPAND) - self._connect_button = hippo.CanvasButton(text=_('Continue')) - self._connect_button.props.widget.set_image(Icon(icon_name='go-right')) - self._connect_button.connect('activated', self._connect_activated_cb) - button_box.append(self._connect_button) + button_box.append(next_canvas_button) root_box.append(button_box) self.set_root(root_box) @@ -312,7 +336,52 @@ class VNCActivityPasswordDialog(hippo.Canvas): self.activate() return True - def _connect_activated_cb(self, item): + def _activated_cb(self, item): + self.activate() + + def activate(self): + self.emit('activated') + + +class VNCActivityErrorDialog(hippo.Canvas): + __gsignals__ = { + 'activated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (),) + } + + def __init__(self, message): + hippo.Canvas.__init__(self) + self.connect('key-press-event', self.__key_press_cb) + + root_box = hippo.CanvasBox(padding=style.zoom(30), + background_color=_BACKGROUND_COLOR.get_int()) + + opts_box = hippo.CanvasBox(xalign=hippo.ALIGNMENT_CENTER, + background_color=_BACKGROUND_COLOR.get_int(), + spacing=style.DEFAULT_SPACING, + orientation=hippo.ORIENTATION_HORIZONTAL,) + label = hippo.CanvasText(text=message) + opts_box.append(label) + root_box.append(opts_box, hippo.PACK_EXPAND) + + button_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL) + back_canvas_button = hippo.CanvasButton(text=_('Back')) + self._back_button = back_canvas_button.props.widget + self._back_button.set_image(Icon(icon_name='go-left')) + back_canvas_button.connect('activated', self._activated_cb) + button_box.append(back_canvas_button) + root_box.append(button_box) + + self.set_root(root_box) + + def grab_focus(self): + self._back_button.grab_focus() + + def __key_press_cb(self, widget, event): + if gtk.gdk.keyval_name(event.keyval) == "Return": + self.activate() + return True + + def _activated_cb(self, item): self.activate() def activate(self): |