Exemplo n.º 1
0
class SetWifi(Template):
    wifi_connection_attempted = False

    def __init__(self, win):

        Template.__init__(self, "", _("to be set"), _("COMPLETE"))

        self.win = win
        self.win.set_main_widget(self)

        self.kano_button.connect('button-release-event', self.win.go_to_home)

        internet_img = Gtk.Image()

        # Very hacky way to centre the Proxy button - put spaces in the label
        self.proxy_button = OrangeButton(_("Proxy  "))
        self.proxy_button.connect('button-release-event', self.go_to_proxy)
        self.disable_proxy = OrangeButton(_("Disable proxy"))

        self.win.change_prev_callback(self.win.go_to_home)
        self.win.top_bar.enable_prev()

        internet_status = Gtk.Label()
        internet_status_style = internet_status.get_style_context()
        internet_status.set_alignment(xalign=1, yalign=0.5)

        internet_action = Gtk.Label()
        internet_action_style = internet_action.get_style_context()
        internet_status_style.add_class('internet_status_top')
        internet_action_style.add_class('internet_status_bottom')
        internet_action.set_alignment(xalign=1, yalign=0.5)

        status_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
        status_box.props.valign = Gtk.Align.CENTER

        configure_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)

        container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
        container.pack_start(status_box, False, False, 2)
        container.pack_start(internet_img, False, False, 2)
        self.box.pack_start(container, False, False, 0)

        network_info_dict = network_info()
        common.has_internet = is_internet()

        if not common.has_internet or not network_info_dict:
            if network_info_dict:
                description = _("Use the browser to log in or configure proxy")
            else:
                description = _("Configure wireless")

            title = _("Get connected")

            self.add_connection = KanoButton(_("WIFI"))
            self.add_connection.connect('button_release_event', self.configure_wifi)
            # We removed the ability to use keyboard to click, so we also remove ability
            # to get keyboard focus
            self.add_connection.set_can_focus(False)

            # For now, this is removed as the event listener is interefering with the
            # kano-connect
            #self.add_connection.connect("key_release_event", self.configure_wifi)

            status_box.pack_start(self.add_connection, False, False, 0)
            internet_img.set_from_file(common.media + "/Graphics/Internet-noConnection.png")
            internet_status.set_text(_("No network found"))
            self.kano_button.set_label(_("BACK"))

            status_box.pack_start(configure_container, False, False, 3)

            go_to_portal_button = OrangeButton(_("Browser Login"))
            go_to_portal_button.connect('button-press-event', self.cb_launch_browser)
            configure_container.pack_start(go_to_portal_button, False, False, 0)

            divider_label = Gtk.Label("|")
            configure_container.pack_start(divider_label, False, False, 3)

            configure_container.pack_end(self.proxy_button, False, False, 0)

        else:
            self.kano_button.set_label(_("COMPLETE"))

            status_box.pack_start(internet_status, False, False, 3)
            status_box.pack_start(internet_action, False, False, 3)
            status_box.pack_start(configure_container, False, False, 3)

            network = network_info_dict.keys()[0]
            ip = network_info_dict[network]['address']
            network_text = network_info_dict[network]['nice_name']

            internet_img.set_from_file(common.media + "/Graphics/Internet-Connection.png")

            internet_status.set_text(network_text)
            internet_action.set_text(ip)

            go_to_portal_button = OrangeButton(_("Browser Login"))
            go_to_portal_button.connect('button-press-event', self.cb_launch_browser)
            configure_container.pack_start(go_to_portal_button, False, False, 0)

            if network_text == 'Ethernet':
                title = _("Connection found!")
                description = _("You're on a wired network")
                # Change to ethernet image here
                internet_img.set_from_file(common.media + "/Graphics/Internet-ethernetConnection.png")

            else:
                title = _("Connection found!")
                description = _("You're on a wireless network")

                divider_label = Gtk.Label("|")
                configure_container.pack_start(divider_label, False, False, 3)

                configure_button = OrangeButton(_("Configure"))
                configure_button.connect('button_press_event', self.configure_wifi)
                configure_container.pack_start(configure_button, False, False, 0)

            divider_label = Gtk.Label("|")
            configure_container.pack_start(divider_label, False, False, 3)
            configure_container.pack_end(self.proxy_button, False, False, 0)

        self.title.title.set_text(title)
        self.title.description.set_text(description)
        self.win.show_all()

    def cb_launch_browser(self, control, signal):
        # start the default browser to visit the default page
        launch_browser()

    def go_to_proxy(self, widget, event):
        self.win.clear_win()
        SetProxy(self.win)

    def configure_wifi(self, widget=None, event=None):
        # If is a mouse click event or key pressed is ENTER
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:
            self.kano_button.set_sensitive(True)
            self.wifi_connection_attempted = True

            # Blur window
            self.win.blur()
            self.win.show_all()

            # Force blur to be shown
            while Gtk.events_pending():
                Gtk.main_iteration()

            # Call WiFi config
            os.system('/usr/bin/kano-wifi-gui')

            # Refresh window after WiFi Setup
            self.win.unblur()
            self.win.clear_win()
            SetWifi(self.win)
