Beispiel #1
0
class ListItemRunningApp(QListWidgetItem):
    """List item representing a running application."""
    def __init__(self, package):
        """List item representing a running application."""
        super(ListItemRunningApp, self).__init__()
        self.widget = FrameRunningApps()
        self.package = package
        self.label = LabelBase(package)
        self.checkbox = CheckBoxBase()

        layout_frame = QHBoxLayout()
        layout_frame.addWidget(self.checkbox)
        layout_frame.addWidget(self.label)
        layout_frame.addStretch()
        self.widget.setLayout(layout_frame)
        self.setSizeHint(self.widget_size())

    def set_checked(self, value):
        """Set the check state for the checkbox in the list item."""
        self.checkbox.setChecked(value)

    def checked(self):
        """Return True if checked otherwise return False."""
        return self.checkbox.isChecked()

    @staticmethod
    def set_loading(item):
        """Override."""
        item

    def text(self):
        """Qt override."""
        return self.label.text()

    @staticmethod
    def set_selected(item):
        """Override."""
        item

    @staticmethod
    def widget_size():
        """Return the size defined in the SASS file."""
        return QSize(SASS_VARIABLES.WIDGET_RUNNING_APPS_TOTAL_WIDTH,
                     SASS_VARIABLES.WIDGET_RUNNING_APPS_TOTAL_HEIGHT)
Beispiel #2
0
class QuitApplicationDialog(DialogBase):
    """Quit application confirmation dialog."""
    def __init__(self, *args, **kwargs):
        """Quit application confirmation dialog."""
        self.config = kwargs.pop('config', CONF)
        super(QuitApplicationDialog, self).__init__(*args, **kwargs)
        self.widget_icon = QSvgWidget(images.ANACONDA_LOGO)
        self.label_about = QLabel('Quit Anaconda Navigator?')
        self.button_ok = ButtonPrimary('Yes')
        self.button_cancel = ButtonNormal('No')
        self.buttonbox = QDialogButtonBox(Qt.Horizontal)
        self.checkbox = CheckBoxBase("Don't show again")

        # Widgets setup
        self.setWindowTitle("Quit application")
        self.widget_icon.setFixedSize(QSize(100, 100))

        # Layouts
        h_layout = QHBoxLayout()
        h_layout.addWidget(self.widget_icon, 0, Qt.AlignTop)
        h_layout.addWidget(SpacerHorizontal())
        h_layout.addWidget(self.label_about)

        layout_buttons = QHBoxLayout()
        layout_buttons.addStretch()
        layout_buttons.addWidget(self.button_cancel)
        layout_buttons.addWidget(SpacerHorizontal())
        layout_buttons.addWidget(self.button_ok)

        main_layout = QVBoxLayout()
        main_layout.addLayout(h_layout)
        main_layout.addWidget(self.checkbox, 0, Qt.AlignRight)
        main_layout.addWidget(SpacerVertical())
        main_layout.addWidget(SpacerVertical())
        main_layout.addLayout(layout_buttons)
        self.setLayout(main_layout)

        # Signals
        self.button_ok.clicked.connect(self.accept)
        self.button_cancel.clicked.connect(self.reject)

        # Setup
        self.update_style_sheet()
        self.setup()
        self.button_cancel.setFocus()

    def setup(self):
        """Setup widget content."""
        # Widget setup
        if self.config.get('main', 'hide_quit_dialog'):
            hide_dialog = Qt.Checked
        else:
            hide_dialog = Qt.Unchecked
        self.checkbox.setChecked(hide_dialog)

    def accept(self):
        """
        Qt overide.

        Update the configuration preferences.
        """
        hide_dialog = self.checkbox.checkState() == Qt.Checked
        self.config.set('main', 'hide_quit_dialog', hide_dialog)
        super(QuitApplicationDialog, self).accept()
