Exemplo n.º 1
0
    def __init__(self, stage, now_cb, later_cb):
        super(ParentalScreen, self).__init__(False, 0)

        self.set_hexpand(False)
        self.set_vexpand(False)
        self.set_margin_left(40)
        self.set_margin_right(40)

        heading = Gtk.Label('For parents...')
        add_class(heading, 'console-screen-heading')

        copy = 'You can put a safety filter on Kano\'s internet. ' + \
               'You can set it now or later.'
        desc = Gtk.Label(copy)
        desc.set_line_wrap(True)
        add_class(desc, 'console-screen-desc')

        padlock = Gtk.Image.new_from_file(stage.media_path('padlock.png'))

        later = KanoButton('GOT IT')
        later.connect('clicked', self._cb_wrapper, later_cb,
                      'init-flow-parental-skipped')
        later.set_size_request(200, 50)

        now = OrangeButton('SET NOW')
        now.connect('clicked', self._cb_wrapper, now_cb,
                    'init-flow-parental-set')

        emptylabel = Gtk.Label("       ")

        buttons = Gtk.ButtonBox()
        buttons.set_layout(Gtk.ButtonBoxStyle.SPREAD)
        buttons.pack_start(emptylabel, True, True, 0)
        buttons.pack_start(later, True, True, 20)
        buttons.pack_start(now, True, True, 20)

        self.pack_start(heading, False, False, 30)
        self.pack_start(desc, False, False, 20)
        self.pack_start(padlock, False, False, 10)
        self.pack_start(buttons, True, True, 30)
Exemplo n.º 2
0
class SetAccount(Gtk.Box):
    def __init__(self, win):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)

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

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

        self.added_or_removed_account = False

        main_heading = Heading(
            _("System account settings"),
            _("Set your account")
        )

        self.pass_button = KanoButton(_("CHANGE PASSWORD"))
        self.pass_button.pack_and_align()
        self.pass_button.connect('button-release-event', self.go_to_password_screen)
        self.pass_button.connect('key-release-event', self.go_to_password_screen)

        self.add_button = KanoButton(_("ADD ACCOUNT"))
        self.add_button.set_size_request(200, 44)
        self.add_button.connect('button-release-event', self.add_account)
        self.add_button.connect('key-release-event', self.add_account)

        self.remove_button = KanoButton(_("REMOVE ACCOUNT"), color='red')
        self.remove_button.set_size_request(200, 44)
        self.remove_button.connect('button-release-event', self.remove_account_dialog)
        self.remove_button.connect('key-release-event', self.remove_account_dialog)

        button_container = Gtk.Box()
        button_container.pack_start(self.add_button, False, False, 10)
        button_container.pack_start(self.remove_button, False, False, 10)

        button_align = Gtk.Alignment(xscale=0, xalign=0.5)
        button_align.add(button_container)

        accounts_heading = Heading(
            _("Accounts"),
            _("Add or remove accounts")
        )

        # Check if we already scheduled an account add or remove
        # We import kano-init locally to avoid circular dependency
        # the packages.
        try:
            from kano_init.utils import is_any_task_scheduled
            if is_any_task_scheduled():
                self.disable_buttons()
        except ImportError:
            self.disable_buttons()

        self.pack_start(main_heading.container, False, False, 0)
        self.pack_start(self.pass_button.align, False, False, 0)
        self.pack_start(accounts_heading.container, False, False, 0)
        self.pack_start(button_align, False, False, 0)

        self.win.show_all()

    def go_to_password_screen(self, widget, event):

        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:
            self.win.clear_win()
            SetPassword(self.win)

    # Gets executed when ADD button is clicked
    def add_account(self, widget=None, event=None):
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:
            kdialog = None

            try:
                # add new user command
                add_user()
            except UserError as e:
                kdialog = kano_dialog.KanoDialog(
                    _("Error creating new user"),
                    str(e),
                    parent_window=self.win
                )
            else:
                kdialog = kano_dialog.KanoDialog(
                    _("Reboot the system"),
                    _("A new account will be created next time you reboot."),
                    parent_window=self.win
                )

                # Tell user to reboot to see changes
                common.need_reboot = True

            kdialog.run()
            self.disable_buttons()

    # Gets executed when REMOVE button is clicked
    def remove_account_dialog(self, widget=None, event=None):
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:
            # Bring in message dialog box
            kdialog = kano_dialog.KanoDialog(
                _("Are you sure you want to delete the current user?"),
                _("You will lose all the data on this account!"),
                [
                    {
                        'label': _("CANCEL"),
                        'color': 'red',
                        'return_value': False
                    },
                    {
                        'label': _("OK"),
                        'color': 'green',
                        'return_value': True
                    }
                ],
                parent_window=self.win
            )
            do_delete_user = kdialog.run()
            if do_delete_user:
                self.disable_buttons()
                try:
                    delete_user()
                except UserError as e:
                    kdialog = kano_dialog.KanoDialog(
                        _("Error deleting user"),
                        str(e),
                        parent_window=self.win
                    )
                    return

                kdialog = kano_dialog.KanoDialog(
                    _("To finish removing this account, you need to reboot"),
                    _("Do you want to reboot?"),
                    [
                        {
                            'label': _("LATER"),
                            'color': 'grey',
                            'return_value': False
                        },
                        {
                            'label': _("REBOOT NOW"),
                            'color': 'orange',
                            'return_value': True
                        }
                    ],
                    parent_window=self.win
                )
                do_reboot_now = kdialog.run()
                if do_reboot_now:
                    os.system("sudo systemctl reboot")

    # Disables both buttons and makes the temp 'flag' folder
    def disable_buttons(self):

        self.add_button.set_sensitive(False)
        self.remove_button.set_sensitive(False)
        self.added_or_removed_account = True
