--- a/ProjectFlask/Project.py Tue Nov 17 19:49:24 2020 +0100 +++ b/ProjectFlask/Project.py Wed Nov 18 20:16:06 2020 +0100 @@ -12,7 +12,7 @@ from PyQt5.QtCore import ( pyqtSlot, QObject, QProcess, QProcessEnvironment, QTimer ) -from PyQt5.QtWidgets import QMenu +from PyQt5.QtWidgets import QMenu, QDialog from E5Gui import E5MessageBox from E5Gui.E5Action import E5Action @@ -23,10 +23,6 @@ import UI.PixmapCache import Utilities -from .RunServerDialog import RunServerDialog -from .RoutesDialog import RoutesDialog -from .FlaskCommandDialog import FlaskCommandDialog - class Project(QObject): """ @@ -180,6 +176,24 @@ self.actions.append(self.initDatabaseAct) ################################## + ## database action below ## + ################################## + + self.pybabelConfigAct = E5Action( + self.tr('Configure PyBabel'), + self.tr('Configure Py&Babel'), + 0, 0, + self, 'flask_config_pybabel') + self.pybabelConfigAct.setStatusTip(self.tr( + 'Shows a dialog to edit the configuration for pybabel')) + self.pybabelConfigAct.setWhatsThis(self.tr( + """<b>Configure PyBabel</b>""" + """<p>Shows a dialog to edit the configuration for pybabel.</p>""" + )) + self.pybabelConfigAct.triggered.connect(self.__configurePybabel) + self.actions.append(self.pybabelConfigAct) + + ################################## ## documentation action below ## ################################## @@ -237,6 +251,8 @@ menu.addAction(self.showRoutesAct) menu.addSection("flask init-db") menu.addAction(self.initDatabaseAct) + menu.addSection(self.tr("Translations")) + menu.addAction(self.pybabelConfigAct) menu.addSection(self.tr("Various")) menu.addAction(self.documentationAct) menu.addSeparator() @@ -581,9 +597,14 @@ self.__projectData[category] = data data = self.__projectData[category] - if key in data: + if not key: + # return complete category dictionary + return data + elif key in data: + # return individual entry return data[key] else: + # failure return None def setData(self, category, key, value): @@ -606,7 +627,12 @@ if data is not None: self.__projectData[category] = data - self.__projectData[category][key] = value + if not key: + # update the complete category + self.__projectData[category] = value + else: + # update individual entry + self.__projectData[category][key] = value self.__e5project.setData( "PROJECTTYPESPECIFICDATA", category, self.__projectData[category]) @@ -634,6 +660,8 @@ @param development flag indicating development mode @type bool """ + from .RunServerDialog import RunServerDialog + if self.__serverDialog is not None: self.__serverDialog.close() @@ -709,6 +737,8 @@ """ Private slot showing all URL dispatch routes. """ + from .RoutesDialog import RoutesDialog + if self.__routesDialog is not None: self.__routesDialog.close() @@ -722,6 +752,8 @@ """ Private slot showing the result of the database creation. """ + from .FlaskCommandDialog import FlaskCommandDialog + dlg = FlaskCommandDialog(self) if dlg.startCommand("init-db"): dlg.exec() @@ -752,6 +784,34 @@ return False + @pyqtSlot() + def __configurePybabel(self): + """ + Private slot to show a dialog to edit the pybabel configuration. + """ + # TODO: implement this + from .PyBabelConfigDialog import PyBabelConfigDialog + + config = self.getData("pybabel", "") + dlg = PyBabelConfigDialog(config) + if dlg.exec() == QDialog.Accepted: + config = dlg.getConfiguration() + self.setData("pybabel", "", config) + + if not os.path.exists(config["configFile"]): + self.__createBabelCfg(config["configFile"]) + + def __createBabelCfg(self, configFile): + """ + Private method to create a template pybabel configuration file. + """ + template = ( + "[python: {0}/**.py]\n" + "[jinja2: {0}/templates/**.html]\n" + "extensions=jinja2.ext.autoescape,jinja2.ext.with_\n" + ) + # TODO: determine app name and write file + def __projectLanguageAdded(self, code): # TODO: implement this with pybabel ... pass