15 |
15 |
16 class FormSelectionDialog(QDialog, Ui_FormSelectionDialog): |
16 class FormSelectionDialog(QDialog, Ui_FormSelectionDialog): |
17 """ |
17 """ |
18 Class implementing a dialog to select the template type. |
18 Class implementing a dialog to select the template type. |
19 """ |
19 """ |
|
20 |
20 Templates = { |
21 Templates = { |
21 "html5": { |
22 "html5": { |
22 "title": QCoreApplication.translate( |
23 "title": QCoreApplication.translate( |
23 "FormSelectionDialog", "Standard HTML 5 template"), |
24 "FormSelectionDialog", "Standard HTML 5 template" |
24 "template": '''<!DOCTYPE html>\n''' |
25 ), |
25 ''' <head>\n''' |
26 "template": """<!DOCTYPE html>\n""" |
26 ''' <title></title>\n''' |
27 """ <head>\n""" |
27 ''' <style>\n''' |
28 """ <title></title>\n""" |
28 ''' </style>\n''' |
29 """ <style>\n""" |
29 ''' </head>\n''' |
30 """ </style>\n""" |
30 '''\n''' |
31 """ </head>\n""" |
31 ''' <body>\n''' |
32 """\n""" |
32 ''' </body>\n''' |
33 """ <body>\n""" |
33 '''</html>\n''', |
34 """ </body>\n""" |
|
35 """</html>\n""", |
34 }, |
36 }, |
35 "basic_jinja": { |
37 "basic_jinja": { |
36 "title": QCoreApplication.translate( |
38 "title": QCoreApplication.translate( |
37 "FormSelectionDialog", "Basic Jinja template"), |
39 "FormSelectionDialog", "Basic Jinja template" |
38 "template": '''<!DOCTYPE html>\n''' |
40 ), |
39 ''' <head>\n''' |
41 "template": """<!DOCTYPE html>\n""" |
40 ''' {% if title %}\n''' |
42 """ <head>\n""" |
41 ''' <title>{{ title }}</title>\n''' |
43 """ {% if title %}\n""" |
42 ''' {% else %}\n''' |
44 """ <title>{{ title }}</title>\n""" |
43 ''' <title>Title</title>\n''' |
45 """ {% else %}\n""" |
44 ''' {% endif %}\n''' |
46 """ <title>Title</title>\n""" |
45 ''' </head>\n''' |
47 """ {% endif %}\n""" |
46 '''\n''' |
48 """ </head>\n""" |
47 ''' <body>\n''' |
49 """\n""" |
48 ''' <h1>Hello, {{ user.username }}!</h1>\n''' |
50 """ <body>\n""" |
49 ''' </body>\n''' |
51 """ <h1>Hello, {{ user.username }}!</h1>\n""" |
50 '''</html>\n''', |
52 """ </body>\n""" |
|
53 """</html>\n""", |
51 }, |
54 }, |
52 "jinja_base": { |
55 "jinja_base": { |
53 "title": QCoreApplication.translate( |
56 "title": QCoreApplication.translate( |
54 "FormSelectionDialog", "Jinja base template"), |
57 "FormSelectionDialog", "Jinja base template" |
55 "template": '''<!DOCTYPE html>\n''' |
58 ), |
56 ''' <head>\n''' |
59 "template": """<!DOCTYPE html>\n""" |
57 ''' {% if title %}\n''' |
60 """ <head>\n""" |
58 ''' <title>{{ title }}</title>\n''' |
61 """ {% if title %}\n""" |
59 ''' {% else %}\n''' |
62 """ <title>{{ title }}</title>\n""" |
60 ''' <title>Title</title>\n''' |
63 """ {% else %}\n""" |
61 ''' {% endif %}\n''' |
64 """ <title>Title</title>\n""" |
62 ''' </head>\n''' |
65 """ {% endif %}\n""" |
63 '''\n''' |
66 """ </head>\n""" |
64 ''' <body>\n''' |
67 """\n""" |
65 ''' {% block content %}{% endblock %}\n''' |
68 """ <body>\n""" |
66 ''' </body>\n''' |
69 """ {% block content %}{% endblock %}\n""" |
67 '''</html>\n''', |
70 """ </body>\n""" |
|
71 """</html>\n""", |
68 }, |
72 }, |
69 "jinja_extends": { |
73 "jinja_extends": { |
70 "title": QCoreApplication.translate( |
74 "title": QCoreApplication.translate( |
71 "FormSelectionDialog", "Jinja extension template"), |
75 "FormSelectionDialog", "Jinja extension template" |
72 "template": '''{% extends "base.html" %}\n''' |
76 ), |
73 '''\n''' |
77 "template": """{% extends "base.html" %}\n""" |
74 '''{% block content %}\n''' |
78 """\n""" |
75 ''' <h1>{{ user.username }}</h1>\n''' |
79 """{% block content %}\n""" |
76 ''' {% for item in items %}\n''' |
80 """ <h1>{{ user.username }}</h1>\n""" |
77 ''' <div><p>{{ item.field1 }}: {{ item.field2 }}''' |
81 """ {% for item in items %}\n""" |
78 '''</p></div>\n''' |
82 """ <div><p>{{ item.field1 }}: {{ item.field2 }}""" |
79 ''' {% endfor %}\n''' |
83 """</p></div>\n""" |
80 '''{% endblock %}\n''' |
84 """ {% endfor %}\n""" |
|
85 """{% endblock %}\n""", |
81 }, |
86 }, |
82 } |
87 } |
83 |
88 |
84 def __init__(self, parent=None): |
89 def __init__(self, parent=None): |
85 """ |
90 """ |
86 Constructor |
91 Constructor |
87 |
92 |
88 @param parent reference to the parent widget |
93 @param parent reference to the parent widget |
89 @type QWidget |
94 @type QWidget |
90 """ |
95 """ |
91 super().__init__(parent) |
96 super().__init__(parent) |
92 self.setupUi(self) |
97 self.setupUi(self) |
93 |
98 |
94 self.buttonBox.button( |
99 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
95 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
100 |
96 |
|
97 self.typeCombo.addItem("") |
101 self.typeCombo.addItem("") |
98 for templateType in FormSelectionDialog.Templates: |
102 for templateType in FormSelectionDialog.Templates: |
99 self.typeCombo.addItem( |
103 self.typeCombo.addItem( |
100 FormSelectionDialog.Templates[templateType]["title"], |
104 FormSelectionDialog.Templates[templateType]["title"], templateType |
101 templateType) |
105 ) |
102 self.typeCombo.setCurrentIndex(0) |
106 self.typeCombo.setCurrentIndex(0) |
103 |
107 |
104 @pyqtSlot(int) |
108 @pyqtSlot(int) |
105 def on_typeCombo_currentIndexChanged(self, index): |
109 def on_typeCombo_currentIndexChanged(self, index): |
106 """ |
110 """ |
107 Private slot to act upon a change of the selected template type. |
111 Private slot to act upon a change of the selected template type. |
108 |
112 |
109 @param index selected index |
113 @param index selected index |
110 @type int |
114 @type int |
111 """ |
115 """ |
112 templateType = self.typeCombo.itemData(index) |
116 templateType = self.typeCombo.itemData(index) |
113 if templateType: |
117 if templateType: |
114 self.preview.setPlainText( |
118 self.preview.setPlainText( |
115 FormSelectionDialog.Templates[templateType]["template"]) |
119 FormSelectionDialog.Templates[templateType]["template"] |
116 self.buttonBox.button( |
120 ) |
117 QDialogButtonBox.StandardButton.Ok).setEnabled(True) |
121 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(True) |
118 else: |
122 else: |
119 self.preview.clear() |
123 self.preview.clear() |
120 self.buttonBox.button( |
124 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
121 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
125 |
122 |
|
123 def getTemplateText(self): |
126 def getTemplateText(self): |
124 """ |
127 """ |
125 Public method to get the template text. |
128 Public method to get the template text. |
126 |
129 |
127 @return text of the template |
130 @return text of the template |
128 @rtype str |
131 @rtype str |
129 """ |
132 """ |
130 templateType = self.typeCombo.currentData() |
133 templateType = self.typeCombo.currentData() |
131 return FormSelectionDialog.Templates[templateType]["template"] |
134 return FormSelectionDialog.Templates[templateType]["template"] |