--- a/CondaInterface/CondaPackagesWidget.py Tue Feb 05 19:39:42 2019 +0100 +++ b/CondaInterface/CondaPackagesWidget.py Tue Feb 05 19:58:26 2019 +0100 @@ -9,10 +9,10 @@ from __future__ import unicode_literals -import os - from PyQt5.QtCore import pyqtSlot, Qt -from PyQt5.QtWidgets import QWidget, QToolButton, QMenu +from PyQt5.QtGui import QCursor +from PyQt5.QtWidgets import QWidget, QToolButton, QMenu, QTreeWidgetItem, \ + QApplication from .Ui_CondaPackagesWidget import Ui_CondaPackagesWidget @@ -23,16 +23,20 @@ """ Class implementing the conda packages management widget. """ - def __init__(self, parent=None): + 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")) @@ -45,19 +49,14 @@ self.__initCondaMenu() self.__populateEnvironments() + self.__updateActionButtons() def __populateEnvironments(self): """ Private method to get a list of environments and populate the selector. """ - # TODO: replace this by the real stuff - envs = [ - "path/to/envs/sqlite", - "path/to/envs/pyqt4", - "path/to/envs/pyqt5", - ] - - environmentNames = [os.path.basename(e) for e in envs] + # TODO: populate with name and prefix + environmentNames = [""] + self.__conda.getCondaEnvironmentsList() self.environmentsComboBox.addItems(sorted(environmentNames)) def __initCondaMenu(self): @@ -71,32 +70,104 @@ self.condaMenuButton.setMenu(self.__condaMenu) - @pyqtSlot(str) - def on_environmentsComboBox_activated(self, p0): + 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 """ - Slot documentation goes here. + updateableItems = [] + for index in range(self.packagesList.topLevelItemCount()): + itm = self.packagesList.topLevelItem(index) + if itm.text(2): + updateableItems.append(itm) - @param p0 DESCRIPTION + 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 """ - # TODO: not implemented yet - raise NotImplementedError + 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): """ - Slot documentation goes here. + Private slot to handle the selection of some items.. """ - # TODO: not implemented yet - raise NotImplementedError + self.__updateActionButtons() @pyqtSlot() def on_refreshButton_clicked(self): """ - Slot documentation goes here. + Private slot to refresh the display. """ - # TODO: not implemented yet - raise NotImplementedError + 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):