ProjectFlask/FormSelectionDialog.py

branch
eric7
changeset 70
22e1d0f69668
parent 66
0d3168d0e310
child 75
7a30d96ea9f6
--- a/ProjectFlask/FormSelectionDialog.py	Thu Dec 30 12:13:22 2021 +0100
+++ b/ProjectFlask/FormSelectionDialog.py	Wed Sep 21 16:30:15 2022 +0200
@@ -17,113 +17,116 @@
     """
     Class implementing a dialog to select the template type.
     """
+
     Templates = {
         "html5": {
             "title": QCoreApplication.translate(
-                "FormSelectionDialog", "Standard HTML 5 template"),
-            "template": '''<!DOCTYPE html>\n'''
-                        '''  <head>\n'''
-                        '''    <title></title>\n'''
-                        '''    <style>\n'''
-                        '''    </style>\n'''
-                        '''  </head>\n'''
-                        '''\n'''
-                        '''  <body>\n'''
-                        '''  </body>\n'''
-                        '''</html>\n''',
+                "FormSelectionDialog", "Standard HTML 5 template"
+            ),
+            "template": """<!DOCTYPE html>\n"""
+            """  <head>\n"""
+            """    <title></title>\n"""
+            """    <style>\n"""
+            """    </style>\n"""
+            """  </head>\n"""
+            """\n"""
+            """  <body>\n"""
+            """  </body>\n"""
+            """</html>\n""",
         },
         "basic_jinja": {
             "title": QCoreApplication.translate(
-                "FormSelectionDialog", "Basic Jinja template"),
-            "template": '''<!DOCTYPE html>\n'''
-                        '''  <head>\n'''
-                        '''    {% if title %}\n'''
-                        '''    <title>{{ title }}</title>\n'''
-                        '''    {% else %}\n'''
-                        '''    <title>Title</title>\n'''
-                        '''    {% endif %}\n'''
-                        '''  </head>\n'''
-                        '''\n'''
-                        '''  <body>\n'''
-                        '''    <h1>Hello, {{ user.username }}!</h1>\n'''
-                        '''  </body>\n'''
-                        '''</html>\n''',
+                "FormSelectionDialog", "Basic Jinja template"
+            ),
+            "template": """<!DOCTYPE html>\n"""
+            """  <head>\n"""
+            """    {% if title %}\n"""
+            """    <title>{{ title }}</title>\n"""
+            """    {% else %}\n"""
+            """    <title>Title</title>\n"""
+            """    {% endif %}\n"""
+            """  </head>\n"""
+            """\n"""
+            """  <body>\n"""
+            """    <h1>Hello, {{ user.username }}!</h1>\n"""
+            """  </body>\n"""
+            """</html>\n""",
         },
         "jinja_base": {
             "title": QCoreApplication.translate(
-                "FormSelectionDialog", "Jinja base template"),
-            "template": '''<!DOCTYPE html>\n'''
-                        '''  <head>\n'''
-                        '''    {% if title %}\n'''
-                        '''    <title>{{ title }}</title>\n'''
-                        '''    {% else %}\n'''
-                        '''    <title>Title</title>\n'''
-                        '''    {% endif %}\n'''
-                        '''  </head>\n'''
-                        '''\n'''
-                        '''  <body>\n'''
-                        '''    {% block content %}{% endblock %}\n'''
-                        '''  </body>\n'''
-                        '''</html>\n''',
+                "FormSelectionDialog", "Jinja base template"
+            ),
+            "template": """<!DOCTYPE html>\n"""
+            """  <head>\n"""
+            """    {% if title %}\n"""
+            """    <title>{{ title }}</title>\n"""
+            """    {% else %}\n"""
+            """    <title>Title</title>\n"""
+            """    {% endif %}\n"""
+            """  </head>\n"""
+            """\n"""
+            """  <body>\n"""
+            """    {% block content %}{% endblock %}\n"""
+            """  </body>\n"""
+            """</html>\n""",
         },
         "jinja_extends": {
             "title": QCoreApplication.translate(
-                "FormSelectionDialog", "Jinja extension template"),
-            "template": '''{% extends "base.html" %}\n'''
-                        '''\n'''
-                        '''{% block content %}\n'''
-                        '''  <h1>{{ user.username }}</h1>\n'''
-                        '''  {% for item in items %}\n'''
-                        '''  <div><p>{{ item.field1 }}: {{ item.field2 }}'''
-                        '''</p></div>\n'''
-                        '''  {% endfor %}\n'''
-                        '''{% endblock %}\n'''
+                "FormSelectionDialog", "Jinja extension template"
+            ),
+            "template": """{% extends "base.html" %}\n"""
+            """\n"""
+            """{% block content %}\n"""
+            """  <h1>{{ user.username }}</h1>\n"""
+            """  {% for item in items %}\n"""
+            """  <div><p>{{ item.field1 }}: {{ item.field2 }}"""
+            """</p></div>\n"""
+            """  {% endfor %}\n"""
+            """{% endblock %}\n""",
         },
     }
-    
+
     def __init__(self, parent=None):
         """
         Constructor
-        
+
         @param parent reference to the parent widget
         @type QWidget
         """
         super().__init__(parent)
         self.setupUi(self)
-        
-        self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Ok).setEnabled(False)
-        
+
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
+
         self.typeCombo.addItem("")
         for templateType in FormSelectionDialog.Templates:
             self.typeCombo.addItem(
-                FormSelectionDialog.Templates[templateType]["title"],
-                templateType)
+                FormSelectionDialog.Templates[templateType]["title"], templateType
+            )
         self.typeCombo.setCurrentIndex(0)
-    
+
     @pyqtSlot(int)
     def on_typeCombo_currentIndexChanged(self, index):
         """
         Private slot to act upon a change of the selected template type.
-        
+
         @param index selected index
         @type int
         """
         templateType = self.typeCombo.itemData(index)
         if templateType:
             self.preview.setPlainText(
-                FormSelectionDialog.Templates[templateType]["template"])
-            self.buttonBox.button(
-                QDialogButtonBox.StandardButton.Ok).setEnabled(True)
+                FormSelectionDialog.Templates[templateType]["template"]
+            )
+            self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(True)
         else:
             self.preview.clear()
-            self.buttonBox.button(
-                QDialogButtonBox.StandardButton.Ok).setEnabled(False)
-    
+            self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
+
     def getTemplateText(self):
         """
         Public method to get the template text.
-        
+
         @return text of the template
         @rtype str
         """

eric ide

mercurial