Tue, 05 Feb 2019 19:58:26 +0100
Conda, CondaPackagesWidget: continued implementing list functionality.
# -*- coding: utf-8 -*- # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the conda packages management widget. """ from __future__ import unicode_literals from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtGui import QCursor from PyQt5.QtWidgets import QWidget, QToolButton, QMenu, QTreeWidgetItem, \ QApplication from .Ui_CondaPackagesWidget import Ui_CondaPackagesWidget import UI.PixmapCache class CondaPackagesWidget(QWidget, Ui_CondaPackagesWidget): """ Class implementing the conda packages management widget. """ def __init__(self, conda, parent=None): """ Constructor @param conda reference to the conda interface @type Conda @param parent reference to the parent widget @type QWidget """ super(CondaPackagesWidget, self).__init__(parent) self.setupUi(self) self.__conda = conda self.condaMenuButton.setObjectName( "navigation_supermenu_button") self.condaMenuButton.setIcon(UI.PixmapCache.getIcon("superMenu.png")) self.condaMenuButton.setToolTip(self.tr("Conda Menu")) self.condaMenuButton.setPopupMode(QToolButton.InstantPopup) self.condaMenuButton.setToolButtonStyle(Qt.ToolButtonIconOnly) self.condaMenuButton.setFocusPolicy(Qt.NoFocus) self.condaMenuButton.setAutoRaise(True) self.condaMenuButton.setShowMenuInside(True) self.__initCondaMenu() self.__populateEnvironments() self.__updateActionButtons() def __populateEnvironments(self): """ Private method to get a list of environments and populate the selector. """ # TODO: populate with name and prefix environmentNames = [""] + self.__conda.getCondaEnvironmentsList() self.environmentsComboBox.addItems(sorted(environmentNames)) def __initCondaMenu(self): """ Private method to create the super menu and attach it to the super menu button. """ self.__condaMenu = QMenu(self) # TODO: implement Conda menu self.__condaMenu.addAction(self.tr("Test Entry"), self.on_refreshButton_clicked) self.condaMenuButton.setMenu(self.__condaMenu) def __selectedUpdateableItems(self): """ Private method to get a list of selected items that can be updated. @return list of selected items that can be updated @rtype list of QTreeWidgetItem """ return [ itm for itm in self.packagesList.selectedItems() if bool(itm.text(2)) ] def __allUpdateableItems(self): """ Private method to get a list of all items that can be updated. @return list of all items that can be updated @rtype list of QTreeWidgetItem """ updateableItems = [] for index in range(self.packagesList.topLevelItemCount()): itm = self.packagesList.topLevelItem(index) if itm.text(2): updateableItems.append(itm) return updateableItems def __updateActionButtons(self): """ Private method to set the state of the action buttons. """ self.upgradeButton.setEnabled( bool(self.__selectedUpdateableItems())) self.uninstallButton.setEnabled( bool(self.packagesList.selectedItems())) self.upgradeAllButton.setEnabled( bool(self.__allUpdateableItems())) # TODO: change to int = index @pyqtSlot(str) def on_environmentsComboBox_currentIndexChanged(self, name): """ Private slot handling the selection of a conda environment. @param name name of the selected conda environment name @type str """ self.packagesList.clear() if name: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() # 1. populate with installed packages # TODO: use prefix installedPackages = self.__conda.getInstalledPackages(name=name) for package, version, build_ in installedPackages: QTreeWidgetItem(self.packagesList, [package, version]) # 2. update with update information updateablePackages = self.__conda.getUpdateablePackages(name=name) for package, version, build_ in updateablePackages: items = self.packagesList.findItems( package, Qt.MatchExactly | Qt.MatchCaseSensitive) if items: items[0].setText(2, version) QApplication.restoreOverrideCursor() self.__updateActionButtons() @pyqtSlot() def on_packagesList_itemSelectionChanged(self): """ Private slot to handle the selection of some items.. """ self.__updateActionButtons() @pyqtSlot() def on_refreshButton_clicked(self): """ Private slot to refresh the display. """ currentEnvironment = self.environmentsComboBox.currentText() self.environmentsComboBox.clear() self.packagesList.clear() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() self.__populateEnvironments() index = self.environmentsComboBox.findText( currentEnvironment, Qt.MatchExactly | Qt.MatchCaseSensitive) if index != -1: self.environmentsComboBox.setCurrentIndex(index) QApplication.restoreOverrideCursor() self.__updateActionButtons() @pyqtSlot() def on_upgradeButton_clicked(self): """ Slot documentation goes here. """ # TODO: not implemented yet raise NotImplementedError @pyqtSlot() def on_upgradeAllButton_clicked(self): """ Slot documentation goes here. """ # TODO: not implemented yet raise NotImplementedError @pyqtSlot() def on_uninstallButton_clicked(self): """ Slot documentation goes here. """ # TODO: not implemented yet raise NotImplementedError