当前位置: 首页>>代码示例>>Python>>正文


Python KanoButton.start_spinner方法代码示例

本文整理汇总了Python中kano.gtk3.buttons.KanoButton.start_spinner方法的典型用法代码示例。如果您正苦于以下问题:Python KanoButton.start_spinner方法的具体用法?Python KanoButton.start_spinner怎么用?Python KanoButton.start_spinner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kano.gtk3.buttons.KanoButton的用法示例。


在下文中一共展示了KanoButton.start_spinner方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SetProxy

# 需要导入模块: from kano.gtk3.buttons import KanoButton [as 别名]
# 或者: from kano.gtk3.buttons.KanoButton import start_spinner [as 别名]

#.........这里部分代码省略.........
    def go_to_wifi(self, widget=None, event=None):
        self.win.clear_win()
        SetWifi(self.win)

    # Update for proxy
    def read_config(self):
        self.enable_proxy, data, _ = get_all_proxies()
        self.enabled_init = self.enable_proxy
        if self.enable_proxy:
            try:
                self.ip_entry.set_text(data['host'])
                self.port_entry.set_text(data['port'])
                if data['username']:
                    self.username_entry.set_text(data['username'])
                if data['password']:
                    self.password_entry.set_text(data['password'])
            except:
                # Something went wrong > disable proxy
                set_all_proxies(False)
                common.proxy_enabled = False
                self.enable_proxy = False
                self.enabled_init = False
                self.clear_entries()
        self.checkbutton.set_active(self.enable_proxy)

    def apply_changes(self, button, event):
        # If enter key is pressed or mouse button is clicked
        if not hasattr(event, 'keyval') or event.keyval == 65293:

            # This is a callback called by the main loop, so it's safe to
            # manipulate GTK objects:
            watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH)
            self.win.get_window().set_cursor(watch_cursor)
            self.kano_button.start_spinner()
            self.kano_button.set_sensitive(False)

            def lengthy_process():

                if self.enable_proxy:
                    host = self.ip_entry.get_text()
                    port = self.port_entry.get_text()
                    username = self.username_entry.get_text()
                    password = self.password_entry.get_text()
                    set_all_proxies(enable=True, host=host, port=port, username=username, password=password)
                    common.proxy_enabled = True

                    success, text = test_proxy()
                    if not success:
                        title = _("Error with proxy")
                        description = text
                        return_value = 1

                        # disable proxy if we couldn't successfully enable it
                        set_all_proxies(False)
                        common.proxy_enabled = False
                    else:
                        title = _("Successfully enabled proxy")
                        description = ""
                        return_value = 0

                else:
                    set_all_proxies(False)
                    common.proxy_enabled = False
                    title = _("Successfully disabled proxy")
                    description = ""
                    return_value = 0
开发者ID:,项目名称:,代码行数:70,代码来源:

示例2: PasswordScreen

# 需要导入模块: from kano.gtk3.buttons import KanoButton [as 别名]
# 或者: from kano.gtk3.buttons.KanoButton import start_spinner [as 别名]

#.........这里部分代码省略.........

        self._show_password = Gtk.CheckButton.new_with_label("Show password")
        self._show_password.get_style_context().add_class("show_password")
        self._show_password.connect("toggled",
                                    self._change_password_entry_visiblity)
        self._show_password.set_active(True)
        self._show_password.set_margin_left(100)

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(vbox)

        vbox.pack_start(self._heading.container, False, False, 10)
        vbox.pack_start(self._padlock_image, False, False, 10)
        vbox.pack_start(self._password_entry, False, False, 10)
        vbox.pack_start(self._show_password, False, False, 10)
        vbox.pack_end(self._connect_btn.align, False, False, 40)

        # Entry should have the keyboard focus
        self._password_entry.grab_focus()

        self.show_all()

    def _create_wrong_password_label(self):
        label = Gtk.Label("Password incorrect")
        label.get_style_context().add_class("wrong_password_label")
        return label

    def _change_password_entry_visiblity(self, widget):
        '''
        Depending on the checkbox, change the writing in the
        password entry to be readable.
        '''
        visibility = self._show_password.get_active()
        self._password_entry.set_visibility(visibility)

    def _refresh_networks(self, widget=None):
        from kano_wifi_gui.RefreshNetworks import RefreshNetworks
        RefreshNetworks(self._win)

    def _on_connect_key_wrapper(self, widget, event):
        if event.keyval == Gdk.KEY_Return:
            self._on_connect()

    def _on_connect(self, widget=None):
        passphrase = self._password_entry.get_text()
        ConnectToNetwork(
            self._win,
            self._network_name,
            passphrase,
            self._encryption
        )

    def _set_button_sensitive(self, widget, event):
        self._connect_btn.set_sensitive(True)

    def _thread_finish(self, success):

        if success:
            self._success_screen()
        else:
            self._wrong_password_screen()

    def _success_screen(self):
        self._win.remove_main_widget()

        title = "Success!"
        description = "You're connected"
        buttons = [
            {
                "label": "OK",
                "color": "green",
                "type": "KanoButton",
                "callback": Gtk.main_quit
            }
        ]
        img_path = os.path.join(img_dir, "internet.png")

        self._win.set_main_widget(
            Template(
                title,
                description,
                buttons,
                self._win.is_plug(),
                img_path
            )
        )

    def _disable_widgets_start_spinner(self):
        self._connect_btn.start_spinner()
        self._connect_btn.set_sensitive(False)
        self._win.top_bar.prev_button.set_sensitive(False)
        self._password_entry.set_sensitive(False)
        self._show_password.set_sensitive(False)

    def _enable_widgets_stop_spinner(self):
        self._connect_btn.stop_spinner()
        self._connect_btn.set_sensitive(True)
        self._win.top_bar.prev_button.set_sensitive(True)
        self._password_entry.set_sensitive(True)
        self._show_password.set_sensitive(True)
