Esempio n. 1
0
class GreeterWindow(ApplicationWindow):
    WIDTH = 400
    HEIGHT = -1

    greeter = LightDM.Greeter

    def __init__(self):
        apply_common_to_screen()

        self.a = self.b = self.c = 0
        self.switching = 0

        ApplicationWindow.__init__(self, _('Login'), self.WIDTH, self.HEIGHT)
        self.connect("delete-event", Gtk.main_quit)

        # Create a new LightDM.Greeter instance which will be used by the 2 views
        self.greeter = GreeterWindow.greeter.new()

        # Create the two views: one for normal Login, the other to create a new account
        self.password_view = PasswordView(None, self.greeter)
        self.newuser_view = NewUserView(self.greeter)
        self.login_with_kw_view = LoginWithKanoWorldView(self.greeter)

        self.grid = Gtk.Grid()
        self.set_main_widget(self.grid)

        self.grid.set_column_spacing(30)
        self.grid.set_row_spacing(30)

        self.top_bar = TopBar(_('Login'))
        self._remove_top_bar_buttons()
        self.top_bar.set_size_request(self.WIDTH, -1)
        self.grid.attach(self.top_bar, 0, 0, 3, 1)

        self.grid.attach(Gtk.Label(), 0, 3, 3, 1)

        self.top_bar.set_prev_callback(self._back_cb)

        self.user_list = UserListView()

        self.go_to_users()

        cursor = Gdk.Cursor.new(Gdk.CursorType.ARROW)
        self.get_root_window().set_cursor(cursor)

    def _remove_top_bar_buttons(self):
        self.top_bar.box.remove(self.top_bar.close_button)
        self.top_bar.box.remove(self.top_bar.next_button)

    def set_main(self, wdg):
        child = self.grid.get_child_at(1, 1)
        if child:
            self.grid.remove(child)

        self.grid.attach(wdg, 1, 1, 1, 1)
        self.show_all()

    def go_to_users(self):
        self.set_main(self.user_list)
        self.top_bar.disable_prev()

    def go_to_password(self, user):
        self.set_main(self.password_view)
        self.top_bar.enable_prev()

        if not self.switching == 1:
            self.greeter.disconnect(self.a)
            self.greeter.disconnect(self.b)
            self.greeter.disconnect(self.c)

            self.greeter = GreeterWindow.greeter.new()
            self.password_view.greeter = self.greeter
            (self.a, self.b, self.c) = self.password_view._reset_greeter()
            self.switching = 1

        self.password_view.grab_focus(user)

    def go_to_newuser(self):
        self.set_main(self.newuser_view)
        self.top_bar.enable_prev()

        if not self.switching == 2:
            self.greeter.disconnect(self.a)
            self.greeter.disconnect(self.b)
            self.greeter.disconnect(self.c)

            self.greeter = GreeterWindow.greeter.new()
            self.newuser_view.greeter = self.greeter

            # FIXME: We do not reset the greeter in the newuser view
            # It will be done only when the local user account has been forced
            # so as to avoid LightDM freezes
            # (self.a, self.b, self.c) = self.newuser_view._reset_greeter()
            self.switching = 2

    def go_to_login_with_kw(self):
        self.set_main(self.login_with_kw_view)
        self.top_bar.enable_prev()

        if not self.switching == 3:
            self.greeter.disconnect(self.a)
            self.greeter.disconnect(self.b)
            self.greeter.disconnect(self.c)

            self.greeter = GreeterWindow.greeter.new()
            self.login_with_kw_view.greeter = self.greeter

            # FIXME: We do not reset the greeter in the newuser view
            # It will be done only when the local user account has been forced
            # so as to avoid LightDM freezes
            # (self.a, self.b, self.c) = self.login_with_kw_view._reset_greeter()
            self.switching = 3

        self.login_with_kw_view.grab_focus()

    def _back_cb(self, event, button):
        self.go_to_users()
