--- a/Plugins/UiExtensionPlugins/PipInterface/PipFreezeDialog.py Tue Jun 12 18:59:45 2018 +0200 +++ b/Plugins/UiExtensionPlugins/PipInterface/PipFreezeDialog.py Tue Jun 12 19:01:06 2018 +0200 @@ -20,25 +20,26 @@ QApplication from E5Gui import E5MessageBox, E5FileDialog +from E5Gui.E5PathPicker import E5PathPickerModes from E5Gui.E5Application import e5App from .Ui_PipFreezeDialog import Ui_PipFreezeDialog import Utilities -import UI.PixmapCache class PipFreezeDialog(QDialog, Ui_PipFreezeDialog): """ Class implementing a dialog to generate a requirements file. """ - def __init__(self, pip, plugin, parent=None): + def __init__(self, pip, parent=None): """ Constructor - @param pip reference to the master object (Pip) - @param plugin reference to the plugin object (ToolPipPlugin) - @param parent reference to the parent widget (QWidget) + @param pip reference to the master object + @type Pip + @param parent reference to the parent widget + @type QWidget """ super(PipFreezeDialog, self).__init__(parent) self.setupUi(self) @@ -47,14 +48,14 @@ self.__refreshButton = self.buttonBox.addButton( self.tr("&Refresh"), QDialogButtonBox.ActionRole) - self.fileButton.setIcon(UI.PixmapCache.getIcon("open.png")) + self.requirementsFilePicker.setMode(E5PathPickerModes.OpenFileMode) + self.requirementsFilePicker.setFilters( + self.tr("Text Files (*.txt);;All Files (*)")) self.__pip = pip - self.__default = self.tr("<Default>") - pipExecutables = sorted(plugin.getPreferences("PipExecutables")) - self.pipComboBox.addItem(self.__default) - self.pipComboBox.addItems(pipExecutables) + self.venvComboBox.addItem(pip.getDefaultEnvironmentString()) + self.venvComboBox.addItems(pip.getVirtualenvNames()) self.__requirementsEdited = False self.__requirementsAvailable = False @@ -65,17 +66,19 @@ """ Protected slot implementing a close event handler. - @param e close event (QCloseEvent) + @param e close event + @type QCloseEvent """ QApplication.restoreOverrideCursor() e.accept() @pyqtSlot(str) - def on_pipComboBox_activated(self, txt): + def on_venvComboBox_activated(self, txt): """ - Private slot handling the selection of a pip executable. + Private slot handling the selection of a virtual environment. - @param txt path of the pip executable (string) + @param txt virtual environment + @type str """ self.__refresh() @@ -84,36 +87,22 @@ """ Private slot handling the switching of the local mode. - @param checked state of the local check box (boolean) + @param checked state of the local check box + @type bool """ self.__refresh() @pyqtSlot(str) - def on_requirementsFileEdit_textChanged(self, txt): + def on_requirementsFilePicker_textChanged(self, txt): """ Private slot handling a change of the requirements file name. - @param txt name of the requirements file (string) + @param txt name of the requirements file + @type str """ self.__updateButtons() @pyqtSlot() - def on_fileButton_clicked(self): - """ - Private slot to enter the requirements file via a file selection - dialog. - """ - fileName = E5FileDialog.getOpenFileName( - self, - self.tr("Select the requirements file"), - self.requirementsFileEdit.text() or os.path.expanduser("~"), - self.tr("Text Files (*.txt);;All Files (*)") - ) - if fileName: - self.requirementsFileEdit.setText( - Utilities.toNativeSeparators(fileName)) - - @pyqtSlot() def on_requirementsEdit_textChanged(self): """ Private slot handling changes of the requirements text. @@ -125,7 +114,8 @@ """ Private slot called by a button of the button box clicked. - @param button button that was clicked (QAbstractButton) + @param button button that was clicked + @type QAbstractButton """ if button == self.buttonBox.button(QDialogButtonBox.Close): self.close() @@ -154,23 +144,23 @@ self.requirementsEdit.clear() self.__requirementsAvailable = False - command = self.pipComboBox.currentText() - if command == self.__default: - command = "" + venvName = self.venvComboBox.currentText() + interpreter = self.__pip.getVirtualenvInterpreter(venvName) + if not interpreter: + return - args = ["freeze"] + args = ["-m", "pip", "freeze"] if self.localCheckBox.isChecked(): args.append("--local") - if self.requirementsFileEdit.text(): + if self.requirementsFilePicker.text(): fileName = Utilities.toNativeSeparators( - self.requirementsFileEdit.text()) + self.requirementsFilePicker.text()) if os.path.exists(fileName): args.append("--requirement") args.append(fileName) QApplication.setOverrideCursor(Qt.WaitCursor) - success, output = self.__pip.runProcess( - args, cmd=command) + success, output = self.__pip.runProcess(args, interpreter) if success: self.requirementsEdit.setPlainText(output) @@ -190,7 +180,7 @@ """ self.saveButton.setEnabled( self.__requirementsAvailable and - bool(self.requirementsFileEdit.text()) + bool(self.requirementsFilePicker.text()) ) self.saveToButton.setEnabled(self.__requirementsAvailable) self.copyButton.setEnabled(self.__requirementsAvailable) @@ -210,7 +200,8 @@ """ Private method to write the requirements text to a file. - @param fileName name of the file to write to (string) + @param fileName name of the file to write to + @type str """ if os.path.exists(fileName): ok = E5MessageBox.warning( @@ -238,7 +229,7 @@ """ Private slot to save the requirements text to the requirements file. """ - fileName = self.requirementsFileEdit.text() + fileName = self.requirementsFilePicker.text() self.__writeToFile(fileName) @pyqtSlot()