Exemplo n.º 3
0
class SetAccount(Gtk.Box):
    def __init__(self, win):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)

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

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

        self.added_or_removed_account = False

        main_heading = Heading(_("System account settings"),
                               _("Set your account"))

        self.pass_button = KanoButton(_("CHANGE PASSWORD"))
        self.pass_button.pack_and_align()
        self.pass_button.connect('button-release-event',
                                 self.go_to_password_screen)
        self.pass_button.connect('key-release-event',
                                 self.go_to_password_screen)

        self.add_button = KanoButton(_("ADD ACCOUNT"))
        self.add_button.set_size_request(200, 44)
        self.add_button.connect('button-release-event', self.add_account)
        self.add_button.connect('key-release-event', self.add_account)

        self.remove_button = KanoButton(_("REMOVE ACCOUNT"), color='red')
        self.remove_button.set_size_request(200, 44)
        self.remove_button.connect('button-release-event',
                                   self.remove_account_dialog)
        self.remove_button.connect('key-release-event',
                                   self.remove_account_dialog)

        button_container = Gtk.Box()
        button_container.pack_start(self.add_button, False, False, 10)
        button_container.pack_start(self.remove_button, False, False, 10)

        button_align = Gtk.Alignment(xscale=0, xalign=0.5)
        button_align.add(button_container)

        accounts_heading = Heading(_("Accounts"), _("Add or remove accounts"))

        # Check if we already scheduled an account add or remove
        # We import kano-init locally to avoid circular dependency
        # the packages.
        try:
            from kano_init.utils import is_any_task_scheduled
            if is_any_task_scheduled():
                self.disable_buttons()
        except ImportError:
            self.disable_buttons()

        self.pack_start(main_heading.container, False, False, 0)
        self.pack_start(self.pass_button.align, False, False, 0)
        self.pack_start(accounts_heading.container, False, False, 0)
        self.pack_start(button_align, False, False, 0)

        self.win.show_all()

    def go_to_password_screen(self, widget, event):

        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:
            self.win.clear_win()
            SetPassword(self.win)

    # Gets executed when ADD button is clicked
    def add_account(self, widget=None, event=None):
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:
            kdialog = None

            try:
                # add new user command
                add_user()
            except UserError as e:
                kdialog = kano_dialog.KanoDialog(_("Error creating new user"),
                                                 str(e),
                                                 parent_window=self.win)
            else:
                kdialog = kano_dialog.KanoDialog(
                    _("Reboot the system"),
                    _("A new account will be created next time you reboot."),
                    parent_window=self.win)

                # Tell user to reboot to see changes
                common.need_reboot = True

            kdialog.run()
            self.disable_buttons()

    # Gets executed when REMOVE button is clicked
    def remove_account_dialog(self, widget=None, event=None):
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:
            # Bring in message dialog box
            kdialog = kano_dialog.KanoDialog(
                _("Are you sure you want to delete the current user?"),
                _("You will lose all the data on this account!"),
                [{
                    'label': _("CANCEL"),
                    'color': 'red',
                    'return_value': False
                }, {
                    'label': _("OK"),
                    'color': 'green',
                    'return_value': True
                }],
                parent_window=self.win)
            do_delete_user = kdialog.run()
            if do_delete_user:
                self.disable_buttons()
                try:
                    delete_user()
                except UserError as e:
                    kdialog = kano_dialog.KanoDialog(_("Error deleting user"),
                                                     str(e),
                                                     parent_window=self.win)
                    return

                kdialog = kano_dialog.KanoDialog(
                    _("To finish removing this account, you need to reboot"),
                    _("Do you want to reboot?"), [{
                        'label': _("LATER"),
                        'color': 'grey',
                        'return_value': False
                    }, {
                        'label': _("REBOOT NOW"),
                        'color': 'orange',
                        'return_value': True
                    }],
                    parent_window=self.win)
                do_reboot_now = kdialog.run()
                if do_reboot_now:
                    os.system("sudo systemctl reboot")

    # Disables both buttons and makes the temp 'flag' folder
    def disable_buttons(self):

        self.add_button.set_sensitive(False)
        self.remove_button.set_sensitive(False)
        self.added_or_removed_account = True