Esempio n. 2
0
    class KanoWifiGui(base_class):

        CSS_PATH = os.path.join(css_dir, 'kano_wifi_gui.css')
        width = 350
        height = 450

        def __init__(self, wiface='wlan0', socket_id=0, no_confirm_ether=False):

            self.wiface = wiface
            self.network_list = []
            self.no_confirm_ether = no_confirm_ether

            # Default basic styling
            apply_common_to_screen()

            # Attach specific styling
            apply_styling_to_screen(self.CSS_PATH)

            # Set window
            base_class.__init__(
                self,
                _("Kano WiFi"),
                self.width,
                self.height,
                socket_id
            )

            self.top_bar = TopBar(_("Kano WiFi"))
            self.top_bar.set_prev_callback(self.refresh_networks)
            self.top_bar.set_close_callback(Gtk.main_quit)
            self.prev_handler = None
            self.connect('delete-event', Gtk.main_quit)
            self.set_keep_above(True)
            self.set_icon_name('kano-settings')
            self.set_decorated(True)

            if self._base_name == "Window":
                self.set_titlebar(self.top_bar)

            self._launch_application()

        def _launch_application(self, widget=None):
            # Decide whether application prompts user to plug in WiFi dongle
            # or tell them they have ethernet.
            # Don't want to call this function more than once
            self.wiface = get_wlan_device()

            has_internet = is_internet()
            ethernet_plugged = is_ethernet_plugged()
            dongle_is_plugged_in = is_device(self.wiface)

            if has_internet and ethernet_plugged and self.no_confirm_ether:
                sys.exit(0)

            # For testing
            # dongle_is_plugged_in = False
            # ethernet_plugged = True
            # has_internet = False

            if has_internet and ethernet_plugged:
                self._you_are_connected_via_ethernet()

            elif dongle_is_plugged_in:
                if has_internet:
                    self._you_have_internet_screen(self.wiface)
                else:
                    # Refresh the networks list
                    self.refresh_networks()

            else:
                self._plug_in_wifi_dongle()

        def refresh_networks(self, widget=None, event=None):
            RefreshNetworks(self)

        def _plug_in_wifi_dongle(self):
            self.remove_main_widget()
            title = _("You don't seem to have a WiFi dongle\nplugged in.")
            description = _("Plug one in and try again")
            buttons = [
                {
                    'label': ""
                },
                {
                    'label': _("TRY AGAIN"),
                    'color': 'green',
                    'callback': self._launch_application,
                    'type': 'KanoButton',
                    'focus': True
                },
                {
                    'label': _("Skip"),
                    'callback': Gtk.main_quit,
                    'type': 'OrangeButton'
                }
            ]

            img_path = os.path.join(img_dir, "dongle2.png")

            screen = Template(
                title,
                description,
                buttons,
                self.is_plug(),
                img_path
            )
            self.set_main_widget(screen)
            screen.button_grab_focus()
            screen.show_all()

        def _you_are_connected_via_ethernet(self):
            self.remove_main_widget()
            title = _("You are already connected via ethernet.")
            description = _("Do you still want to connect with WiFi?")

            # Decide which callback to use depending on if wifi dongle is
            # plugged in
            buttons = [
                {
                    'label': _("NO"),
                    'color': 'red',
                    'callback': Gtk.main_quit,
                    'type': 'KanoButton'
                },
                {
                    'label': _("YES"),
                    'color': 'green',
                    'callback': self._ethernet_next_step,
                    'type': 'KanoButton',
                    'focus': True
                }
            ]

            img_path = os.path.join(img_dir, "ethernet-2.png")

            screen = Template(
                title,
                description,
                buttons,
                self.is_plug(),
                img_path
            )
            self.set_main_widget(screen)
            screen.button_grab_focus()
            screen.show_all()

        def _ethernet_next_step(self, widget=None):
            dongle_is_plugged_in = is_device(self.wiface)
            if dongle_is_plugged_in:
                self.refresh_networks()
            else:
                self._plug_in_wifi_dongle()

        def _you_have_internet_screen(self, wiface):
            self.remove_main_widget()
            title = _("You already have internet!")
            description = _("Do you want to change network?")
            buttons = [
                {
                    'label': _("NO"),
                    'color': 'red',
                    'callback': Gtk.main_quit,
                    'type': 'KanoButton'
                },
                {
                    'label': _("YES"),
                    'color': 'green',
                    'callback': self.refresh_networks,
                    'type': 'KanoButton',
                    'focus': True
                }
            ]
            img_path = os.path.join(img_dir, "internet.png")

            screen = Template(
                title,
                description,
                buttons,
                self.is_plug(),
                img_path
            )
            self.set_main_widget(screen)
            screen.button_grab_focus()
            screen.show_all()

        def _decide(self):
            if is_device(self.wiface):
                self.refresh_networks()
            else:
                self._plug_in_wifi_dongle()
