--- a/ProjectFlask/PyBabelConfigDialog.py Thu Nov 19 20:19:55 2020 +0100 +++ b/ProjectFlask/PyBabelConfigDialog.py Sat Nov 21 17:50:57 2020 +0100 @@ -7,6 +7,8 @@ Module implementing a dialog to edit the PyBabel configuration. """ +import os + from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtWidgets import QDialog, QDialogButtonBox @@ -43,6 +45,11 @@ self.configFilePicker.setDefaultDirectory( self.__e5project.getProjectPath()) + self.translationsDirectoryPicker.setMode( + E5PathPickerModes.DirectoryMode) + self.translationsDirectoryPicker.setDefaultDirectory( + self.__e5project.getProjectPath()) + self.catalogFilePicker.setMode( E5PathPickerModes.SaveFileEnsureExtensionMode) self.catalogFilePicker.setFilters(self.tr( @@ -60,6 +67,12 @@ self.configFilePicker.setText( self.__e5project.getAbsoluteUniversalPath( configuration["configFile"])) + if "translationsDirectory" in configuration: + self.translationsDirectoryPicker.setText( + self.__e5project.getAbsoluteUniversalPath( + configuration["translationsDirectory"])) + if "domain" in configuration: + self.domainEdit.setText(configuration["domain"]) if "catalogFile" in configuration: self.catalogFilePicker.setText( self.__e5project.getAbsoluteUniversalPath( @@ -80,21 +93,50 @@ configuration = { "configFile": self.__e5project.getRelativeUniversalPath( self.configFilePicker.text()), - "catalogFile": self.__e5project.getRelativeUniversalPath( - self.catalogFilePicker.text()), + "translationsDirectory": self.__e5project.getRelativeUniversalPath( + self.translationsDirectoryPicker.text()), } + + domain = self.domainEdit.text() + if domain: + configuration["domain"] = domain + else: + configuration["domain"] = "messages" + + catalogFile = self.catalogFilePicker.text() + if not catalogFile: + # use a default name made of translations dir and domain + catalogFile = os.path.join( + configuration["translationsDirectory"], + "{0}.pot".format(configuration["domain"])) + configuration["catalogFile"] = ( + self.__e5project.getRelativeUniversalPath(catalogFile) + ) + if self.markersEdit.text(): configuration["markersList"] = self.markersEdit.text().split() return configuration def __updateOK(self): + """ + Private method to update the status of the OK button. + """ enable = ( bool(self.configFilePicker.text()) and - bool(self.catalogFilePicker.text()) + bool(self.translationsDirectoryPicker.text()) ) self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) + def __updateCatalogPicker(self): + """ + Private method to update the contents of the catalog picker. + """ + translationsDirectory = self.translationsDirectoryPicker.text() + domain = self.domainEdit.text() + self.catalogFilePicker.setText(os.path.join( + translationsDirectory, "{0}.pot".format(domain))) + @pyqtSlot(str) def on_configFilePicker_textChanged(self, txt): """ @@ -106,7 +148,7 @@ self.__updateOK() @pyqtSlot(str) - def on_catalogFilePicker_textChanged(self, txt): + def on_translationsDirectoryPicker_textChanged(self, txt): """ Private slot to handle a change of the catalog file name. @@ -114,3 +156,14 @@ @type str """ self.__updateOK() + self.__updateCatalogPicker() + + @pyqtSlot(str) + def on_domainEdit_textChanged(self, txt): + """ + Private slot to handle a change of the translations domain. + + @param txt entered translations domain + @type str + """ + self.__updateCatalogPicker()