Beispiel #3
0
class QuitRunningAppsDialog(DialogBase):
    """Dialog for closing running apps if quiting navigator."""
    def __init__(self, *args, **kwargs):
        """Dialog for closing running apps if quiting navigator."""
        self.running_processes = kwargs.pop('running_processes', [])
        self.config = kwargs.pop('config', CONF)
        super(QuitRunningAppsDialog, self).__init__(*args, **kwargs)

        self.list = ListRunningApps(self)
        self.label_about = QLabel('There are some applications running. '
                                  'Please select \nthe applications you '
                                  'want to close on quit:')
        self.button_close = ButtonDanger('Quit')
        self.button_cancel = ButtonNormal('Cancel')
        self.buttonbox = QDialogButtonBox(Qt.Horizontal)
        self.checkbox = CheckBoxBase("Don't show again")

        # Widget setup
        self.setWindowTitle("Close running applications")

        # Layouts
        layout_buttons = QHBoxLayout()
        layout_buttons.addStretch()
        layout_buttons.addWidget(self.button_cancel)
        layout_buttons.addWidget(SpacerHorizontal())
        layout_buttons.addWidget(self.button_close)

        main_layout = QVBoxLayout()
        main_layout.addWidget(self.label_about)
        main_layout.addWidget(SpacerVertical())
        main_layout.addWidget(self.list, 0, Qt.AlignCenter)
        main_layout.addWidget(SpacerVertical())
        main_layout.addWidget(self.checkbox, 0, Qt.AlignRight)
        main_layout.addWidget(SpacerVertical())
        main_layout.addWidget(SpacerVertical())
        main_layout.addLayout(layout_buttons)
        self.setLayout(main_layout)

        # Signals
        self.button_close.clicked.connect(self.accept)
        self.button_cancel.clicked.connect(self.reject)

        # Setup
        self.update_style_sheet()
        self.setup()
        self.button_cancel.setFocus()

    def setup(self):
        """Setup widget content."""
        # Widget setup
        packages = sorted(set(p['package'] for p in self.running_processes))
        checked_packages = self.config.get('main', 'running_apps_to_close')
        for package in packages:
            item = ListItemRunningApp(package)
            item.set_checked(package in checked_packages)
            self.list.addItem(item)

        if self.config.get('main', 'hide_running_apps_dialog'):
            hide_dialog = Qt.Checked
        else:
            hide_dialog = Qt.Unchecked
        self.checkbox.setChecked(hide_dialog)

    def accept(self):
        """
        Qt overide.

        Update the configuration preferences.
        """
        original_checked_packages = set(
            self.config.get('main', 'running_apps_to_close'))
        hide_dialog = self.checkbox.checkState() == Qt.Checked
        checked_packages = {i.text() for i in self.list.items() if i.checked()}
        packages = {i.text() for i in self.list.items()}
        delta = original_checked_packages - packages
        new_packages = sorted(list(checked_packages.union(delta)))
        self.config.set('main', 'running_apps_to_close', new_packages)
        self.config.set('main', 'hide_running_apps_dialog', hide_dialog)
        super(QuitRunningAppsDialog, self).accept()