开发者ID:gvsurenderreddy,项目名称:kano-settings,代码行数:104,代码来源:PasswordScreen.py

示例3: LoginWithKanoWorldView

# 需要导入模块: from kano.gtk3.buttons import KanoButton [as 别名]
# 或者: from kano.gtk3.buttons.KanoButton import start_spinner [as 别名]
class LoginWithKanoWorldView(Gtk.Grid):

    def __init__(self, greeter):
        Gtk.Grid.__init__(self)

        self.get_style_context().add_class('password')
        self.set_row_spacing(12)

        self.greeter = greeter

        title = Heading(_('Login with Kano World'),
                        _('Enter your Kano World details.'))
        self.attach(title.container, 0, 0, 1, 1)

        self.username = Gtk.Entry()
        self.username.set_placeholder_text('username')
        self.attach(self.username, 0, 1, 1, 1)

        self.password = Gtk.Entry()
        self.password.set_visibility(False)
        self.password.set_placeholder_text('password')
        self.attach(self.password, 0, 2, 1, 1)

        self.login_btn = KanoButton(_('LOGIN'))
        self.login_btn.connect('clicked', self._btn_login_pressed)
        self.attach(self.login_btn, 0, 3, 1, 1)

    def _btn_login_pressed(self, event=None, button=None):
        '''
        Authenticates against Kano World. If successful synchronizes to a local
        Unix account, and tells lightdm to go forward with local a login.
        '''
        logger.debug('Synchronizing Kano World account')
        self.login_btn.start_spinner()
        self.login_btn.set_sensitive(False)

        t = threading.Thread(target=self._thr_login)
        t.start()

    def _thr_login(self):
        loggedin = False
        reason = ''

        # TODO: Disable the "login" button unless these entry fields are non-empty
        # Collect credentials from the view
        self.unix_password = self.password.get_text()
        self.world_username = self.username.get_text()
        self.unix_username = self.username.get_text()
        atsign = self.unix_username.find('@')
        if atsign != -1:
            # For if we are in "staging" mode (see /etc/kano-world.conf)
            self.unix_username = self.unix_username[:atsign]

        # Now try to login to Kano World
        try:
            logger.debug('Authenticating user: {} to Kano World'.format(self.username.get_text()))
            (loggedin, reason) = kano_world_authenticate(self.username.get_text(), self.password.get_text())
            logger.debug('Kano World auth response: {} - {}'.format(loggedin, reason))
        except Exception as e:
            reason = str(e)
            logger.debug('Kano World auth Exception: {}'.format(reason))
            pass

        if not loggedin:
            # Kano world auth unauthorized
            # FIXME: Localizing the below string fails with an exception
            GObject.idle_add(self._error_message_box, 'Failed to authenticate to Kano World', reason)
            return
        else:
            # We are authenticated to Kano World: proceed with forcing local user
            rc = -1
            try:
                # Create the local unix user, bypass kano-init-flow, login & sync to Kano World
                createuser_cmd = 'sudo /usr/bin/kano-greeter-account {} {} {}'.format(
                    self.unix_username, self.unix_password, self.world_username)
                _, _, rc = run_cmd(createuser_cmd)
                if rc == 0:
                    logger.debug('Local user created correctly: {}'.format(self.unix_username))
                elif rc == 1:
                    logger.debug('Local user already exists, proceeding with login: {}'.format(self.unix_username))

                created = True
            except:
                created = False

            if not created:
                logger.debug('Error creating new local user: {}'.format(self.unix_username))
                GObject.idle_add(self._error_message_box, "Could not create local user", rc)
                return

            # Tell Lidghtdm to proceed with login session using the new user
            # We bind LightDM at this point only, this minimizes the number of attempts
            # to bind the Greeter class to a view, which he does not like quite well.
            logger.debug('Scheduling lightdm authentication in math thread')
            GObject.idle_add(self._auth_call)

    def _auth_call(self):
        logger.debug('Starting lightdm authentication')
        self._reset_greeter()
        self.greeter.authenticate(self.unix_username)
