--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ProjectPyramid/FormSelectionDialog.py Tue Aug 28 17:15:21 2012 +0200 @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing a dialog to select the template type. +""" + +from PyQt4.QtCore import pyqtSlot +from PyQt4.QtGui 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 (QWidget) + """ + super().__init__(parent) + self.setupUi(self) + + self.__templates = { + "html5" : [self.trUtf8("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''' + ], + "sections" : [self.trUtf8("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.Ok) + self.__okButton.setEnabled(False) + + self.typeCombo.addItem("") + for templateType in self.templates: + self.typeCombo.addItem(self.templates[templateType][0], + 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 (integer) + """ + 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 (string) + """ + templateType = self.typeCombo.itemData(self.typeCombo.currentIndex()) + return self.templates[templateType][1]