PipInterface/PipPackagesWidget.py

branch
pypi
changeset 6785
058d63c537a4
child 6792
9dd854f05c83
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PipInterface/PipPackagesWidget.py	Mon Feb 18 19:49:43 2019 +0100
@@ -0,0 +1,159 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the pip 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, QApplication
+
+from .Ui_PipPackagesWidget import Ui_PipPackagesWidget
+
+import UI.PixmapCache
+
+from .Pip import Pip
+
+
+class PipPackagesWidget(QWidget, Ui_PipPackagesWidget):
+    """
+    Class documentation goes here.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget
+        @type QWidget
+        """
+        super(PipPackagesWidget, self).__init__(parent)
+        self.setupUi(self)
+        
+        self.pipMenuButton.setObjectName(
+            "navigation_supermenu_button")
+        self.pipMenuButton.setIcon(UI.PixmapCache.getIcon("superMenu"))
+        self.pipMenuButton.setToolTip(self.tr("pip Menu"))
+        self.pipMenuButton.setPopupMode(QToolButton.InstantPopup)
+        self.pipMenuButton.setToolButtonStyle(Qt.ToolButtonIconOnly)
+        self.pipMenuButton.setFocusPolicy(Qt.NoFocus)
+        self.pipMenuButton.setAutoRaise(True)
+        self.pipMenuButton.setShowMenuInside(True)
+        
+        self.searchToggleButton.setIcon(UI.PixmapCache.getIcon("find"))
+        
+        self.__pip = Pip(self)
+        
+        self.__initPipMenu()
+        self.__populateEnvironments()
+        self.__updateActionButtons()
+        
+        self.statusLabel.hide()
+        self.searchWidget.hide()
+        
+    def __initPipMenu(self):
+        """
+        Private method to create the super menu and attach it to the super
+        menu button.
+        """
+        self.__pip.initActions()
+        
+        self.__pipMenu = self.__pip.initMenu()
+        
+        self.pipMenuButton.setMenu(self.__pipMenu)
+    
+    def __populateEnvironments(self):
+        """
+        Private method to get a list of environments and populate the selector.
+        """
+        self.environmentsComboBox.addItem("")
+        projectVenv = self.__pip.getProjectEnvironmentString()
+        if projectVenv:
+            self.environmentsComboBox.addItem(projectVenv)
+        self.environmentsComboBox.addItems(self.__pip.getVirtualenvNames())
+    
+    def __updateActionButtons(self):
+        """
+        Private method to set the state of the action buttons.
+        """
+        # TODO: not yet implemented
+        pass
+    
+    #######################################################################
+    ## Slots handling widget signals below
+    #######################################################################
+    
+    @pyqtSlot(int)
+    def on_environmentsComboBox_currentIndexChanged(self, index):
+        """
+        Private slot handling the selection of a conda environment.
+        
+        @param index index of the selected conda environment
+        @type int
+        """
+        self.packagesList.clear()
+        venvName = self.environmentsComboBox.currentText()
+        if venvName:
+            interpreter = self.__pip.getVirtualenvInterpreter(venvName)
+            if interpreter:
+                QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
+                self.statusLabel.show()
+                self.statusLabel.setText(
+                    self.tr("Getting installed packages..."))
+                QApplication.processEvents()
+                
+                # 1. populate with installed packages
+                pass    # TODO: add code to list installed
+                
+                # 2. update with update information
+                pass    # TODO: add code to list outdated
+                
+                self.packagesList.sortItems(0, Qt.AscendingOrder)
+                for col in range(self.packagesList.columnCount()):
+                    self.packagesList.resizeColumnToContents(col)
+                self.packagesList.setUpdatesEnabled(True)
+                QApplication.restoreOverrideCursor()
+                self.statusLabel.hide()
+        
+        self.__updateActionButtons()
+        self.__updateSearchActionButtons()
+    
+    #######################################################################
+    ## Search widget related methods below
+    #######################################################################
+    
+    def __updateSearchActionButtons(self):
+        """
+        Private method to update the action button states of the search widget.
+        """
+        # TODO: adjust this like search dialog
+        enable = len(self.searchResultList.selectedItems()) == 1
+        self.installButton.setEnabled(
+            enable and self.environmentsComboBox.currentIndex() > 0)
+        self.showDetailsButton.setEnabled(
+            enable and bool(self.searchResultList.selectedItems()[0].parent()))
+    
+    @pyqtSlot(bool)
+    def on_searchToggleButton_toggled(self, checked):
+        """
+        Private slot to togle the search widget.
+        
+        @param checked state of the search widget button
+        @type bool
+        """
+        self.searchWidget.setVisible(checked)
+        
+        if checked:
+            self.searchEdit.setFocus(Qt.OtherFocusReason)
+            self.searchEdit.selectAll()
+            
+            self.__updateSearchActionButtons()
+    
+    #######################################################################
+    ## Menu related methods below
+    #######################################################################
+    

eric ide

mercurial