src/eric7/Project/ProjectVenvConfigurationDialog.py

branch
eric7
changeset 9323
6ae7193558ac
child 9389
7b2344009d7a
equal deleted inserted replaced
9322:3f0fe9a79aa1 9323:6ae7193558ac
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the configuration for the embedded environment
8 of the project.
9 """
10
11 import glob
12 import os
13
14 from PyQt6.QtCore import pyqtSlot
15 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
16
17 from EricWidgets.EricPathPicker import EricPathPickerModes
18
19 from .Ui_ProjectVenvConfigurationDialog import Ui_ProjectVenvConfigurationDialog
20
21 import Globals
22
23
24 class ProjectVenvConfigurationDialog(QDialog, Ui_ProjectVenvConfigurationDialog):
25 """
26 Class implementing a dialog to enter the configuration for the embedded
27 environment of the project.
28 """
29
30 def __init__(
31 self,
32 venvName="",
33 venvDirectory="",
34 venvInterpreter="",
35 execPath="",
36 parent=None,
37 ):
38 """
39 Constructor
40
41 @param venvName logical name of a virtual environment for editing
42 @type str
43 @param venvDirectory directory of the virtual environment
44 @type str
45 @param venvInterpreter Python interpreter of the virtual environment
46 @type str
47 @param execPath search path string to be prepended to the PATH
48 environment variable
49 @type str
50 @param parent reference to the parent widget (defaults to None)
51 @type QWidget (optional)
52 """
53 super().__init__(parent)
54 self.setupUi(self)
55
56 self.__venvName = venvName
57
58 self.pythonExecPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
59 self.pythonExecPicker.setWindowTitle(self.tr("Python Interpreter"))
60 self.pythonExecPicker.setDefaultDirectory(venvDirectory)
61
62 self.execPathEdit.setToolTip(
63 self.tr(
64 "Enter the executable search path to be prepended to the PATH"
65 " environment variable. Use '{0}' as the separator."
66 ).format(os.pathsep)
67 )
68
69 self.nameEdit.setText(venvName)
70 self.execPathEdit.setText(execPath)
71
72 if venvDirectory:
73 # try to determine a Python interpreter name
74 if Globals.isWindowsPlatform():
75 candidates = glob.glob(
76 os.path.join(venvDirectory, "Scripts", "python*.exe")
77 ) + glob.glob(os.path.join(venvDirectory, "python*.exe"))
78 else:
79 candidates = glob.glob(os.path.join(venvDirectory, "bin", "python*"))
80 self.pythonExecPicker.addItems(sorted(candidates))
81
82 if venvInterpreter:
83 self.pythonExecPicker.setText(venvInterpreter)
84 else:
85 self.pythonExecPicker.setText(venvDirectory)
86
87 @pyqtSlot(str)
88 def __updateOK(self):
89 """
90 Private method to update the enabled status of the OK button.
91 """
92 interpreterPath = self.pythonExecPicker.text()
93 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
94 bool(interpreterPath)
95 and os.path.isfile(interpreterPath)
96 and os.access(interpreterPath, os.X_OK)
97 )
98
99 @pyqtSlot(str)
100 def on_pythonExecPicker_textChanged(self, txt):
101 """
102 Private slot to handle changes of the entered Python interpreter path.
103
104 @param txt entered Python interpreter path
105 @type str
106 """
107 self.__updateOK()
108
109 def getData(self):
110 """
111 Public method to get the entered data.
112
113 @return tuple containing the path of the selected Python interpreter and
114 a string to be prepended to the PATH environment variable
115 @rtype tuple of (str, str)
116 """
117 return self.pythonExecPicker.text(), self.execPathEdit.text()

eric ide

mercurial