#.........这里部分代码省略.........
开发者ID:comuri,项目名称:kano-greeter,代码行数:103,代码来源:login_with_kw_view.py

示例4: PasswordView

# 需要导入模块: from kano.gtk3.buttons import KanoButton [as 别名]
# 或者: from kano.gtk3.buttons.KanoButton import start_spinner [as 别名]
class PasswordView(Gtk.Grid):

    def __init__(self, user, greeter):
        Gtk.Grid.__init__(self)

        self.get_style_context().add_class('password')
        self.set_row_spacing(10)

        self.greeter = greeter

        self.user = user
        self.title = self._set_title()

        self.attach(self.title.container, 0, 0, 1, 1)
        self.label = Gtk.Label(user)
        self.label.get_style_context().add_class('login')
        self.attach(self.label, 0, 1, 1, 1)
        self.password = Gtk.Entry()
        self.password.set_visibility(False)
        self.password.set_alignment(0.5)
        self.password.connect('activate', self._login_cb)
        self.attach(self.password, 0, 2, 1, 1)

        self.login_btn = KanoButton(_('Login').upper())
        self.login_btn.connect('clicked', self._login_cb)
        self.attach(self.login_btn, 0, 3, 1, 1)

        # Protect against removing the last Kano user
        # so you do not get locked out from logging into the Kit
        system_users = KanoUserList().get_users()
        if len(system_users) > 1:
            delete_account_btn = OrangeButton(_('Remove Account'))
            delete_account_btn.connect('clicked', self.delete_user)
            self.attach(delete_account_btn, 0, 4, 1, 1)

    def _set_title(self, create=True):
        '''
        Creates a Heading text widget, or updates it
        with the currently selected username.
        '''
        text_title = _('{}: Enter your password').format(self.user)
        text_description = _('If you haven\'t changed your\npassword, use "kano"')

        if create:
            title = Heading(text_title, text_description)
            return title
        else:
            self.title.set_text(text_title, text_description)
            return self.title

    def _reset_greeter(self):
        # connect signal handlers to LightDM
        self.cb_one = self.greeter.connect('show-prompt', self._send_password_cb)
        self.cb_two = self.greeter.connect('authentication-complete',
                                           self._authentication_complete_cb)
        self.cb_three = self.greeter.connect('show-message', self._auth_error_cb)

        self.greeter.connect_sync()
        return (self.cb_one, self.cb_two, self.cb_three)

    def _login_cb(self, event=None, button=None):
        logger.debug('Sending username to LightDM')

        self.login_btn.start_spinner()
        Gtk.main_iteration_do(True)

        # The call below will simply initiate the login flow.
        # The greeter library will inform us through callbacks
        # See: http://web.mit.edu/Source/debathena/config/lightdm-config/debian/debathena-lightdm-greeter
        self.greeter.authenticate(self.user)

    def _send_password_cb(self, _greeter, text, prompt_type):
        logger.debug(u'Need to show prompt: {}'.format(text))

        if _greeter.get_in_authentication():
            logger.debug('Sending password to LightDM')
            _greeter.respond(self.password.get_text())

    def _authentication_complete_cb(self, _greeter):
        logger.debug('Authentication process is complete')

        if not _greeter.get_is_authenticated():
            logger.warn('Could not authenticate user {}'.format(self.user))
            self._auth_error_cb(_('Incorrect password (The default is "kano")'))
            return

        logger.info(
            'The user {} is authenticated. Starting LightDM X Session'
            .format(self.user))

        set_last_user(self.user)

        if not _greeter.start_session_sync('lightdm-xsession'):
            logger.error('Failed to start session')
        else:
            logger.info('Login failed')

    def _auth_error_cb(self, text, message_type=None):
        logger.info(u'There was an error logging in: {}'.format(text))

#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例5: ResetPassword

