Wed, 02 Dec 2020 19:54:44 +0100
Finished implementing project specific flask settings.
--- a/ProjectFlask/FlaskConfigDialog.py Wed Dec 02 19:54:18 2020 +0100 +++ b/ProjectFlask/FlaskConfigDialog.py Wed Dec 02 19:54:44 2020 +0100 @@ -14,6 +14,8 @@ from .Ui_FlaskConfigDialog import Ui_FlaskConfigDialog +import UI.PixmapCache + class FlaskConfigDialog(QDialog, Ui_FlaskConfigDialog): """ @@ -31,14 +33,29 @@ super(FlaskConfigDialog, self).__init__(parent) self.setupUi(self) + self.newEnvironmentButton.setIcon( + UI.PixmapCache.getIcon("virtualenvConfig")) + + self.__virtualEnvManager = e5App().getObject("VirtualEnvManager") + self.virtualEnvironmentComboBox.addItem("") self.virtualEnvironmentComboBox.addItems( - sorted(e5App().getObject("VirtualEnvManager").getVirtualenvNames( + sorted(self.__virtualEnvManager.getVirtualenvNames( noRemote=True, noConda=True )) ) - # TODO: set initial values based on configuration + if "virtual_environment_name" in configuration: + self.virtualEnvironmentComboBox.setCurrentText( + configuration["virtual_environment_name"]) + self.flaskBabelBox.setChecked( + configuration.get("flask_babel_override", False)) + self.flaskBabelCheckBox.setChecked( + configuration.get("flask_babel_available", False)) + self.flaskMigrateBox.setChecked( + configuration.get("flask_migrate_override", False)) + self.flaskMigrateCheckBox.setChecked( + configuration.get("flask_migrate_available", False)) msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) @@ -53,6 +70,55 @@ configuration = { "virtual_environment_name": self.virtualEnvironmentComboBox.currentText(), + "flask_babel_override": + self.flaskBabelBox.isChecked(), + "flask_babel_available": + self.flaskBabelCheckBox.isChecked(), + "flask_migrate_override": + self.flaskMigrateBox.isChecked(), + "flask_migrate_available": + self.flaskMigrateCheckBox.isChecked(), } return configuration + + @pyqtSlot() + def on_newEnvironmentButton_clicked(self): + """ + Private slot to open a dialog for adding a new virtual environment. + """ +## self.__virtualEnvManager.createVirtualEnv() + from VirtualEnv.VirtualenvConfigurationDialog import ( + VirtualenvConfigurationDialog + ) + + dlg = VirtualenvConfigurationDialog(self) + if dlg.exec() == QDialog.Accepted: + resultDict = dlg.getData() + + if resultDict["envType"] == "conda": + # conda environments are not suitable + return + else: + # now do the call + from VirtualEnv.VirtualenvExecDialog import ( + VirtualenvExecDialog + ) + dia = VirtualenvExecDialog( + resultDict, self.__virtualEnvManager, self) + dia.show() + dia.start(resultDict["arguments"]) + dia.exec() + + # reload the list of environments + currentEnvName = self.virtualEnvironmentComboBox.currentText() + + self.virtualEnvironmentComboBox.clear() + self.virtualEnvironmentComboBox.addItem("") + self.virtualEnvironmentComboBox.addItems( + sorted(self.__virtualEnvManager.getVirtualenvNames( + noRemote=True, noConda=True + )) + ) + + self.virtualEnvironmentComboBox.setCurrentText(currentEnvName)
--- a/ProjectFlask/FlaskConfigDialog.ui Wed Dec 02 19:54:18 2020 +0100 +++ b/ProjectFlask/FlaskConfigDialog.ui Wed Dec 02 19:54:44 2020 +0100 @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>500</width> - <height>171</height> + <height>253</height> </rect> </property> <property name="windowTitle"> @@ -16,7 +16,7 @@ <property name="sizeGripEnabled"> <bool>true</bool> </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> + <layout class="QVBoxLayout" name="verticalLayout_4"> <item> <widget class="QGroupBox" name="groupBox_2"> <property name="title"> @@ -24,11 +24,22 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QComboBox" name="virtualEnvironmentComboBox"> - <property name="toolTip"> - <string>Select a project specific virtual environment</string> - </property> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QComboBox" name="virtualEnvironmentComboBox"> + <property name="toolTip"> + <string>Select a project specific virtual environment</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="newEnvironmentButton"> + <property name="toolTip"> + <string>Press to open a dialog to create a new virtual environment</string> + </property> + </widget> + </item> + </layout> </item> <item> <widget class="QLabel" name="label"> @@ -44,6 +55,56 @@ </widget> </item> <item> + <widget class="QGroupBox" name="flaskBabelBox"> + <property name="toolTip"> + <string>Select this to override the auto-detection feature</string> + </property> + <property name="title"> + <string>Override 'flask-babel' Availability</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QCheckBox" name="flaskBabelCheckBox"> + <property name="toolTip"> + <string>Select to manually indicate the 'flask-babel' availability</string> + </property> + <property name="text"> + <string>'flask-babel' available</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="flaskMigrateBox"> + <property name="toolTip"> + <string>Select this to override the auto-detection feature</string> + </property> + <property name="title"> + <string>Override 'flask-migrate' Availability</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QCheckBox" name="flaskMigrateCheckBox"> + <property name="toolTip"> + <string>Select to manually indicate the 'flask-migrate' availability</string> + </property> + <property name="text"> + <string>'flask-migrate' available</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> <widget class="QDialogButtonBox" name="buttonBox"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -55,6 +116,14 @@ </item> </layout> </widget> + <tabstops> + <tabstop>virtualEnvironmentComboBox</tabstop> + <tabstop>newEnvironmentButton</tabstop> + <tabstop>flaskBabelBox</tabstop> + <tabstop>flaskBabelCheckBox</tabstop> + <tabstop>flaskMigrateBox</tabstop> + <tabstop>flaskMigrateCheckBox</tabstop> + </tabstops> <resources/> <connections> <connection>
--- a/ProjectFlask/Project.py Wed Dec 02 19:54:18 2020 +0100 +++ b/ProjectFlask/Project.py Wed Dec 02 19:54:44 2020 +0100 @@ -383,11 +383,13 @@ @return path of the virtual environment @rtype str """ - # TODO: use project specific override first, global setting second language = self.__e5project.getProjectLanguage() if language == "Python3": - venvName = self.__plugin.getPreferences( - "VirtualEnvironmentNamePy3") + # get project specific virtual environment name + venvName = self.getData("flask", "virtual_environment_name") + if not venvName: + venvName = self.__plugin.getPreferences( + "VirtualEnvironmentNamePy3") else: venvName = "" if venvName: @@ -715,8 +717,6 @@ """ Private slot to configure the project specific flask parameters. """ - # TODO: implement the flask project config dialog - # 2. support for project specific virtual environment from .FlaskConfigDialog import FlaskConfigDialog config = self.getData("flask", "") @@ -724,6 +724,12 @@ if dlg.exec() == QDialog.Accepted: config = dlg.getConfiguration() self.setData("flask", "", config) + + self.__migrateProject.determineCapability() + + self.__pybabelProject.determineCapability() + self.projectClosedHooks() + self.projectOpenedHooks() ################################################################## ## slot below implements documentation function