Exemplo n.º 2
0
class SetWifi(Template):
    wifi_connection_attempted = False

    def __init__(self, win):

        Template.__init__(self, "", _("to be set"), _("COMPLETE"))

        self.win = win
        self.win.set_main_widget(self)

        self.kano_button.connect('button-release-event', self.win.go_to_home)

        internet_img = Gtk.Image()

        # Very hacky way to centre the Proxy button - put spaces in the label
        self.proxy_button = OrangeButton(_("Proxy  "))
        self.proxy_button.connect('button-release-event', self.go_to_proxy)
        self.disable_proxy = OrangeButton(_("Disable proxy"))

        self.win.change_prev_callback(self.win.go_to_home)
        self.win.top_bar.enable_prev()

        internet_status = Gtk.Label()
        internet_status_style = internet_status.get_style_context()
        internet_status.set_alignment(xalign=1, yalign=0.5)

        internet_action = Gtk.Label()
        internet_action_style = internet_action.get_style_context()
        internet_status_style.add_class('internet_status_top')
        internet_action_style.add_class('internet_status_bottom')
        internet_action.set_alignment(xalign=1, yalign=0.5)

        status_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
        status_box.props.valign = Gtk.Align.CENTER

        configure_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                                      spacing=0)

        container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
        container.pack_start(status_box, False, False, 2)
        container.pack_start(internet_img, False, False, 2)
        self.box.pack_start(container, False, False, 0)

        network_info_dict = network_info()
        common.has_internet = is_internet()

        if not common.has_internet or not network_info_dict:
            if network_info_dict:
                description = _("Use the browser to log in or configure proxy")
            else:
                description = _("Configure wireless")

            title = _("Get connected")

            self.add_connection = KanoButton(_("WIFI"))
            self.add_connection.connect('button_release_event',
                                        self.configure_wifi)
            # We removed the ability to use keyboard to click, so we also remove ability
            # to get keyboard focus
            self.add_connection.set_can_focus(False)

            # For now, this is removed as the event listener is interefering with the
            # kano-connect
            #self.add_connection.connect("key_release_event", self.configure_wifi)

            status_box.pack_start(self.add_connection, False, False, 0)
            internet_img.set_from_file(common.media +
                                       "/Graphics/Internet-noConnection.png")
            internet_status.set_text(_("No network found"))
            self.kano_button.set_label(_("BACK"))

            status_box.pack_start(configure_container, False, False, 3)

            go_to_portal_button = OrangeButton(_("Browser Login"))
            go_to_portal_button.connect('button-press-event',
                                        self.cb_launch_browser)
            configure_container.pack_start(go_to_portal_button, False, False,
                                           0)

            divider_label = Gtk.Label("|")
            configure_container.pack_start(divider_label, False, False, 3)

            configure_container.pack_end(self.proxy_button, False, False, 0)

        else:
            self.kano_button.set_label(_("COMPLETE"))

            status_box.pack_start(internet_status, False, False, 3)
            status_box.pack_start(internet_action, False, False, 3)
            status_box.pack_start(configure_container, False, False, 3)

            network = network_info_dict.keys()[0]
            ip = network_info_dict[network]['address']
            network_text = network_info_dict[network]['nice_name']

            internet_img.set_from_file(common.media +
                                       "/Graphics/Internet-Connection.png")

            internet_status.set_text(network_text)
            internet_action.set_text(ip)

            go_to_portal_button = OrangeButton(_("Browser Login"))
            go_to_portal_button.connect('button-press-event',
                                        self.cb_launch_browser)
            configure_container.pack_start(go_to_portal_button, False, False,
                                           0)

            if network_text == 'Ethernet':
                title = _("Connection found!")
                description = _("You're on a wired network")
                # Change to ethernet image here
                internet_img.set_from_file(
                    common.media + "/Graphics/Internet-ethernetConnection.png")

            else:
                title = _("Connection found!")
                description = _("You're on a wireless network")

                divider_label = Gtk.Label("|")
                configure_container.pack_start(divider_label, False, False, 3)

                configure_button = OrangeButton(_("Configure"))
                configure_button.connect('button_press_event',
                                         self.configure_wifi)
                configure_container.pack_start(configure_button, False, False,
                                               0)

            divider_label = Gtk.Label("|")
            configure_container.pack_start(divider_label, False, False, 3)
            configure_container.pack_end(self.proxy_button, False, False, 0)

        self.title.title.set_text(title)
        self.title.description.set_text(description)
        self.win.show_all()

    def cb_launch_browser(self, control, signal):
        # start the default browser to visit the default page
        launch_browser()

    def go_to_proxy(self, widget, event):
        self.win.clear_win()
        SetProxy(self.win)

    def configure_wifi(self, widget=None, event=None):
        # If is a mouse click event or key pressed is ENTER
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:
            self.kano_button.set_sensitive(True)
            self.wifi_connection_attempted = True

            # Blur window
            self.win.blur()
            self.win.show_all()

            # Force blur to be shown
            while Gtk.events_pending():
                Gtk.main_iteration()

            # Call WiFi config
            os.system('/usr/bin/kano-wifi-gui')

            # Refresh window after WiFi Setup
            self.win.unblur()
            self.win.clear_win()
            SetWifi(self.win)