14 from PyQt6.QtCore import pyqtSlot |
14 from PyQt6.QtCore import pyqtSlot |
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_FlaskVirtualenvConfigurationDialog import ( |
19 from .Ui_FlaskVirtualenvConfigurationDialog import Ui_FlaskVirtualenvConfigurationDialog |
20 Ui_FlaskVirtualenvConfigurationDialog |
|
21 ) |
|
22 |
20 |
23 import Utilities |
21 import Utilities |
24 |
22 |
25 |
23 |
26 class FlaskVirtualenvConfigurationDialog( |
24 class FlaskVirtualenvConfigurationDialog( |
27 QDialog, Ui_FlaskVirtualenvConfigurationDialog |
25 QDialog, Ui_FlaskVirtualenvConfigurationDialog |
28 ): |
26 ): |
29 """ |
27 """ |
30 Class implementing a dialog to configure a project specific virtual |
28 Class implementing a dialog to configure a project specific virtual |
31 environment. |
29 environment. |
32 |
30 |
33 Note: This dialog is a simplified variant of the one found in the eric |
31 Note: This dialog is a simplified variant of the one found in the eric |
34 package. |
32 package. |
35 """ |
33 """ |
|
34 |
36 def __init__(self, projectPath, projectName, parent=None): |
35 def __init__(self, projectPath, projectName, parent=None): |
37 """ |
36 """ |
38 Constructor |
37 Constructor |
39 |
38 |
40 @param projectPath directory path of the project |
39 @param projectPath directory path of the project |
41 @type str |
40 @type str |
42 @param projectName name of the project |
41 @param projectName name of the project |
43 @type str |
42 @type str |
44 @param parent reference to the parent widget |
43 @param parent reference to the parent widget |
45 @type QWidget |
44 @type QWidget |
46 """ |
45 """ |
47 super().__init__(parent) |
46 super().__init__(parent) |
48 self.setupUi(self) |
47 self.setupUi(self) |
49 |
48 |
50 self.targetDirectoryPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
49 self.targetDirectoryPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
51 self.targetDirectoryPicker.setWindowTitle( |
50 self.targetDirectoryPicker.setWindowTitle( |
52 self.tr("Virtualenv Target Directory")) |
51 self.tr("Virtualenv Target Directory") |
|
52 ) |
53 self.targetDirectoryPicker.setDefaultDirectory(projectPath) |
53 self.targetDirectoryPicker.setDefaultDirectory(projectPath) |
54 |
54 |
55 self.pythonExecPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
55 self.pythonExecPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
56 self.pythonExecPicker.setWindowTitle( |
56 self.pythonExecPicker.setWindowTitle(self.tr("Python Interpreter")) |
57 self.tr("Python Interpreter")) |
|
58 self.pythonExecPicker.setDefaultDirectory( |
57 self.pythonExecPicker.setDefaultDirectory( |
59 sys.executable.replace("w.exe", ".exe")) |
58 sys.executable.replace("w.exe", ".exe") |
60 |
59 ) |
|
60 |
61 mandatoryStyleSheet = "QLineEdit {border: 2px solid;}" |
61 mandatoryStyleSheet = "QLineEdit {border: 2px solid;}" |
62 self.targetDirectoryPicker.setStyleSheet(mandatoryStyleSheet) |
62 self.targetDirectoryPicker.setStyleSheet(mandatoryStyleSheet) |
63 self.nameEdit.setStyleSheet(mandatoryStyleSheet) |
63 self.nameEdit.setStyleSheet(mandatoryStyleSheet) |
64 |
64 |
65 # pre-populate some fields |
65 # pre-populate some fields |
66 self.nameEdit.setText("Project {0}".format(projectName)) |
66 self.nameEdit.setText("Project {0}".format(projectName)) |
67 self.targetDirectoryPicker.setText(os.path.join(projectPath, "venv")) |
67 self.targetDirectoryPicker.setText(os.path.join(projectPath, "venv")) |
68 |
68 |
69 msh = self.minimumSizeHint() |
69 msh = self.minimumSizeHint() |
70 self.resize(max(self.width(), msh.width()), msh.height()) |
70 self.resize(max(self.width(), msh.width()), msh.height()) |
71 |
71 |
72 def __updateOK(self): |
72 def __updateOK(self): |
73 """ |
73 """ |
74 Private method to update the enabled status of the OK button. |
74 Private method to update the enabled status of the OK button. |
75 """ |
75 """ |
76 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
76 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
77 bool(self.targetDirectoryPicker.text()) and |
77 bool(self.targetDirectoryPicker.text()) and bool(self.nameEdit.text()) |
78 bool(self.nameEdit.text()) |
|
79 ) |
78 ) |
80 |
79 |
81 @pyqtSlot(str) |
80 @pyqtSlot(str) |
82 def on_nameEdit_textChanged(self, txt): |
81 def on_nameEdit_textChanged(self, txt): |
83 """ |
82 """ |
84 Private slot handling a change of the virtual environment name. |
83 Private slot handling a change of the virtual environment name. |
85 |
84 |
86 @param txt name of the virtual environment |
85 @param txt name of the virtual environment |
87 @type str |
86 @type str |
88 """ |
87 """ |
89 self.__updateOK() |
88 self.__updateOK() |
90 |
89 |
91 @pyqtSlot(str) |
90 @pyqtSlot(str) |
92 def on_targetDirectoryPicker_textChanged(self, txt): |
91 def on_targetDirectoryPicker_textChanged(self, txt): |
93 """ |
92 """ |
94 Private slot handling a change of the target directory. |
93 Private slot handling a change of the target directory. |
95 |
94 |
96 @param txt target directory |
95 @param txt target directory |
97 @type str |
96 @type str |
98 """ |
97 """ |
99 self.__updateOK() |
98 self.__updateOK() |
100 |
99 |
101 def __generateTargetDir(self): |
100 def __generateTargetDir(self): |
102 """ |
101 """ |
103 Private method to generate a valid target directory path. |
102 Private method to generate a valid target directory path. |
104 |
103 |
105 @return target directory path |
104 @return target directory path |
106 @rtype str |
105 @rtype str |
107 """ |
106 """ |
108 targetDirectory = Utilities.toNativeSeparators( |
107 targetDirectory = Utilities.toNativeSeparators( |
109 self.targetDirectoryPicker.text()) |
108 self.targetDirectoryPicker.text() |
|
109 ) |
110 if not os.path.isabs(targetDirectory): |
110 if not os.path.isabs(targetDirectory): |
111 targetDirectory = os.path.join(os.path.expanduser("~"), |
111 targetDirectory = os.path.join(os.path.expanduser("~"), targetDirectory) |
112 targetDirectory) |
|
113 return targetDirectory |
112 return targetDirectory |
114 |
113 |
115 def getData(self): |
114 def getData(self): |
116 """ |
115 """ |
117 Public method to retrieve the dialog data. |
116 Public method to retrieve the dialog data. |
118 |
117 |
119 Note: This method returns a data structure compatible with the one |
118 Note: This method returns a data structure compatible with the one |
120 returned by the eric virtual environment configuration dialog. |
119 returned by the eric virtual environment configuration dialog. |
121 |
120 |
122 @return dictionary containing the data for the environment to be |
121 @return dictionary containing the data for the environment to be |
123 created. The keys for both variants are 'arguments' containing the |
122 created. The keys for both variants are 'arguments' containing the |
124 command line arguments, 'logicalName' containing the environment |
123 command line arguments, 'logicalName' containing the environment |
125 name to be used with the virtual environment manager and 'envType' |
124 name to be used with the virtual environment manager and 'envType' |
126 containing the environment type (always pyvenv). The pyvenv |
125 containing the environment type (always pyvenv). The pyvenv |