18 from PyQt5.QtCore import pyqtSlot, Qt |
18 from PyQt5.QtCore import pyqtSlot, Qt |
19 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton, \ |
19 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton, \ |
20 QApplication |
20 QApplication |
21 |
21 |
22 from E5Gui import E5MessageBox, E5FileDialog |
22 from E5Gui import E5MessageBox, E5FileDialog |
|
23 from E5Gui.E5PathPicker import E5PathPickerModes |
23 from E5Gui.E5Application import e5App |
24 from E5Gui.E5Application import e5App |
24 |
25 |
25 from .Ui_PipFreezeDialog import Ui_PipFreezeDialog |
26 from .Ui_PipFreezeDialog import Ui_PipFreezeDialog |
26 |
27 |
27 import Utilities |
28 import Utilities |
28 import UI.PixmapCache |
|
29 |
29 |
30 |
30 |
31 class PipFreezeDialog(QDialog, Ui_PipFreezeDialog): |
31 class PipFreezeDialog(QDialog, Ui_PipFreezeDialog): |
32 """ |
32 """ |
33 Class implementing a dialog to generate a requirements file. |
33 Class implementing a dialog to generate a requirements file. |
34 """ |
34 """ |
35 def __init__(self, pip, plugin, parent=None): |
35 def __init__(self, pip, parent=None): |
36 """ |
36 """ |
37 Constructor |
37 Constructor |
38 |
38 |
39 @param pip reference to the master object (Pip) |
39 @param pip reference to the master object |
40 @param plugin reference to the plugin object (ToolPipPlugin) |
40 @type Pip |
41 @param parent reference to the parent widget (QWidget) |
41 @param parent reference to the parent widget |
|
42 @type QWidget |
42 """ |
43 """ |
43 super(PipFreezeDialog, self).__init__(parent) |
44 super(PipFreezeDialog, self).__init__(parent) |
44 self.setupUi(self) |
45 self.setupUi(self) |
45 self.setWindowFlags(Qt.Window) |
46 self.setWindowFlags(Qt.Window) |
46 |
47 |
47 self.__refreshButton = self.buttonBox.addButton( |
48 self.__refreshButton = self.buttonBox.addButton( |
48 self.tr("&Refresh"), QDialogButtonBox.ActionRole) |
49 self.tr("&Refresh"), QDialogButtonBox.ActionRole) |
49 |
50 |
50 self.fileButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
51 self.requirementsFilePicker.setMode(E5PathPickerModes.OpenFileMode) |
|
52 self.requirementsFilePicker.setFilters( |
|
53 self.tr("Text Files (*.txt);;All Files (*)")) |
51 |
54 |
52 self.__pip = pip |
55 self.__pip = pip |
53 |
56 |
54 self.__default = self.tr("<Default>") |
57 self.venvComboBox.addItem(pip.getDefaultEnvironmentString()) |
55 pipExecutables = sorted(plugin.getPreferences("PipExecutables")) |
58 self.venvComboBox.addItems(pip.getVirtualenvNames()) |
56 self.pipComboBox.addItem(self.__default) |
|
57 self.pipComboBox.addItems(pipExecutables) |
|
58 |
59 |
59 self.__requirementsEdited = False |
60 self.__requirementsEdited = False |
60 self.__requirementsAvailable = False |
61 self.__requirementsAvailable = False |
61 |
62 |
62 self.__updateButtons() |
63 self.__updateButtons() |
63 |
64 |
64 def closeEvent(self, e): |
65 def closeEvent(self, e): |
65 """ |
66 """ |
66 Protected slot implementing a close event handler. |
67 Protected slot implementing a close event handler. |
67 |
68 |
68 @param e close event (QCloseEvent) |
69 @param e close event |
|
70 @type QCloseEvent |
69 """ |
71 """ |
70 QApplication.restoreOverrideCursor() |
72 QApplication.restoreOverrideCursor() |
71 e.accept() |
73 e.accept() |
72 |
74 |
73 @pyqtSlot(str) |
75 @pyqtSlot(str) |
74 def on_pipComboBox_activated(self, txt): |
76 def on_venvComboBox_activated(self, txt): |
75 """ |
77 """ |
76 Private slot handling the selection of a pip executable. |
78 Private slot handling the selection of a virtual environment. |
77 |
79 |
78 @param txt path of the pip executable (string) |
80 @param txt virtual environment |
|
81 @type str |
79 """ |
82 """ |
80 self.__refresh() |
83 self.__refresh() |
81 |
84 |
82 @pyqtSlot(bool) |
85 @pyqtSlot(bool) |
83 def on_localCheckBox_clicked(self, checked): |
86 def on_localCheckBox_clicked(self, checked): |
84 """ |
87 """ |
85 Private slot handling the switching of the local mode. |
88 Private slot handling the switching of the local mode. |
86 |
89 |
87 @param checked state of the local check box (boolean) |
90 @param checked state of the local check box |
|
91 @type bool |
88 """ |
92 """ |
89 self.__refresh() |
93 self.__refresh() |
90 |
94 |
91 @pyqtSlot(str) |
95 @pyqtSlot(str) |
92 def on_requirementsFileEdit_textChanged(self, txt): |
96 def on_requirementsFilePicker_textChanged(self, txt): |
93 """ |
97 """ |
94 Private slot handling a change of the requirements file name. |
98 Private slot handling a change of the requirements file name. |
95 |
99 |
96 @param txt name of the requirements file (string) |
100 @param txt name of the requirements file |
|
101 @type str |
97 """ |
102 """ |
98 self.__updateButtons() |
103 self.__updateButtons() |
99 |
|
100 @pyqtSlot() |
|
101 def on_fileButton_clicked(self): |
|
102 """ |
|
103 Private slot to enter the requirements file via a file selection |
|
104 dialog. |
|
105 """ |
|
106 fileName = E5FileDialog.getOpenFileName( |
|
107 self, |
|
108 self.tr("Select the requirements file"), |
|
109 self.requirementsFileEdit.text() or os.path.expanduser("~"), |
|
110 self.tr("Text Files (*.txt);;All Files (*)") |
|
111 ) |
|
112 if fileName: |
|
113 self.requirementsFileEdit.setText( |
|
114 Utilities.toNativeSeparators(fileName)) |
|
115 |
104 |
116 @pyqtSlot() |
105 @pyqtSlot() |
117 def on_requirementsEdit_textChanged(self): |
106 def on_requirementsEdit_textChanged(self): |
118 """ |
107 """ |
119 Private slot handling changes of the requirements text. |
108 Private slot handling changes of the requirements text. |
152 Public method to start the command. |
142 Public method to start the command. |
153 """ |
143 """ |
154 self.requirementsEdit.clear() |
144 self.requirementsEdit.clear() |
155 self.__requirementsAvailable = False |
145 self.__requirementsAvailable = False |
156 |
146 |
157 command = self.pipComboBox.currentText() |
147 venvName = self.venvComboBox.currentText() |
158 if command == self.__default: |
148 interpreter = self.__pip.getVirtualenvInterpreter(venvName) |
159 command = "" |
149 if not interpreter: |
160 |
150 return |
161 args = ["freeze"] |
151 |
|
152 args = ["-m", "pip", "freeze"] |
162 if self.localCheckBox.isChecked(): |
153 if self.localCheckBox.isChecked(): |
163 args.append("--local") |
154 args.append("--local") |
164 if self.requirementsFileEdit.text(): |
155 if self.requirementsFilePicker.text(): |
165 fileName = Utilities.toNativeSeparators( |
156 fileName = Utilities.toNativeSeparators( |
166 self.requirementsFileEdit.text()) |
157 self.requirementsFilePicker.text()) |
167 if os.path.exists(fileName): |
158 if os.path.exists(fileName): |
168 args.append("--requirement") |
159 args.append("--requirement") |
169 args.append(fileName) |
160 args.append(fileName) |
170 |
161 |
171 QApplication.setOverrideCursor(Qt.WaitCursor) |
162 QApplication.setOverrideCursor(Qt.WaitCursor) |
172 success, output = self.__pip.runProcess( |
163 success, output = self.__pip.runProcess(args, interpreter) |
173 args, cmd=command) |
|
174 |
164 |
175 if success: |
165 if success: |
176 self.requirementsEdit.setPlainText(output) |
166 self.requirementsEdit.setPlainText(output) |
177 self.__requirementsAvailable = True |
167 self.__requirementsAvailable = True |
178 else: |
168 else: |