# 需要导入模块: from kano.gtk3.buttons import KanoButton [as 别名]
# 或者: from kano.gtk3.buttons.KanoButton import start_spinner [as 别名]
class ResetPassword(Gtk.Box):

    def __init__(self, win):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)

        self.win = win
        self.win.set_decorated(False)
        self.win.set_main_widget(self)

        self.heading = Heading(
            _("Reset your password"),
            _("We'll send a new password to your email")
        )
        self.pack_start(self.heading.container, False, False, 10)

        self.labelled_entries = LabelledEntries([
            {"heading": _("Email"), "subheading": ""}
        ])
        align = Gtk.Alignment(xscale=0, xalign=0.5)
        self.pack_start(align, False, False, 15)

        self.labelled_entries.set(0, 0, 1, 1)
        self.labelled_entries.set_hexpand(True)

        align.add(self.labelled_entries)

        # Read email from file
        user_email = get_email()

        self.email_entry = self.labelled_entries.get_entry(0)
        self.email_entry.set_text(user_email)
        self.email_entry.connect("key-release-event", self.activate)

        self.button = KanoButton(_("Reset password").upper())
        self.button.pack_and_align()
        self.button.connect("button-release-event", self.activate)
        self.button.connect("key-release-event", self.activate)
        self.button.set_padding(30, 30, 0, 0)

        self.pack_start(self.button.align, False, False, 0)
        self.win.show_all()

    def activate(self, widget, event):
        if not hasattr(event, 'keyval') or event.keyval == 65293:
            watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH)
            self.win.get_window().set_cursor(watch_cursor)
            self.button.set_sensitive(False)
            self.button.start_spinner()

            thread = threading.Thread(target=self.send_new_password)
            thread.start()

    def send_new_password(self):
        # User may change email
        email = self.labelled_entries.get_entry(0).get_text()
        success, text = reset_password(email)
        if success:
            title = _("Success!")
            description = _("Sent new password to your email")
            button_dict = {
                _("Go to login screen").upper(): {"return_value": 12},
                _("Quit").upper(): {"return_value": 10, "color": "red"}
            }
        else:
            title = _("Something went wrong!")
            description = text
            button_dict = {
                _("Quit").upper(): {"return_value": 10, "color": "red"},
                _("Try again").upper(): {"return_value": 11}
            }

        GObject.idle_add(
            self.finished_thread_cb,
            title,
            description,
            button_dict
        )

    def finished_thread_cb(self, title, description, button_dict):
        kdialog = KanoDialog(
            title,
            description,
            button_dict=button_dict,
            parent_window=self.win
        )
        response = kdialog.run()

        self.win.get_window().set_cursor(None)
        self.button.stop_spinner()
        self.button.set_sensitive(True)

        if response == 10:
            Gtk.main_quit()
        # stay put
        elif response == 11:
            pass
        elif response == 12:
            self.go_to_login_screen()

    def go_to_login_screen(self):
#.........这里部分代码省略.........
开发者ID:japonophile,项目名称:kano-profile,代码行数:103,代码来源:login.py

示例6: NetworkScreen

# 需要导入模块: from kano.gtk3.buttons import KanoButton [as 别名]
# 或者: from kano.gtk3.buttons.KanoButton import start_spinner [as 别名]

#.........这里部分代码省略.........
            self._skip_btn.connect('clicked', self.skip)
        else:
            blank_label = Gtk.Label("")
            buttonbox.pack_start(blank_label, False, False, 0)

        return buttonbox

    # Attached to a callback, hence the extra argument
    def skip(self, skip_btn=None):
        # Exit with an extreme exit code so the init-flow knows the user
        # pressed SKIP
        sys.exit(100)

    def _set_connect_btn_status(self, connect=True):
        self._connect_btn.disconnect(self.connect_handler)

        if connect:
            self.connect_handler = self._connect_btn.connect(
                'clicked', self._first_time_connect
            )
            self._connect_btn.set_color('green')
            self._connect_btn.set_label(_("CONNECT"))

        else:
            self.connect_handler = self._connect_btn.connect(
                'clicked', self._launch_disconnect_thread
            )
            self._connect_btn.set_color('red')
            self._connect_btn.set_label(_("DISCONNECT"))

    def _launch_disconnect_thread(self, widget=None):
        watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH)
        self._win.get_window().set_cursor(watch_cursor)
        self._connect_btn.start_spinner()
        self._connect_btn.set_sensitive(False)

        # Force the spinner to show on the window.
        while Gtk.events_pending():
            Gtk.main_iteration()

        t = threading.Thread(target=self._threaded_disconnect)
        t.start()

    def _disconnect_screen(self):
        self._win.remove_main_widget()
        title = _("Disconnect complete.")
        description = _("You're now offline")
        buttons = [
            {
                'label': _("CLOSE"),
                'type': 'KanoButton',
                'color': 'red',
                'callback': Gtk.main_quit
            },
            {
                'label': _("CONNECT"),
                'type': 'KanoButton',
                'color': 'green',
                'callback': self._go_to_spinner_screen
            }
        ]
        img_path = os.path.join(img_dir, "no-wifi.png")
        self._win.set_main_widget(
            Template(
                title,
                description,
开发者ID:KanoComputing,项目名称:kano-settings,代码行数:70,代码来源:NetworkScreen.py


注:本文中的kano.gtk3.buttons.KanoButton.start_spinner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。