14 |
14 |
15 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
15 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
16 from eric7.SystemUtilities import OSUtilities, PythonUtilities |
16 from eric7.SystemUtilities import OSUtilities, PythonUtilities |
17 |
17 |
18 from .Ui_VirtualenvAddEditDialog import Ui_VirtualenvAddEditDialog |
18 from .Ui_VirtualenvAddEditDialog import Ui_VirtualenvAddEditDialog |
|
19 from .VirtualenvMeta import VirtualenvMetaData |
19 |
20 |
20 |
21 |
21 class VirtualenvAddEditDialog(QDialog, Ui_VirtualenvAddEditDialog): |
22 class VirtualenvAddEditDialog(QDialog, Ui_VirtualenvAddEditDialog): |
22 """ |
23 """ |
23 Class implementing a dialog to enter the data of a virtual environment. |
24 Class implementing a dialog to enter the data of a virtual environment. |
24 """ |
25 """ |
25 |
26 |
26 def __init__( |
27 def __init__( |
27 self, |
28 self, |
28 manager, |
29 manager, |
29 venvName="", |
30 metadata=None, |
30 venvDirectory="", |
|
31 venvInterpreter="", |
|
32 isGlobal=False, |
|
33 isConda=False, |
|
34 isRemote=False, |
|
35 execPath="", |
|
36 description="", |
|
37 baseDir="", |
31 baseDir="", |
38 parent=None, |
32 parent=None, |
39 ): |
33 ): |
40 """ |
34 """ |
41 Constructor |
35 Constructor |
42 |
36 |
43 @param manager reference to the virtual environment manager |
37 @param manager reference to the virtual environment manager |
44 @type VirtualenvManager |
38 @type VirtualenvManager |
45 @param venvName logical name of a virtual environment for editing |
39 @param metadata object containing the metadata of the virtual environment |
46 @type str |
40 (defaults to None) |
47 @param venvDirectory directory of the virtual environment |
41 @type VirtualenvMetaData (optional) |
48 @type str |
42 @param baseDir base directory for the virtual environments (defaults to "") |
49 @param venvInterpreter Python interpreter of the virtual environment |
43 @type str (optional) |
50 @type str |
44 @param parent reference to the parent widget (defaults to None) |
51 @param isGlobal flag indicating a global environment |
45 @type QWidget (optional) |
52 @type bool |
|
53 @param isConda flag indicating an Anaconda virtual environment |
|
54 @type bool |
|
55 @param isRemote flag indicating a remotely accessed environment |
|
56 @type bool |
|
57 @param execPath search path string to be prepended to the PATH |
|
58 environment variable |
|
59 @type str |
|
60 @param description descriptive text for the environment |
|
61 @type str |
|
62 @param baseDir base directory for the virtual environments |
|
63 @type str |
|
64 @param parent reference to the parent widget |
|
65 @type QWidget |
|
66 """ |
46 """ |
67 super().__init__(parent) |
47 super().__init__(parent) |
68 self.setupUi(self) |
48 self.setupUi(self) |
69 |
49 |
70 self.__venvName = venvName |
50 self.__venvName = "" if metadata is None else metadata.name |
71 self.__manager = manager |
51 self.__manager = manager |
72 self.__editMode = bool(venvName) |
52 self.__editMode = bool(self.__venvName) |
73 |
53 |
74 if self.__editMode: |
54 if self.__editMode: |
75 self.setWindowTitle(self.tr("Edit Virtual Environment")) |
55 self.setWindowTitle(self.tr("Edit Virtual Environment")) |
76 else: |
56 else: |
77 self.setWindowTitle(self.tr("Add Virtual Environment")) |
57 self.setWindowTitle(self.tr("Add Virtual Environment")) |
95 "Enter the executable search path to be prepended to the PATH" |
75 "Enter the executable search path to be prepended to the PATH" |
96 " environment variable. Use '{0}' as the separator." |
76 " environment variable. Use '{0}' as the separator." |
97 ).format(os.pathsep) |
77 ).format(os.pathsep) |
98 ) |
78 ) |
99 |
79 |
100 self.nameEdit.setText(venvName) |
80 self.nameEdit.setText(self.__venvName) |
101 if venvDirectory: |
81 if metadata: |
102 self.targetDirectoryPicker.setText(venvDirectory, toNative=not isRemote) |
82 if metadata.path: |
|
83 self.targetDirectoryPicker.setText( |
|
84 metadata.path, toNative=not metadata.is_remote |
|
85 ) |
|
86 else: |
|
87 self.targetDirectoryPicker.setText( |
|
88 self.__envBaseDir, toNative=not metadata.is_remote |
|
89 ) |
|
90 if not metadata.interpreter and metadata.path and not metadata.is_remote: |
|
91 py = self.__detectPythonInterpreter(metadata.path) |
|
92 self.pythonExecPicker.setText(py) |
|
93 else: |
|
94 self.pythonExecPicker.setText( |
|
95 metadata.interpreter, toNative=not metadata.is_remote |
|
96 ) |
103 else: |
97 else: |
104 self.targetDirectoryPicker.setText(self.__envBaseDir, toNative=not isRemote) |
98 self.targetDirectoryPicker.setText(self.__envBaseDir, toNative=True) |
105 if not venvInterpreter and venvDirectory and not isRemote: |
99 |
106 py = self.__detectPythonInterpreter(venvDirectory) |
100 self.globalCheckBox.setChecked(metadata.is_global if metadata else False) |
107 self.pythonExecPicker.setText(py) |
101 self.anacondaCheckBox.setChecked(metadata.is_conda if metadata else False) |
108 else: |
102 self.remoteCheckBox.setChecked(metadata.is_remote if metadata else False) |
109 self.pythonExecPicker.setText(venvInterpreter, toNative=not isRemote) |
103 self.execPathEdit.setText(metadata.exec_path if metadata else "") |
110 |
104 self.descriptionEdit.setPlainText(metadata.description if metadata else "") |
111 self.globalCheckBox.setChecked(isGlobal) |
|
112 self.anacondaCheckBox.setChecked(isConda) |
|
113 self.remoteCheckBox.setChecked(isRemote) |
|
114 self.execPathEdit.setText(execPath) |
|
115 self.descriptionEdit.setPlainText(description) |
|
116 |
105 |
117 self.__updateOk() |
106 self.__updateOk() |
118 |
107 |
119 self.nameEdit.setFocus(Qt.FocusReason.OtherFocusReason) |
108 self.nameEdit.setFocus(Qt.FocusReason.OtherFocusReason) |
120 |
109 |
265 else: |
254 else: |
266 self.execPathEdit.setText( |
255 self.execPathEdit.setText( |
267 os.path.join(self.targetDirectoryPicker.text(), "bin"), |
256 os.path.join(self.targetDirectoryPicker.text(), "bin"), |
268 ) |
257 ) |
269 |
258 |
270 def getData(self): |
259 def getMetaData(self): |
271 """ |
260 """ |
272 Public method to retrieve the entered data. |
261 Public method to retrieve the entered metadata. |
273 |
262 |
274 @return tuple containing the logical name, the directory, the interpreter of the |
263 @return metadata for the virtual environment |
275 virtual environment, a flag indicating a global environment, a flag |
264 @rtype VirtualenvMetaData |
276 indicating an Anaconda environment, a flag indicating a remotely accessed |
|
277 environment, a string to be prepended to the PATH environment variable and |
|
278 a descriptive text |
|
279 @rtype tuple of (str, str, str, bool, bool, bool, str, str) |
|
280 """ |
265 """ |
281 nativePaths = not self.remoteCheckBox.isChecked() |
266 nativePaths = not self.remoteCheckBox.isChecked() |
282 return ( |
267 return VirtualenvMetaData( |
283 self.nameEdit.text(), |
268 name=self.nameEdit.text(), |
284 self.targetDirectoryPicker.text(toNative=nativePaths), |
269 path=self.targetDirectoryPicker.text(toNative=nativePaths), |
285 self.pythonExecPicker.text(toNative=nativePaths), |
270 interpreter=self.pythonExecPicker.text(toNative=nativePaths), |
286 self.globalCheckBox.isChecked(), |
271 is_global=self.globalCheckBox.isChecked(), |
287 self.anacondaCheckBox.isChecked(), |
272 is_conda=self.anacondaCheckBox.isChecked(), |
288 self.remoteCheckBox.isChecked(), |
273 is_remote=self.remoteCheckBox.isChecked(), |
289 self.execPathEdit.text(), |
274 exec_path=self.execPathEdit.text(), |
290 self.descriptionEdit.toPlainText(), |
275 description=self.descriptionEdit.toPlainText(), |
291 ) |
276 ) |