Tue, 10 Dec 2024 15:49:00 +0100
Updated copyright for 2025.
# -*- coding: utf-8 -*- # Copyright (c) 2012 - 2025 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog to select the template type. """ from PyQt6.QtCore import pyqtSlot from PyQt6.QtWidgets import QDialog, QDialogButtonBox from .Ui_FormSelectionDialog import Ui_FormSelectionDialog class FormSelectionDialog(QDialog, Ui_FormSelectionDialog): """ Class implementing a dialog to select the template type. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setupUi(self) self.__templates = { "html5": [ self.tr("Standard HTML 5 template"), """<!DOCTYPE html>\n""" """ <head>\n""" """ <title></title>\n""" """ <style>\n""" """ </style>\n""" """ </head>\n""" """\n""" """ <body>\n""" """ </body>\n""" """</html>\n""", ], "simple": [ self.tr("Standard HTML template"), """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"\n""" """ "http://www.w3.org/TR/html4/strict.dtd">\n""" """ <head>\n""" """ <title></title>\n""" """ <style>\n""" """ </style>\n""" """ </head>\n""" """\n""" """ <body>\n""" """ </body>\n""" """</html>\n""", ], "complex": [ self.tr("Chameleon template"), """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0""" """ Strict//EN"\n""" """ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n""" '''<html xmlns="http://www.w3.org/1999/xhtml"''' """ xml:lang="en"\n""" """ xmlns:tal="http://xml.zope.org/namespaces/tal">\n""" """ xmlns:metal="http://xml.zope.org/namespaces/""" """metal">\n""" """<head>\n""" """ <title>The Pyramid Web Application Development""" """ Framework</title>\n""" """ <meta http-equiv="Content-Type"\n""" """ content="text/html;charset=UTF-8"/>\n""" ''' <meta name="keywords" content="python web application"''' """ />\n""" """ <meta name="description" content="pyramid web""" """ application" />\n""" """ <link rel="shortcut icon"\n""" """ href="${request.static_url('site:static/""" """favicon.ico')}" />\n""" """ <link rel="stylesheet"\n""" """ href="${request.static_url('site:static/""" """pylons.css')}"\n""" """ type="text/css" media="screen" charset="utf-8" />\n""" """ <link rel="stylesheet"\n""" """ href="http://static.pylonsproject.org/fonts/nobile/""" """stylesheet.css"\n""" """ media="screen" />\n""" """ <link rel="stylesheet"\n""" """ href="http://static.pylonsproject.org/fonts/neuton/""" """stylesheet.css"\n""" """ media="screen" />\n""" """ <!--[if lte IE 6]>\n""" """ <link rel="stylesheet"\n""" """ href="${request.static_url('site:static/ie6.css')}"\n""" """ type="text/css" media="screen" charset="utf-8" />\n""" """ <![endif]-->\n""" """</head>\n""" """<body>\n""" """ <div id="wrap">\n""" """ <div id="top">\n""" """ </div>\n""" """ <div id="middle">\n""" """ </div>\n""" """ <div id="bottom">\n""" """ </div>\n""" """ </div>\n""" """ <div id="footer">\n""" """ <div class="footer">© Copyright 2012, Somebody.""" """</div>\n""" """ </div>\n""" """</body>\n""" """</html>\n""", ], "sections": [ self.tr("Mako template with sections"), """## -*- coding: utf-8 -*-\n""" """\n""" """<!DOCTYPE html>\n""" """<html>\n""" """<head>\n""" """ <title>${self.title()}</title>\n""" """ ${self.head()}\n""" """</head>\n""" """<body>\n""" """ ${self.header()}\n""" """ ${self.tabs()}\n""" """ ${self.menu()}\n""" """ ${self.heading()}\n""" """ ${self.breadcrumbs()}\n""" """ ${next.body()}\n""" """ ${self.footer()}\n""" """</body>\n""" """</html>\n""" """\n""" """<%def name="title()">SimpleSite</%def>\n""" """<%def name="head()"></%def>\n""" """<%def name="header()"><a name="top"></a></%def>\n""" """<%def name="tabs()"></%def>\n""" """<%def name="menu()"></%def>\n""" """<%def name="heading()"><h1>${c.heading or 'No Title'}""" """</h1></%def>\n""" """<%def name="breadcrumbs()"></%def>\n""" """<%def name="footer()"><p><a href="#top">Top ^</a></p>""" """</%def>\n""", ], } self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) self.__okButton.setEnabled(False) templates = {} for templateType in self.__templates: templates[self.__templates[templateType][0]] = templateType self.typeCombo.addItem("") for templateString, templateType in sorted(templates.items()): self.typeCombo.addItem(templateString, 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(self.__templates[templateType][1]) self.__okButton.setEnabled(True) else: self.preview.clear() self.__okButton.setEnabled(False) def getTemplateText(self): """ Public method to get the template text. @return text of the template @rtype str """ templateType = self.typeCombo.itemData(self.typeCombo.currentIndex()) return self.__templates[templateType][1]