13 from E5Gui.E5Application import e5App |
13 from E5Gui.E5Application import e5App |
14 |
14 |
15 from .Ui_FlaskConfigDialog import Ui_FlaskConfigDialog |
15 from .Ui_FlaskConfigDialog import Ui_FlaskConfigDialog |
16 |
16 |
17 import UI.PixmapCache |
17 import UI.PixmapCache |
|
18 import Preferences |
18 |
19 |
19 |
20 |
20 class FlaskConfigDialog(QDialog, Ui_FlaskConfigDialog): |
21 class FlaskConfigDialog(QDialog, Ui_FlaskConfigDialog): |
21 """ |
22 """ |
22 Class implementing a dialog to configure project specific flask settings. |
23 Class implementing a dialog to configure project specific flask settings. |
23 """ |
24 """ |
24 def __init__(self, configuration, parent=None): |
25 def __init__(self, configuration, project, parent=None): |
25 """ |
26 """ |
26 Constructor |
27 Constructor |
27 |
28 |
28 @param configuration current project specific configuration |
29 @param configuration current project specific configuration |
29 @type dict |
30 @type dict |
|
31 @param project reference to the flask project object |
|
32 @type Project |
30 @param parent reference to the parent widget |
33 @param parent reference to the parent widget |
31 @type QWidget |
34 @type QWidget |
32 """ |
35 """ |
33 super(FlaskConfigDialog, self).__init__(parent) |
36 super(FlaskConfigDialog, self).__init__(parent) |
34 self.setupUi(self) |
37 self.setupUi(self) |
35 |
38 |
36 self.newEnvironmentButton.setIcon( |
39 self.newEnvironmentButton.setIcon( |
37 UI.PixmapCache.getIcon("virtualenvConfig")) |
40 UI.PixmapCache.getIcon("virtualenvConfig")) |
|
41 |
|
42 self.__project = project |
38 |
43 |
39 self.__virtualEnvManager = e5App().getObject("VirtualEnvManager") |
44 self.__virtualEnvManager = e5App().getObject("VirtualEnvManager") |
40 |
45 |
41 self.virtualEnvironmentComboBox.addItem("") |
46 self.virtualEnvironmentComboBox.addItem("") |
42 self.virtualEnvironmentComboBox.addItems( |
47 self.virtualEnvironmentComboBox.addItems( |
85 @pyqtSlot() |
90 @pyqtSlot() |
86 def on_newEnvironmentButton_clicked(self): |
91 def on_newEnvironmentButton_clicked(self): |
87 """ |
92 """ |
88 Private slot to open a dialog for adding a new virtual environment. |
93 Private slot to open a dialog for adding a new virtual environment. |
89 """ |
94 """ |
90 ## self.__virtualEnvManager.createVirtualEnv() |
95 from .FlaskVirtualenvConfigurationDialog import ( |
91 from VirtualEnv.VirtualenvConfigurationDialog import ( |
96 FlaskVirtualenvConfigurationDialog |
92 VirtualenvConfigurationDialog |
|
93 ) |
97 ) |
94 |
98 |
95 dlg = VirtualenvConfigurationDialog(self) |
99 e5Project = e5App().getObject("Project") |
|
100 dlg = FlaskVirtualenvConfigurationDialog( |
|
101 e5Project.getProjectPath(), |
|
102 e5Project.getProjectName(), |
|
103 self) |
96 if dlg.exec() == QDialog.Accepted: |
104 if dlg.exec() == QDialog.Accepted: |
97 resultDict = dlg.getData() |
105 resultDict = dlg.getData() |
98 |
106 |
99 if resultDict["envType"] == "conda": |
107 # now do the call |
100 # conda environments are not suitable |
108 from VirtualEnv.VirtualenvExecDialog import VirtualenvExecDialog |
101 return |
109 dia = VirtualenvExecDialog( |
102 else: |
110 resultDict, self.__virtualEnvManager, self) |
103 # now do the call |
111 dia.show() |
104 from VirtualEnv.VirtualenvExecDialog import ( |
112 dia.start(resultDict["arguments"]) |
105 VirtualenvExecDialog |
113 dia.exec() |
106 ) |
|
107 dia = VirtualenvExecDialog( |
|
108 resultDict, self.__virtualEnvManager, self) |
|
109 dia.show() |
|
110 dia.start(resultDict["arguments"]) |
|
111 dia.exec() |
|
112 |
|
113 # reload the list of environments |
|
114 currentEnvName = self.virtualEnvironmentComboBox.currentText() |
|
115 |
114 |
116 self.virtualEnvironmentComboBox.clear() |
115 self.virtualEnvironmentComboBox.clear() |
117 self.virtualEnvironmentComboBox.addItem("") |
116 self.virtualEnvironmentComboBox.addItem("") |
118 self.virtualEnvironmentComboBox.addItems( |
117 self.virtualEnvironmentComboBox.addItems( |
119 sorted(self.__virtualEnvManager.getVirtualenvNames( |
118 sorted(self.__virtualEnvManager.getVirtualenvNames( |
120 noRemote=True, noConda=True |
119 noRemote=True, noConda=True |
121 )) |
120 )) |
122 ) |
121 ) |
123 |
122 |
124 self.virtualEnvironmentComboBox.setCurrentText(currentEnvName) |
123 self.virtualEnvironmentComboBox.setCurrentText( |
|
124 resultDict["logicalName"]) |
|
125 |
|
126 self.__installFlask(resultDict["targetDirectory"]) |
|
127 |
|
128 def __installFlask(self, venvDir): |
|
129 """ |
|
130 Private method to install flask into the newly created environment. |
|
131 |
|
132 @param venvtDir directory containing the virtual environment |
|
133 @type str |
|
134 """ |
|
135 from PipInterface.PipDialog import PipDialog |
|
136 |
|
137 interpreter = self.__project.getFullCommand("python", venvDir) |
|
138 if Preferences.getPip("PipSearchIndex"): |
|
139 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" |
|
140 args = ["-m", "pip", "install", "--index-url", indexUrl] |
|
141 else: |
|
142 args = ["-m", "pip", "install"] |
|
143 args.append("flask") |
|
144 dia = PipDialog(self.tr('Install Flask'), self) |
|
145 res = dia.startProcess(interpreter, args) |
|
146 if res: |
|
147 dia.exec() |