Beispiel #4
0
class CreateDialog(EnvironmentActionsDialog):
    """Create new environment dialog."""

    PYTHON_VERSIONS = ['2.7', '3.5', '3.6']

    def __init__(self, parent=None):
        """Create new environment dialog."""
        super(CreateDialog, self).__init__(parent=parent)

        # Widgets
        self.label_name = LabelBase("Name:")
        self.label_location = LabelBase("Location:")
        self.label_prefix = LabelBase('')
        self.text_name = LineEditBase()
        self.label_version = LabelBase("Python version")
        self.label_packages = LabelBase("Packages:")
        self.combo_version = ComboBoxBase()
        self.check_python = CheckBoxBase("Python")
        self.check_r = CheckBoxBase('R')
        self.button_ok = ButtonPrimary('Create')
        self.button_cancel = ButtonNormal('Cancel')

        # Widgets setup
        self.align_labels(
            [self.label_name, self.label_location, self.label_packages])
        self.text_name.setPlaceholderText("New environment name")
        self.setMinimumWidth(self.BASE_DIALOG_WIDTH)
        self.setWindowTitle("Create new environment")
        self.text_name.setValidator(self.get_regex_validator())
        self.label_prefix.setObjectName('environment-location')
        self.combo_version.setObjectName('package-version')

        # Supported set of python versions
        versions = self.PYTHON_VERSIONS
        now = "{}.{}".format(sys.version_info.major, sys.version_info.minor)
        if now not in versions:
            # Guard against non-standard version, or the coming 3.6
            versions.append(now)
            versions.sort()
        versions = list(reversed(versions))
        self.combo_version.addItems(versions)
        self.combo_version.setCurrentIndex(versions.index(now))

        # Layouts
        layout_python = QHBoxLayout()
        layout_python.addWidget(self.check_python)
        layout_python.addWidget(self.combo_version)
        layout_python.addStretch()

        layout_r = QHBoxLayout()
        layout_r.addWidget(self.check_r)

        grid = QGridLayout()
        grid.addWidget(self.label_name, 0, 0)
        grid.addWidget(SpacerHorizontal(), 0, 1)
        grid.addWidget(self.text_name, 0, 2)
        grid.addWidget(SpacerVertical(), 1, 0)
        grid.addWidget(self.label_location, 2, 0)
        grid.addWidget(SpacerHorizontal(), 2, 1)
        grid.addWidget(self.label_prefix, 2, 2)
        grid.addWidget(SpacerVertical(), 3, 0)
        grid.addWidget(self.label_packages, 4, 0)
        grid.addLayout(layout_python, 4, 2)
        grid.addWidget(SpacerVertical(), 5, 0)
        grid.addLayout(layout_r, 6, 2)

        layout_buttons = QHBoxLayout()
        layout_buttons.addStretch()
        layout_buttons.addWidget(self.button_cancel)
        layout_buttons.addWidget(SpacerHorizontal())
        layout_buttons.addWidget(self.button_ok)

        main_layout = QVBoxLayout()
        main_layout.addLayout(grid)
        main_layout.addWidget(SpacerVertical())
        main_layout.addWidget(SpacerVertical())
        main_layout.addLayout(layout_buttons)

        self.setLayout(main_layout)

        # Signals
        self.button_ok.clicked.connect(self.accept)
        self.button_cancel.clicked.connect(self.reject)
        self.text_name.textChanged.connect(self.refresh)
        self.check_python.stateChanged.connect(self.refresh)
        self.check_r.stateChanged.connect(self.refresh)

        # Setup
        self.text_name.setFocus()
        self.check_python.setChecked(True)
        self.check_r.setChecked(False)
        self.refresh()

    def refresh(self, text=''):
        """Update status of buttons based on data."""
        name = self.name
        self.update_location()

        if self.environments:
            check = self.install_python or self.install_r
            if check and self.is_valid_env_name(name):
                self.button_ok.setDisabled(False)
            else:
                self.button_ok.setDisabled(True)
        self.combo_version.setEnabled(self.install_python)

    @property
    def python_version(self):
        """Return the python version if python was selected for install."""
        version = None
        if self.install_python:
            version = self.combo_version.currentText()
        return version

    @property
    def install_python(self):
        """Return if python was selected for install."""
        return bool(self.check_python.checkState())

    @property
    def install_r(self):
        """Return if r was selected for install."""
        return bool(self.check_r.checkState())
