src/eric7/QScintilla/Exporters/__init__.py

branch
eric7
changeset 9487
78cb053591c9
parent 9482
a2bc06a54d9d
child 9497
8beca4047c53
--- a/src/eric7/QScintilla/Exporters/__init__.py	Tue Nov 08 11:50:50 2022 +0100
+++ b/src/eric7/QScintilla/Exporters/__init__.py	Tue Nov 08 12:19:25 2022 +0100
@@ -7,6 +7,9 @@
 Package implementing exporters for various file formats.
 """
 
+import contextlib
+import importlib
+
 from PyQt6.QtCore import QCoreApplication
 
 
@@ -38,26 +41,18 @@
     @return reference to the instanciated exporter object
         (QScintilla.Exporter.Exporter)
     """
-    try:
-        if exporterFormat == "HTML":
-            from .ExporterHTML import ExporterHTML  # __IGNORE_WARNING_I101__
-
-            return ExporterHTML(editor)
-        elif exporterFormat == "PDF":
-            from .ExporterPDF import ExporterPDF  # __IGNORE_WARNING_I101__
-
-            return ExporterPDF(editor)
-        elif exporterFormat == "RTF":
-            from .ExporterRTF import ExporterRTF  # __IGNORE_WARNING_I101__
+    exporterMapping = {
+        "HTML": "ExporterHTML",
+        "ODT": "ExporterODT",
+        "PDF": "ExporterPDF",
+        "RTF": "ExporterRTF",
+        "TeX": "ExporterTEX",
+    }
+    with contextlib.suppress(ImportError):
+        if exporterFormat in exporterMapping:
+            mod = importlib.import_module(
+                "eric7.QScintilla.Exporters.{0}".format(exporterMapping[exporterFormat])
+            )
+            return mod.createExporter(editor)
 
-            return ExporterRTF(editor)
-        elif exporterFormat == "TeX":
-            from .ExporterTEX import ExporterTEX  # __IGNORE_WARNING_I101__
-
-            return ExporterTEX(editor)
-        elif exporterFormat == "ODT":
-            from .ExporterODT import ExporterODT  # __IGNORE_WARNING_I101__
-
-            return ExporterODT(editor)
-    except ImportError:
-        return None
+    return None

eric ide

mercurial