ProjectFlask/Project.py

changeset 15
3f5c05eb2d5f
parent 14
d2da14b2a233
child 16
dd3f6bfb85f7
diff -r d2da14b2a233 -r 3f5c05eb2d5f ProjectFlask/Project.py
--- a/ProjectFlask/Project.py	Thu Nov 19 18:34:05 2020 +0100
+++ b/ProjectFlask/Project.py	Thu Nov 19 20:19:55 2020 +0100
@@ -23,6 +23,8 @@
 import UI.PixmapCache
 import Utilities
 
+from .FlaskCommandDialog import FlaskCommandDialog
+
 
 class Project(QObject):
     """
@@ -762,10 +764,8 @@
         """
         Private slot showing the result of the database creation.
         """
-        from .FlaskCommandDialog import FlaskCommandDialog
-        
         dlg = FlaskCommandDialog(self)
-        if dlg.startCommand("init-db"):
+        if dlg.startFlaskCommand("init-db"):
             dlg.exec()
     
     ##################################################################
@@ -882,11 +882,62 @@
         # TODO: implement this with pybabel ...
         pass
     
-    def openPOEditor(self):
-        # TODO: implement this with pybabel ...
-        pass
+    def openPOEditor(self, poFile):
+        """
+        Public method to edit the given file in an external .po editor.
+        
+        @param poFile name of the .po file
+        @type str
+        """
+        editor = self.__plugin.getPreferences("TranslationsEditor")
+        if poFile.endswith(".po") and editor:
+            wd, _ = self.getApplication()
+            started, pid = QProcess.startDetached(editor, [poFile], wd)
+            if not started:
+                E5MessageBox.critical(
+                    None,
+                    self.tr('Process Generation Error'),
+                    self.tr('The translations editor process ({0}) could'
+                            ' not be started.').format(
+                        os.path.basename(editor)))
     
     def extractMessages(self):
+        """
+        Public method to extract the messages catalog template file.
+        """
+        title = self.tr("Extract messages")
+        if self.__ensurePybabelConfigured():
+            potFile = self.__e5project.getAbsoluteUniversalPath(
+                self.getData("pybabel", "catalogFile"))
+            
+            try:
+                potFilePath = os.path.dirname(potFile)
+                os.makedirs(potFilePath)
+            except EnvironmentError:
+                pass
+            
+            args = [
+                "-F",
+                self.__e5project.getAbsoluteUniversalPath(
+                    self.getData("pybabel", "configFile"))
+            ]
+            if self.getData("pybabel", "markersList"):
+                for marker in self.getData("pybabel", "markersList"):
+                    args += ["-k", marker]
+            args += [
+                "-o",
+                potFile,
+                "."
+            ]
+            
+            dlg = FlaskCommandDialog(self)
+            res = dlg.startBabelCommand(
+                "extract", args, title,
+                msgSuccess=self.tr("\nMessages extracted successfully.")
+            )
+            if res:
+                dlg.exec()
+                self.__e5project.appendFile(potFile)
         # TODO: implement this with pybabel ...
         pass
     

eric ide

mercurial