Esempio n. 3
0
    class KanoWifiGui(base_class):

        CSS_PATH = os.path.join(css_dir, 'kano_wifi_gui.css')
        width = 350
        height = 450

        def __init__(self, wiface='wlan0', socket_id=0, no_confirm_ether=False):

            self.wiface = wiface
            self.network_list = []
            self.no_confirm_ether = no_confirm_ether

            # Default basic styling
            apply_common_to_screen()

            # Attach specific styling
            apply_styling_to_screen(self.CSS_PATH)

            # Set window
            base_class.__init__(
                self,
                _("Kano WiFi"),
                self.width,
                self.height,
                socket_id
            )

            self.top_bar = TopBar(_("Kano WiFi"))
            self.top_bar.set_prev_callback(self.refresh_networks)
            self.top_bar.set_close_callback(Gtk.main_quit)
            self.prev_handler = None
            self.connect('delete-event', Gtk.main_quit)
            self.set_keep_above(True)
            self.set_icon_name('kano-settings')
            self.set_decorated(True)

            if self._base_name == "Window":
                self.set_titlebar(self.top_bar)

            self._launch_application()

        def _launch_application(self, widget=None):
            # Decide whether application prompts user to plug in WiFi dongle
            # or tell them they have ethernet.
            # Don't want to call this function more than once
            self.wiface = get_wlan_device()

            has_internet = is_internet()
            ethernet_plugged = is_ethernet_plugged()
            dongle_is_plugged_in = is_device(self.wiface)

            if has_internet and ethernet_plugged and self.no_confirm_ether:
                sys.exit(0)

            # For testing
            # dongle_is_plugged_in = False
            # ethernet_plugged = True
            # has_internet = False

            if has_internet and ethernet_plugged:
                self._you_are_connected_via_ethernet()

            elif dongle_is_plugged_in:
                if has_internet:
                    self._you_have_internet_screen(self.wiface)
                else:
                    # Refresh the networks list
                    self.refresh_networks()

            else:
                self._plug_in_wifi_dongle()

        def refresh_networks(self, widget=None, event=None):
            RefreshNetworks(self)

        def _plug_in_wifi_dongle(self):
            self.remove_main_widget()
            title = _("You don't seem to have a WiFi dongle\nplugged in.")
            description = _("Plug one in and try again")
            buttons = [
                {
                    'label': ""
                },
                {
                    'label': _("TRY AGAIN"),
                    'color': 'green',
                    'callback': self._launch_application,
                    'type': 'KanoButton',
                    'focus': True
                },
                {
                    'label': _("Skip"),
                    'callback': Gtk.main_quit,
                    'type': 'OrangeButton'
                }
            ]

            img_path = os.path.join(img_dir, "dongle2.png")

            screen = Template(
                title,
                description,
                buttons,
                self.is_plug(),
                img_path
            )
            self.set_main_widget(screen)
            screen.button_grab_focus()
            screen.show_all()

        def _you_are_connected_via_ethernet(self):
            self.remove_main_widget()
            title = _("You are already connected via ethernet.")
            description = _("Do you still want to connect with WiFi?")

            # Decide which callback to use depending on if wifi dongle is
            # plugged in
            buttons = [
                {
                    'label': _("NO"),
                    'color': 'red',
                    'callback': Gtk.main_quit,
                    'type': 'KanoButton'
                },
                {
                    'label': _("YES"),
                    'color': 'green',
                    'callback': self._ethernet_next_step,
                    'type': 'KanoButton',
                    'focus': True
                }
            ]

            img_path = os.path.join(img_dir, "ethernet-2.png")

            screen = Template(
                title,
                description,
                buttons,
                self.is_plug(),
                img_path
            )
            self.set_main_widget(screen)
            screen.button_grab_focus()
            screen.show_all()

        def _ethernet_next_step(self, widget=None):
            dongle_is_plugged_in = is_device(self.wiface)
            if dongle_is_plugged_in:
                self.refresh_networks()
            else:
                self._plug_in_wifi_dongle()

        def _you_have_internet_screen(self, wiface):
            self.remove_main_widget()
            title = _("You already have internet!")
            description = _("Do you want to change network?")
            buttons = [
                {
                    'label': _("NO"),
                    'color': 'red',
                    'callback': Gtk.main_quit,
                    'type': 'KanoButton'
                },
                {
                    'label': _("YES"),
                    'color': 'green',
                    'callback': self.refresh_networks,
                    'type': 'KanoButton',
                    'focus': True
                }
            ]
            img_path = os.path.join(img_dir, "internet.png")

            screen = Template(
                title,
                description,
                buttons,
                self.is_plug(),
                img_path
            )
            self.set_main_widget(screen)
            screen.button_grab_focus()
            screen.show_all()

        def _decide(self):
            if is_device(self.wiface):
                self.refresh_networks()
            else:
                self._plug_in_wifi_dongle()