ProjectFlask/FlaskBabelExtension/PyBabelConfigDialog.py

branch
eric7
changeset 70
22e1d0f69668
parent 66
0d3168d0e310
child 72
4557829a4acf
--- a/ProjectFlask/FlaskBabelExtension/PyBabelConfigDialog.py	Thu Dec 30 12:13:22 2021 +0100
+++ b/ProjectFlask/FlaskBabelExtension/PyBabelConfigDialog.py	Wed Sep 21 16:30:15 2022 +0200
@@ -22,10 +22,11 @@
     """
     Class implementing a dialog to edit the flask-babel configuration.
     """
+
     def __init__(self, configuration, parent=None):
         """
         Constructor
-        
+
         @param configuration current pybabel configuration
         @type dict
         @param parent reference to the parent widget
@@ -33,140 +34,141 @@
         """
         super().__init__(parent)
         self.setupUi(self)
-        
+
         self.__ericProject = ericApp().getObject("Project")
-        
+
         self.configFilePicker.setMode(
-            EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE)
-        self.configFilePicker.setFilters(self.tr(
-            "Configuration Files (*.cfg);;"
-            "All Files (*)"
-        ))
-        self.configFilePicker.setDefaultDirectory(
-            self.__ericProject.getProjectPath())
-        
-        self.translationsDirectoryPicker.setMode(
-            EricPathPickerModes.DIRECTORY_MODE)
+            EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE
+        )
+        self.configFilePicker.setFilters(
+            self.tr("Configuration Files (*.cfg);;" "All Files (*)")
+        )
+        self.configFilePicker.setDefaultDirectory(self.__ericProject.getProjectPath())
+
+        self.translationsDirectoryPicker.setMode(EricPathPickerModes.DIRECTORY_MODE)
         self.translationsDirectoryPicker.setDefaultDirectory(
-            self.__ericProject.getProjectPath())
-        
+            self.__ericProject.getProjectPath()
+        )
+
         self.catalogFilePicker.setMode(
-            EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE)
-        self.catalogFilePicker.setFilters(self.tr(
-            "Message Catalog Files (*.pot);;"
-            "All Files (*)"
-        ))
-        self.catalogFilePicker.setDefaultDirectory(
-            self.__ericProject.getProjectPath())
-        
+            EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE
+        )
+        self.catalogFilePicker.setFilters(
+            self.tr("Message Catalog Files (*.pot);;" "All Files (*)")
+        )
+        self.catalogFilePicker.setDefaultDirectory(self.__ericProject.getProjectPath())
+
         self.configFilePicker.setFocus(Qt.FocusReason.OtherFocusReason)
-        
-        self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Ok).setEnabled(False)
-        
+
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
+
         if "configFile" in configuration:
             self.configFilePicker.setText(
-                self.__ericProject.getAbsoluteUniversalPath(
-                    configuration["configFile"]))
+                self.__ericProject.getAbsoluteUniversalPath(configuration["configFile"])
+            )
         if "translationsDirectory" in configuration:
             self.translationsDirectoryPicker.setText(
                 self.__ericProject.getAbsoluteUniversalPath(
-                    configuration["translationsDirectory"]))
+                    configuration["translationsDirectory"]
+                )
+            )
         if "domain" in configuration:
             self.domainEdit.setText(configuration["domain"])
         if "catalogFile" in configuration:
             self.catalogFilePicker.setText(
                 self.__ericProject.getAbsoluteUniversalPath(
-                    configuration["catalogFile"]))
+                    configuration["catalogFile"]
+                )
+            )
         if "markersList" in configuration:
             self.markersEdit.setText(" ".join(configuration["markersList"]))
-        
+
         msh = self.minimumSizeHint()
         self.resize(max(self.width(), msh.width()), msh.height())
-    
+
     def getConfiguration(self):
         """
         Public method to get the entered configuration data.
-        
+
         @return pybabel configuration
         @rtype dict
         """
         configuration = {
-            "configFile":
-                self.__ericProject.getRelativeUniversalPath(
-                    self.configFilePicker.text()),
-            "translationsDirectory":
-                self.__ericProject.getRelativeUniversalPath(
-                    self.translationsDirectoryPicker.text()),
+            "configFile": self.__ericProject.getRelativeUniversalPath(
+                self.configFilePicker.text()
+            ),
+            "translationsDirectory": self.__ericProject.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.__ericProject.getRelativeUniversalPath(catalogFile)
+                "{0}.pot".format(configuration["domain"]),
+            )
+        configuration["catalogFile"] = self.__ericProject.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.translationsDirectoryPicker.text())
+        enable = bool(self.configFilePicker.text()) and bool(
+            self.translationsDirectoryPicker.text()
         )
-        self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
-    
+        self.buttonBox.button(QDialogButtonBox.StandardButton.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)))
-    
+        self.catalogFilePicker.setText(
+            os.path.join(translationsDirectory, "{0}.pot".format(domain))
+        )
+
     @pyqtSlot(str)
     def on_configFilePicker_textChanged(self, txt):
         """
         Private slot to handle a change of the configuration file name.
-        
+
         @param txt configuration file name
         @type str
         """
         self.__updateOK()
-    
+
     @pyqtSlot(str)
     def on_translationsDirectoryPicker_textChanged(self, txt):
         """
         Private slot to handle a change of the catalog file name.
-        
+
         @param txt configuration file name
         @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
         """

eric ide

mercurial