Esempio n. 1
0
    def __init__(self, parent, provider):
        self.provider = provider
        self.tooltip = self.BASE_TOOLTIP
        self.installation_thread = KiteInstallationThread(self)
        super().__init__(parent)
        is_installed, _ = check_if_kite_installed()
        self.setVisible(is_installed)

        # Installation dialog
        self.installer = KiteInstallerDialog(self, self.installation_thread)

        self.installation_thread.sig_installation_status.connect(
            self.set_value)
        self.sig_clicked.connect(self.show_installation_dialog)
Esempio n. 2
0
def test_kite_install(qtbot):
    """Test the correct execution of the installation process of kite."""
    install_manager = KiteInstallationThread(None)
    installation_statuses = []

    def installation_status(status):
        installation_statuses.append(status)

    def error_msg(error):
        # Should not enter here
        assert False

    def download_progress(progress, total):
        assert total != 0

    def finished():
        if sys.platform.startswith("linux"):
            expected_installation_status = [
                DOWNLOADING_SCRIPT,
                DOWNLOADING_INSTALLER,
                INSTALLING,
                FINISHED]
        else:
            expected_installation_status = [
                DOWNLOADING_INSTALLER,
                INSTALLING,
                FINISHED]

        # This status can be obtained the second time our tests are run
        if not installation_statuses == ['Installation finished']:
            assert installation_statuses == expected_installation_status

    install_manager.sig_installation_status.connect(installation_status)
    install_manager.sig_error_msg.connect(error_msg)
    install_manager.sig_download_progress.connect(download_progress)
    install_manager.finished.connect(finished)
    with qtbot.waitSignal(install_manager.finished, timeout=INSTALL_TIMEOUT):
        install_manager.install()

    # Check that kite was installed and is running
    qtbot.waitUntil(
        lambda: check_if_kite_installed() and check_if_kite_running(),
        timeout=5000)
Esempio n. 3
0
class KiteStatusWidget(StatusBarWidget):
    """Status bar widget for Kite completions status."""
    BASE_TOOLTIP = _("Kite completions status")
    DEFAULT_STATUS = _('not reachable')
    ID = 'kite_status'

    def __init__(self, parent, provider):
        self.provider = provider
        self.tooltip = self.BASE_TOOLTIP
        self.installation_thread = KiteInstallationThread(self)
        super().__init__(parent)
        is_installed, _ = check_if_kite_installed()
        self.setVisible(is_installed)

        # Installation dialog
        self.installer = KiteInstallerDialog(self, self.installation_thread)

        self.installation_thread.sig_installation_status.connect(
            self.set_value)
        self.sig_clicked.connect(self.show_installation_dialog)

    def set_value(self, value):
        """Return Kite completions state."""
        kite_enabled = self.provider.get_option(('enabled_providers', 'kite'),
                                                default=True,
                                                section='completions')
        is_installing = self.is_installing()
        cancelled_or_errored = self.installation_cancelled_or_errored()

        if (value is not None and 'short' in value):
            self.tooltip = value['long']
            value = value['short']
        elif value is not None and (is_installing or cancelled_or_errored):
            self.setVisible(True)
            if value == NOT_INSTALLED:
                return
            elif is_installing:
                self.tooltip = _("Kite installation will continue in the "
                                 "background.\n"
                                 "Click here to show the installation "
                                 "dialog again")
            elif cancelled_or_errored:
                self.tooltip = _("Click here to show the\n"
                                 "installation dialog again")
        elif value is None:
            value = self.DEFAULT_STATUS
            self.tooltip = self.BASE_TOOLTIP
        self.update_tooltip()
        self.setVisible(value != NOT_INSTALLED and kite_enabled)
        value = "Kite: {0}".format(value)
        super(KiteStatusWidget, self).set_value(value)

    def get_tooltip(self):
        """Reimplementation to get a dynamic tooltip."""
        return self.tooltip

    def get_icon(self):
        return ima.get_icon('kite', adjust_for_interface=True)

    @Slot()
    def show_installation_dialog(self):
        """Show installation dialog."""
        installed, path = check_if_kite_installed()
        if not installed and not running_under_pytest():
            self.installer.show()

    def is_installing(self):
        """Check if an installation is taking place."""
        return (self.installation_thread.isRunning()
                and not self.installation_thread.cancelled)

    def installation_cancelled_or_errored(self):
        """Check if an installation was cancelled or failed."""
        return self.installation_thread.cancelled_or_errored()

    @Slot()
    def mainwindow_setup_finished(self):
        """
        This is called after the main window setup finishes, and the
        third time Spyder is started, to show Kite's installation dialog
        and onboarding if necessary.
        """
        spyder_runs = self.provider.get_option('spyder_runs')
        if spyder_runs == 3:
            self.provider._kite_onboarding()

            show_dialog = self.provider.get_option('show_installation_dialog')
            if show_dialog:
                # Only show the dialog once at startup
                self.provider.set_option('show_installation_dialog', False)
                self.show_installation_dialog()
        else:
            if spyder_runs < 3:
                self.provider.set_option('spyder_runs', spyder_runs + 1)