Conda, CondaPackagesWidget: continued implementing list functionality. conda

Wed, 06 Feb 2019 19:52:33 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 06 Feb 2019 19:52:33 +0100
branch
conda
changeset 6705
8cf1c3851b5c
parent 6704
772563b2eb0a
child 6706
d792e054cde2

Conda, CondaPackagesWidget: continued implementing list functionality.

CondaInterface/Conda.py file | annotate | diff | comparison | revisions
CondaInterface/CondaPackagesWidget.py file | annotate | diff | comparison | revisions
CondaInterface/CondaPackagesWidget.ui file | annotate | diff | comparison | revisions
--- a/CondaInterface/Conda.py	Wed Feb 06 19:35:51 2019 +0100
+++ b/CondaInterface/Conda.py	Wed Feb 06 19:52:33 2019 +0100
@@ -167,17 +167,13 @@
             
             return jsonDict["success"]
     
-    def getCondaEnvironmentsList(self, listPrefixes=False):
+    def getCondaEnvironmentsList(self):
         """
         Public method to get a list of all Conda environments.
         
-        @param listPrefixes flag indicating to return prefixes instead of names
-        @type bool
-        @return list of environment names or prefixes
-        @rtype list of str
+        @return list of tuples containing the environment name and prefix
+        @rtype list of tuples of (str, str)
         """
-        # TODO: return environment name and prefix
-        # TODO: return root environment only, if writable ('root_prefix', 'root_writable')
         exe = Preferences.getConda("CondaExecutable")
         if not exe:
             exe = "conda"
@@ -197,11 +193,16 @@
                     jsonDict = {}
                 
                 if "envs" in jsonDict:
-                    if listPrefixes:
-                        environmentsList = jsonDict["envs"][:]
-                    else:
-                        environmentsList = [
-                            os.path.basename(e) for e in jsonDict["envs"]]
+                    for prefix in jsonDict["envs"][:]:
+                        if prefix == jsonDict["root_prefix"]:
+                            if not jsonDict["root_writable"]:
+                                # root prefix is listed but not writable
+                                continue
+                            name = self.tr("<root>")
+                        else:
+                            name = os.path.basename(prefix)
+                        
+                        environmentsList.append((name, prefix))
         
         return environmentsList
     
@@ -250,7 +251,7 @@
         proc = QProcess()
         proc.start(exe, args)
         if proc.waitForStarted(15000):
-            if proc.waitForFinished(15000):
+            if proc.waitForFinished(30000):
                 output = str(proc.readAllStandardOutput(),
                              Preferences.getSystem("IOEncoding"),
                              'replace').strip()
@@ -315,7 +316,7 @@
         proc = QProcess()
         proc.start(exe, args)
         if proc.waitForStarted(15000):
-            if proc.waitForFinished(15000):
+            if proc.waitForFinished(30000):
                 output = str(proc.readAllStandardOutput(),
                              Preferences.getSystem("IOEncoding"),
                              'replace').strip()
--- a/CondaInterface/CondaPackagesWidget.py	Wed Feb 06 19:35:51 2019 +0100
+++ b/CondaInterface/CondaPackagesWidget.py	Wed Feb 06 19:52:33 2019 +0100
@@ -55,9 +55,10 @@
         """
         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))
+        environments = [("", "")] + sorted(
+            self.__conda.getCondaEnvironmentsList())
+        for environment in environments:
+            self.environmentsComboBox.addItem(environment[0], environment[1])
     
     def __initCondaMenu(self):
         """
@@ -66,7 +67,8 @@
         """
         self.__condaMenu = QMenu(self)
         # TODO: implement Conda menu
-        self.__condaMenu.addAction(self.tr("Test Entry"), self.on_refreshButton_clicked)
+        self.__condaMenu.addAction(self.tr("Test Entry"),
+                                   self.on_refreshButton_clicked)
         
         self.condaMenuButton.setMenu(self.__condaMenu)
     
@@ -108,34 +110,40 @@
         self.upgradeAllButton.setEnabled(
             bool(self.__allUpdateableItems()))
     
-    # TODO: change to int = index
-    @pyqtSlot(str)
-    def on_environmentsComboBox_currentIndexChanged(self, name):
+    @pyqtSlot(int)
+    def on_environmentsComboBox_currentIndexChanged(self, index):
         """
         Private slot handling the selection of a conda environment.
         
-        @param name name of the selected conda environment name
-        @type str
+        @param index index of the selected conda environment
+        @type int
         """
         self.packagesList.clear()
-        if name:
+        prefix = self.environmentsComboBox.itemData(index)
+        if prefix:
             QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
             QApplication.processEvents()
             
+            self.packagesList.setUpdatesEnabled(False)
             # 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])
+            installedPackages = \
+                self.__conda.getInstalledPackages(prefix=prefix)
+            for package, version, build in installedPackages:
+                itm = QTreeWidgetItem(self.packagesList, [package, version])
+                itm.setToolTip(1, self.tr("Build: {0}").format(build))
             
             # 2. update with update information
-            updateablePackages = self.__conda.getUpdateablePackages(name=name)
-            for package, version, build_ in updateablePackages:
+            updateablePackages = \
+                self.__conda.getUpdateablePackages(prefix=prefix)
+            for package, version, build in updateablePackages:
                 items = self.packagesList.findItems(
                     package, Qt.MatchExactly | Qt.MatchCaseSensitive)
                 if items:
                     items[0].setText(2, version)
+                    items[0].setToolTip(2, self.tr("Build: {0}").format(build))
             
+            self.packagesList.sortItems(0, Qt.AscendingOrder)
+            self.packagesList.setUpdatesEnabled(True)
             QApplication.restoreOverrideCursor()
         
         self.__updateActionButtons()
--- a/CondaInterface/CondaPackagesWidget.ui	Wed Feb 06 19:35:51 2019 +0100
+++ b/CondaInterface/CondaPackagesWidget.ui	Wed Feb 06 19:52:33 2019 +0100
@@ -35,9 +35,6 @@
      <property name="itemsExpandable">
       <bool>false</bool>
      </property>
-     <property name="sortingEnabled">
-      <bool>true</bool>
-     </property>
      <attribute name="headerDefaultSectionSize">
       <number>150</number>
      </attribute>

eric ide

mercurial