|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2018 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the interpreter for a virtual |
|
8 environment. |
|
9 """ |
|
10 |
|
11 import os |
|
12 |
|
13 from PyQt5.QtCore import pyqtSlot |
|
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
15 |
|
16 from E5Gui.E5PathPicker import E5PathPickerModes |
|
17 |
|
18 from .Ui_VirtualenvInterpreterSelectionDialog import ( |
|
19 Ui_VirtualenvInterpreterSelectionDialog |
|
20 ) |
|
21 |
|
22 |
|
23 class VirtualenvInterpreterSelectionDialog( |
|
24 QDialog, Ui_VirtualenvInterpreterSelectionDialog): |
|
25 """ |
|
26 Class implementing a dialog to enter the interpreter for a virtual |
|
27 environment. |
|
28 """ |
|
29 def __init__(self, venvName, venvDirectory, parent=None): |
|
30 """ |
|
31 Constructor |
|
32 |
|
33 @param venvName name for the virtual environment |
|
34 @type str |
|
35 @param venvDirectory directory of the virtual environment |
|
36 @type str |
|
37 @param parent reference to the parent widget |
|
38 @type QWidget |
|
39 """ |
|
40 super().__init__(parent) |
|
41 self.setupUi(self) |
|
42 |
|
43 self.pythonExecPicker.setMode(E5PathPickerModes.OpenFileMode) |
|
44 self.pythonExecPicker.setWindowTitle( |
|
45 self.tr("Python Interpreter")) |
|
46 |
|
47 self.nameEdit.setText(venvName) |
|
48 self.pythonExecPicker.setText(venvDirectory) |
|
49 |
|
50 def __updateOK(self): |
|
51 """ |
|
52 Private method to update the enabled status of the OK button. |
|
53 """ |
|
54 interpreterPath = self.pythonExecPicker.text() |
|
55 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
|
56 bool(interpreterPath) and |
|
57 os.path.isfile(interpreterPath) and |
|
58 os.access(interpreterPath, os.X_OK) |
|
59 ) |
|
60 |
|
61 @pyqtSlot(str) |
|
62 def on_pythonExecPicker_textChanged(self, txt): |
|
63 """ |
|
64 Private slot to handle changes of the entered Python interpreter path. |
|
65 |
|
66 @param txt entered Python interpreter path |
|
67 @type str |
|
68 """ |
|
69 self.__updateOK() |
|
70 |
|
71 def getData(self): |
|
72 """ |
|
73 Public method to get the entered data. |
|
74 |
|
75 @return path of the selected Python interpreter |
|
76 @rtype str |
|
77 """ |
|
78 return self.pythonExecPicker.text() |