src/eric7/VirtualEnv/VirtualenvInterpreterSelectionDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9321
3cca871d0be1
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
15 from PyQt6.QtWidgets import QDialog, QDialogButtonBox 15 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
16 16
17 from EricWidgets.EricPathPicker import EricPathPickerModes 17 from EricWidgets.EricPathPicker import EricPathPickerModes
18 18
19 from .Ui_VirtualenvInterpreterSelectionDialog import ( 19 from .Ui_VirtualenvInterpreterSelectionDialog import (
20 Ui_VirtualenvInterpreterSelectionDialog 20 Ui_VirtualenvInterpreterSelectionDialog,
21 ) 21 )
22 22
23 import Globals 23 import Globals
24 24
25 25
26 class VirtualenvInterpreterSelectionDialog( 26 class VirtualenvInterpreterSelectionDialog(
27 QDialog, Ui_VirtualenvInterpreterSelectionDialog): 27 QDialog, Ui_VirtualenvInterpreterSelectionDialog
28 ):
28 """ 29 """
29 Class implementing a dialog to enter the interpreter for a virtual 30 Class implementing a dialog to enter the interpreter for a virtual
30 environment. 31 environment.
31 """ 32 """
33
32 def __init__(self, venvName, venvDirectory, parent=None): 34 def __init__(self, venvName, venvDirectory, parent=None):
33 """ 35 """
34 Constructor 36 Constructor
35 37
36 @param venvName name for the virtual environment 38 @param venvName name for the virtual environment
37 @type str 39 @type str
38 @param venvDirectory directory of the virtual environment 40 @param venvDirectory directory of the virtual environment
39 @type str 41 @type str
40 @param parent reference to the parent widget 42 @param parent reference to the parent widget
41 @type QWidget 43 @type QWidget
42 """ 44 """
43 super().__init__(parent) 45 super().__init__(parent)
44 self.setupUi(self) 46 self.setupUi(self)
45 47
46 self.pythonExecPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) 48 self.pythonExecPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
47 self.pythonExecPicker.setWindowTitle( 49 self.pythonExecPicker.setWindowTitle(self.tr("Python Interpreter"))
48 self.tr("Python Interpreter")) 50
49
50 self.nameEdit.setText(venvName) 51 self.nameEdit.setText(venvName)
51 52
52 if venvDirectory: 53 if venvDirectory:
53 # try to determine a Python interpreter name 54 # try to determine a Python interpreter name
54 if Globals.isWindowsPlatform(): 55 if Globals.isWindowsPlatform():
55 candidates = glob.glob( 56 candidates = glob.glob(
56 os.path.join(venvDirectory, "Scripts", "python*.exe") 57 os.path.join(venvDirectory, "Scripts", "python*.exe")
57 ) + glob.glob(os.path.join(venvDirectory, "python*.exe")) 58 ) + glob.glob(os.path.join(venvDirectory, "python*.exe"))
58 else: 59 else:
59 candidates = glob.glob( 60 candidates = glob.glob(os.path.join(venvDirectory, "bin", "python*"))
60 os.path.join(venvDirectory, "bin", "python*")
61 )
62 self.pythonExecPicker.addItems(sorted(candidates)) 61 self.pythonExecPicker.addItems(sorted(candidates))
63 self.pythonExecPicker.setText("") 62 self.pythonExecPicker.setText("")
64 else: 63 else:
65 self.pythonExecPicker.setText(venvDirectory) 64 self.pythonExecPicker.setText(venvDirectory)
66 65
67 def __updateOK(self): 66 def __updateOK(self):
68 """ 67 """
69 Private method to update the enabled status of the OK button. 68 Private method to update the enabled status of the OK button.
70 """ 69 """
71 interpreterPath = self.pythonExecPicker.text() 70 interpreterPath = self.pythonExecPicker.text()
72 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( 71 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
73 bool(interpreterPath) and 72 bool(interpreterPath)
74 os.path.isfile(interpreterPath) and 73 and os.path.isfile(interpreterPath)
75 os.access(interpreterPath, os.X_OK) 74 and os.access(interpreterPath, os.X_OK)
76 ) 75 )
77 76
78 @pyqtSlot(str) 77 @pyqtSlot(str)
79 def on_pythonExecPicker_textChanged(self, txt): 78 def on_pythonExecPicker_textChanged(self, txt):
80 """ 79 """
81 Private slot to handle changes of the entered Python interpreter path. 80 Private slot to handle changes of the entered Python interpreter path.
82 81
83 @param txt entered Python interpreter path 82 @param txt entered Python interpreter path
84 @type str 83 @type str
85 """ 84 """
86 self.__updateOK() 85 self.__updateOK()
87 86
88 def getData(self): 87 def getData(self):
89 """ 88 """
90 Public method to get the entered data. 89 Public method to get the entered data.
91 90
92 @return path of the selected Python interpreter 91 @return path of the selected Python interpreter
93 @rtype str 92 @rtype str
94 """ 93 """
95 return self.pythonExecPicker.text() 94 return self.pythonExecPicker.text()

eric ide

mercurial