diff -r 48c3ca1ac264 -r ca89c7d94c94 CondaInterface/CondaPackagesWidget.py --- a/CondaInterface/CondaPackagesWidget.py Sun Feb 10 17:24:10 2019 +0100 +++ b/CondaInterface/CondaPackagesWidget.py Sun Feb 10 19:46:34 2019 +0100 @@ -9,12 +9,15 @@ from __future__ import unicode_literals +import os + from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtGui import QCursor from PyQt5.QtWidgets import QWidget, QToolButton, QMenu, QTreeWidgetItem, \ QApplication from E5Gui import E5MessageBox +from E5Gui.E5Application import e5App from .Ui_CondaPackagesWidget import Ui_CondaPackagesWidget @@ -93,10 +96,51 @@ menu button. """ self.__condaMenu = QMenu(self) - # TODO: implement Conda menu + self.__envActs = [] + + self.__cleanMenu = QMenu(self.tr("Clean"), self) + self.__cleanMenu.addAction( + self.tr("All"), lambda: self.__cleanMenuAction("all")) + self.__cleanMenu.addAction( + self.tr("Cache"), lambda: self.__cleanMenuAction("index-cache")) + self.__cleanMenu.addAction( + self.tr("Lock Files"), + lambda: self.__cleanMenuAction("lock")) + self.__cleanMenu.addAction( + self.tr("Packages"), lambda: self.__cleanMenuAction("packages")) + self.__cleanMenu.addAction( + self.tr("Tarballs"), lambda: self.__cleanMenuAction("tarballs")) + self.__cleanMenu.addAction( + self.tr("Temporary Files"), + lambda: self.__cleanMenuAction("temp_files")) + + self.__condaMenu.addAction( + self.tr("About Conda..."), self.__aboutConda) + self.__condaMenu.addSeparator() self.__condaMenu.addAction( self.tr("Update Conda"), self.__conda.updateConda) self.__condaMenu.addSeparator() + self.__envActs.append(self.__condaMenu.addAction( + self.tr("Install Packages"), self.__installPackages)) + self.__envActs.append(self.__condaMenu.addAction( + self.tr("Install Local Packages"), self.__installLocalPackage)) + self.__envActs.append(self.__condaMenu.addAction( + self.tr("Install Requirements"), self.__installRequirements)) + self.__condaMenu.addSeparator() + self.__envActs.append(self.__condaMenu.addAction( + self.tr("Generate Requirements"), self.__generateRequirements)) + self.__condaMenu.addSeparator() + self.__envActs.append(self.__condaMenu.addAction( + self.tr("Clone Environment"), self.__cloneEnvironment)) + self.__condaMenu.addSeparator() + self.__envActs.append(self.__condaMenu.addMenu(self.__cleanMenu)) + self.__condaMenu.addSeparator() + self.__condaMenu.addAction( + self.tr("Edit User Configuration..."), + self.__editUserConfiguration) + self.__condaMenu.addSeparator() + self.__condaMenu.addAction( + self.tr("Configure..."), self.__condaConfigure) self.condaMenuButton.setMenu(self.__condaMenu) @@ -154,16 +198,19 @@ QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() + # 1. populate with installed packages self.packagesList.setUpdatesEnabled(False) - # 1. populate with installed packages installedPackages = \ self.__conda.getInstalledPackages(prefix=prefix) for package, version, build in installedPackages: itm = QTreeWidgetItem(self.packagesList, [package, version]) itm.setData(1, self.PackageVersionRole, version) itm.setData(1, self.PackageBuildRole, build) + self.packagesList.setUpdatesEnabled(True) + QApplication.processEvents() # 2. update with update information + self.packagesList.setUpdatesEnabled(False) updateablePackages = \ self.__conda.getUpdateablePackages(prefix=prefix) for package, version, build in updateablePackages: @@ -186,7 +233,8 @@ )) self.packagesList.sortItems(0, Qt.AscendingOrder) - self.packagesList.resizeColumnToContents(0) + for col in range(self.packagesList.columnCount()): + self.packagesList.resizeColumnToContents(col) self.packagesList.setUpdatesEnabled(True) QApplication.restoreOverrideCursor() @@ -448,9 +496,115 @@ self.__updateSearchActionButtons() + ####################################################################### + ## Menu related methods below + ####################################################################### + @pyqtSlot() def __aboutToShowCondaMenu(self): """ Private slot to handle the conda menu about to be shown. """ selectedEnvironment = self.environmentsComboBox.currentText() + enable = selectedEnvironment not in [""] + for act in self.__envActs: + act.setEnabled(enable) + + @pyqtSlot() + def __aboutConda(self): + """ + Private slot to + """ + # TODO: implement this menu function + # conda info --all + infoDict = self.__conda.getCondaInformation() + + from .CondaInfoDialog import CondaInfoDialog + dlg = CondaInfoDialog(infoDict, self) + dlg.exec_() + + @pyqtSlot() + def __installPackages(self): + """ + Private slot to + """ + # TODO: implement this menu function + # conda install ... + + @pyqtSlot() + def __installLocalPackage(self): + """ + Private slot to + """ + # TODO: implement this menu function + # conda install --use-local + + @pyqtSlot() + def __installRequirements(self): + """ + Private slot to + """ + # TODO: implement this menu function + # conda install --file FILE1 --file FILE2 ... + + @pyqtSlot() + def __generateRequirements(self): + """ + Private slot to + """ + # TODO: implement this menu function + # conda list --export + + @pyqtSlot() + def __cloneEnvironment(self): + """ + Private slot to + """ + # TODO: implement this menu function + # conda create --clone ENV + + def __cleanMenuAction(self, cleanAction): + """ + Private method to + """ + # TODO: implement this menu function + # conda clean + # --all (act = 'all') + # --index-cache (act = 'index-cache') + # --lock (act = 'lock') + # --packages (act = 'packages') + # --tarballs (act = 'tarballs') + # -c prefix1 prefix2 ... (act = 'temp_files') + + @pyqtSlot() + def __editUserConfiguration(self): + """ + Private slot to edit the user configuration. + """ + from QScintilla.MiniEditor import MiniEditor + + cfgFile = CondaInterface.userConfiguration() + if not cfgFile: + return + + if not os.path.exists(cfgFile): + self.__conda.writeDefaultConfiguration() + + # check, if the destination is writeable + if not os.access(cfgFile, os.W_OK): + E5MessageBox.critical( + None, + self.tr("Edit Configuration"), + self.tr("""The configuration file "{0}" does not exist""" + """ or is not writable.""")) + return + + self.__editor = MiniEditor(cfgFile, "YAML") + self.__editor.show() + + @pyqtSlot() + def __condaConfigure(self): + """ + Private slot to open the configuration page. + """ + e5App().getObject("UserInterface").showPreferences("condaPage")