Beispiel #5
0
class CreateDialog(EnvironmentActionsDialog):
    """Create new environment dialog."""

    MRO = 'mro'
    R = 'r'
    PYTHON_VERSIONS = [u'2.7', u'3.5', u'3.6', u'3.7']
    MRO_MAC_MIN_VERSION = (10, 11)

    def __init__(self, parent=None, api=None):
        """Create new environment dialog."""
        super(CreateDialog, self).__init__(parent=parent, api=api)

        # Widgets
        self.label_name = LabelBase("Name:")
        self.label_location = LabelBase("Location:")
        self.label_prefix = LabelBase('')
        self.text_name = LineEditBase()
        self.label_version = LabelBase("Python version")
        self.label_packages = LabelBase("Packages:")
        self.combo_version = ComboBoxBase()
        self.check_python = CheckBoxBase("Python")
        self.check_r = CheckBoxBase('R')
        self.combo_r_type = ComboBoxBase()
        self.button_ok = ButtonPrimary('Create')
        self.button_cancel = ButtonNormal('Cancel')

        # Widgets setup
        self.align_labels(
            [self.label_name, self.label_location, self.label_packages]
        )
        self.text_name.setPlaceholderText("New environment name")
        self.setMinimumWidth(self.BASE_DIALOG_WIDTH)
        self.setWindowTitle("Create new environment")
        self.text_name.setValidator(self.get_regex_validator())
        self.label_prefix.setObjectName('environment-location')
        self.combo_version.setObjectName('package-version')
        self.combo_r_type.setObjectName('r-type')

        # Supported set of python versions
        self.combo_version.setDisabled(True)

        r_types = [self.R]
        self.combo_r_type.clear()
        self.combo_r_type.addItems(r_types)
        self.combo_r_type.setCurrentIndex(0)
        self.combo_r_type.setEnabled(len(r_types) != 1)

        # Layouts
        layout_packages = QGridLayout()
        layout_packages.addWidget(self.check_python, 0, 0)
        layout_packages.addWidget(SpacerHorizontal(), 0, 1)
        layout_packages.addWidget(self.combo_version, 0, 2)
        layout_packages.addWidget(SpacerVertical(), 1, 0)
        layout_packages.addWidget(self.check_r, 2, 0)
        layout_packages.addWidget(SpacerHorizontal(), 2, 1)
        layout_packages.addWidget(self.combo_r_type, 2, 2)

        grid = QGridLayout()
        grid.addWidget(self.label_name, 0, 0, 1, 1)
        grid.addWidget(SpacerHorizontal(), 0, 1, 1, 1)
        grid.addWidget(self.text_name, 0, 2, 1, 4)
        grid.addWidget(SpacerVertical(), 1, 0, 1, 1)
        grid.addWidget(self.label_location, 2, 0, 1, 1)
        grid.addWidget(SpacerHorizontal(), 2, 1, 1, 1)
        grid.addWidget(self.label_prefix, 2, 2, 1, 4)
        grid.addWidget(SpacerVertical(), 3, 0, 1, 1)
        grid.addWidget(self.label_packages, 4, 0, 1, 1)
        grid.addWidget(SpacerHorizontal(), 4, 1, 1, 1)
        grid.addLayout(layout_packages, 4, 2, 3, 1)

        layout_buttons = QHBoxLayout()
        layout_buttons.addStretch()
        layout_buttons.addWidget(self.button_cancel)
        layout_buttons.addWidget(SpacerHorizontal())
        layout_buttons.addWidget(self.button_ok)

        main_layout = QVBoxLayout()
        main_layout.addLayout(grid)
        main_layout.addWidget(SpacerVertical())
        main_layout.addWidget(SpacerVertical())
        main_layout.addLayout(layout_buttons)

        self.setLayout(main_layout)

        # Signals
        self.button_ok.clicked.connect(self.accept)
        self.button_cancel.clicked.connect(self.reject)
        self.text_name.textChanged.connect(self.refresh)
        self.check_python.stateChanged.connect(self.refresh)
        self.check_r.stateChanged.connect(self.refresh)
        self.sig_setup_ready.connect(self.update_mro)
        self.sig_setup_ready.connect(self.update_pyversions)

        # Setup
        self.text_name.setFocus()
        self.check_python.setChecked(True)
        self.check_r.setChecked(False)
        self.refresh()

    def update_pyversions(self):
        """"""
        python_pks = self._packages.get('python', {})
        python_versions = python_pks.get('versions', [])
        pyvers = set(['.'.join(v.split('.')[:2]) for v in python_versions])

        final_pyvers = []
        for pyver in self.PYTHON_VERSIONS:
            if pyver in pyvers:
                final_pyvers.append(pyver)

        versions = self.PYTHON_VERSIONS
        now = "{}.{}".format(sys.version_info.major, sys.version_info.minor)
        if now not in final_pyvers:
            # Guard against non-standard version, or the coming 3.7
            final_pyvers.append(now)
            final_pyvers.sort()
        final_pyvers = list(reversed(final_pyvers))

        self.combo_version.addItems(final_pyvers)
        self.combo_version.setCurrentIndex(versions.index(now))
        self.combo_version.setEnabled(True)

    def update_mro(self):
        """"""
        # Operating systems with MRO support
        r_types = [self.R]
        if self.api:
            is_mro_available = self.api._conda_api.is_package_available(
                'mro-base',
                channels=self.channels,
            )

            if is_mro_available and BITS_64:
                if ((MAC and MAC_VERSION_INFO > self.MRO_MAC_MIN_VERSION)
                        or WIN or LINUX):
                    r_types = [self.MRO, self.R]

        self.combo_r_type.clear()
        self.combo_r_type.addItems(r_types)
        self.combo_r_type.setCurrentIndex(0)
        self.combo_r_type.setEnabled(len(r_types) != 1)

    def refresh(self, text=''):
        """Update status of buttons based on data."""
        name = self.name
        self.update_location()

        if self.environments:
            check = self.install_python or self.install_r
            if check and self.is_valid_env_name(name):
                self.button_ok.setDisabled(False)
            else:
                self.button_ok.setDisabled(True)
        self.combo_version.setEnabled(self.install_python)
        self.combo_r_type.setEnabled(self.install_r)

    @property
    def python_version(self):
        """Return the python version if python was selected for install."""
        version = None
        if self.install_python:
            version = self.combo_version.currentText()
        return version

    @property
    def install_python(self):
        """Return if python was selected for install."""
        return bool(self.check_python.checkState())

    @property
    def install_r(self):
        """Return if r was selected for install."""
        return bool(self.check_r.checkState())

    @property
    def r_type(self):
        """Return if r was selected for install."""
        return bool(self.combo_r_type.currentText())