20 |
20 |
21 class FlaskConfigDialog(QDialog, Ui_FlaskConfigDialog): |
21 class FlaskConfigDialog(QDialog, Ui_FlaskConfigDialog): |
22 """ |
22 """ |
23 Class implementing a dialog to configure project specific flask settings. |
23 Class implementing a dialog to configure project specific flask settings. |
24 """ |
24 """ |
|
25 |
25 def __init__(self, configuration, project, parent=None): |
26 def __init__(self, configuration, project, parent=None): |
26 """ |
27 """ |
27 Constructor |
28 Constructor |
28 |
29 |
29 @param configuration current project specific configuration |
30 @param configuration current project specific configuration |
30 @type dict |
31 @type dict |
31 @param project reference to the flask project object |
32 @param project reference to the flask project object |
32 @type Project |
33 @type Project |
33 @param parent reference to the parent widget |
34 @param parent reference to the parent widget |
34 @type QWidget |
35 @type QWidget |
35 """ |
36 """ |
36 super().__init__(parent) |
37 super().__init__(parent) |
37 self.setupUi(self) |
38 self.setupUi(self) |
38 |
39 |
39 self.newEnvironmentButton.setIcon( |
40 self.newEnvironmentButton.setIcon(UI.PixmapCache.getIcon("virtualenvConfig")) |
40 UI.PixmapCache.getIcon("virtualenvConfig")) |
41 |
41 |
|
42 self.__project = project |
42 self.__project = project |
43 |
43 |
44 self.__virtualEnvManager = ericApp().getObject("VirtualEnvManager") |
44 self.__virtualEnvManager = ericApp().getObject("VirtualEnvManager") |
45 |
45 |
46 self.virtualEnvironmentComboBox.addItem("") |
46 self.virtualEnvironmentComboBox.addItem("") |
47 self.virtualEnvironmentComboBox.addItems( |
47 self.virtualEnvironmentComboBox.addItems( |
48 sorted(self.__virtualEnvManager.getVirtualenvNames( |
48 sorted( |
49 noRemote=True, noConda=True |
49 self.__virtualEnvManager.getVirtualenvNames(noRemote=True, noConda=True) |
50 )) |
50 ) |
51 ) |
51 ) |
52 |
52 |
53 if "virtual_environment_name" in configuration: |
53 if "virtual_environment_name" in configuration: |
54 self.virtualEnvironmentComboBox.setCurrentText( |
54 self.virtualEnvironmentComboBox.setCurrentText( |
55 configuration["virtual_environment_name"]) |
55 configuration["virtual_environment_name"] |
56 self.flaskBabelBox.setChecked( |
56 ) |
57 configuration.get("flask_babel_override", False)) |
57 self.flaskBabelBox.setChecked(configuration.get("flask_babel_override", False)) |
58 self.flaskBabelCheckBox.setChecked( |
58 self.flaskBabelCheckBox.setChecked( |
59 configuration.get("flask_babel_available", False)) |
59 configuration.get("flask_babel_available", False) |
|
60 ) |
60 self.flaskMigrateBox.setChecked( |
61 self.flaskMigrateBox.setChecked( |
61 configuration.get("flask_migrate_override", False)) |
62 configuration.get("flask_migrate_override", False) |
|
63 ) |
62 self.flaskMigrateCheckBox.setChecked( |
64 self.flaskMigrateCheckBox.setChecked( |
63 configuration.get("flask_migrate_available", False)) |
65 configuration.get("flask_migrate_available", False) |
64 |
66 ) |
|
67 |
65 msh = self.minimumSizeHint() |
68 msh = self.minimumSizeHint() |
66 self.resize(max(self.width(), msh.width()), msh.height()) |
69 self.resize(max(self.width(), msh.width()), msh.height()) |
67 |
70 |
68 def getConfiguration(self): |
71 def getConfiguration(self): |
69 """ |
72 """ |
70 Public method to get the entered configuration data. |
73 Public method to get the entered configuration data. |
71 |
74 |
72 @return project specific configuration |
75 @return project specific configuration |
73 @rtype dict |
76 @rtype dict |
74 """ |
77 """ |
75 configuration = { |
78 configuration = { |
76 "virtual_environment_name": |
79 "virtual_environment_name": self.virtualEnvironmentComboBox.currentText(), |
77 self.virtualEnvironmentComboBox.currentText(), |
80 "flask_babel_override": self.flaskBabelBox.isChecked(), |
78 "flask_babel_override": |
81 "flask_babel_available": self.flaskBabelCheckBox.isChecked(), |
79 self.flaskBabelBox.isChecked(), |
82 "flask_migrate_override": self.flaskMigrateBox.isChecked(), |
80 "flask_babel_available": |
83 "flask_migrate_available": self.flaskMigrateCheckBox.isChecked(), |
81 self.flaskBabelCheckBox.isChecked(), |
|
82 "flask_migrate_override": |
|
83 self.flaskMigrateBox.isChecked(), |
|
84 "flask_migrate_available": |
|
85 self.flaskMigrateCheckBox.isChecked(), |
|
86 } |
84 } |
87 |
85 |
88 return configuration |
86 return configuration |
89 |
87 |
90 @pyqtSlot() |
88 @pyqtSlot() |
91 def on_newEnvironmentButton_clicked(self): |
89 def on_newEnvironmentButton_clicked(self): |
92 """ |
90 """ |
93 Private slot to open a dialog for adding a new virtual environment. |
91 Private slot to open a dialog for adding a new virtual environment. |
94 """ |
92 """ |
95 from .FlaskVirtualenvConfigurationDialog import ( |
93 from .FlaskVirtualenvConfigurationDialog import ( |
96 FlaskVirtualenvConfigurationDialog |
94 FlaskVirtualenvConfigurationDialog, |
97 ) |
95 ) |
98 |
96 |
99 ericProject = ericApp().getObject("Project") |
97 ericProject = ericApp().getObject("Project") |
100 dlg = FlaskVirtualenvConfigurationDialog( |
98 dlg = FlaskVirtualenvConfigurationDialog( |
101 ericProject.getProjectPath(), |
99 ericProject.getProjectPath(), ericProject.getProjectName(), self |
102 ericProject.getProjectName(), |
100 ) |
103 self) |
|
104 if dlg.exec() == QDialog.DialogCode.Accepted: |
101 if dlg.exec() == QDialog.DialogCode.Accepted: |
105 resultDict = dlg.getData() |
102 resultDict = dlg.getData() |
106 |
103 |
107 # now do the call |
104 # now do the call |
108 from VirtualEnv.VirtualenvExecDialog import VirtualenvExecDialog |
105 from VirtualEnv.VirtualenvExecDialog import VirtualenvExecDialog |
109 dia = VirtualenvExecDialog( |
106 |
110 resultDict, self.__virtualEnvManager, self) |
107 dia = VirtualenvExecDialog(resultDict, self.__virtualEnvManager, self) |
111 dia.show() |
108 dia.show() |
112 dia.start(resultDict["arguments"]) |
109 dia.start(resultDict["arguments"]) |
113 dia.exec() |
110 dia.exec() |
114 |
111 |
115 self.virtualEnvironmentComboBox.clear() |
112 self.virtualEnvironmentComboBox.clear() |
116 self.virtualEnvironmentComboBox.addItem("") |
113 self.virtualEnvironmentComboBox.addItem("") |
117 self.virtualEnvironmentComboBox.addItems( |
114 self.virtualEnvironmentComboBox.addItems( |
118 sorted(self.__virtualEnvManager.getVirtualenvNames( |
115 sorted( |
119 noRemote=True, noConda=True |
116 self.__virtualEnvManager.getVirtualenvNames( |
120 )) |
117 noRemote=True, noConda=True |
|
118 ) |
|
119 ) |
121 ) |
120 ) |
122 |
121 |
123 self.virtualEnvironmentComboBox.setCurrentText( |
122 self.virtualEnvironmentComboBox.setCurrentText(resultDict["logicalName"]) |
124 resultDict["logicalName"]) |
123 |
125 |
|
126 self.__installFlask(resultDict["targetDirectory"]) |
124 self.__installFlask(resultDict["targetDirectory"]) |
127 |
125 |
128 def __installFlask(self, venvDir): |
126 def __installFlask(self, venvDir): |
129 """ |
127 """ |
130 Private method to install flask into the newly created environment. |
128 Private method to install flask into the newly created environment. |
131 |
129 |
132 @param venvDir directory containing the virtual environment |
130 @param venvDir directory containing the virtual environment |
133 @type str |
131 @type str |
134 """ |
132 """ |
135 from PipInterface.PipDialog import PipDialog |
133 from PipInterface.PipDialog import PipDialog |
136 |
134 |
137 interpreter = self.__project.getFullCommand("python", venvDir) |
135 interpreter = self.__project.getFullCommand("python", venvDir) |
138 if Preferences.getPip("PipSearchIndex"): |
136 if Preferences.getPip("PipSearchIndex"): |
139 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" |
137 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" |
140 args = ["-m", "pip", "install", "--index-url", indexUrl] |
138 args = ["-m", "pip", "install", "--index-url", indexUrl] |
141 else: |
139 else: |
142 args = ["-m", "pip", "install"] |
140 args = ["-m", "pip", "install"] |
143 args.append("flask") |
141 args.append("flask") |
144 dia = PipDialog(self.tr('Install Flask'), self) |
142 dia = PipDialog(self.tr("Install Flask"), self) |
145 res = dia.startProcess(interpreter, args) |
143 res = dia.startProcess(interpreter, args) |
146 if res: |
144 if res: |
147 dia.exec() |
145 dia.exec() |