ProjectPyramid/FormSelectionDialog.py

Sun, 27 Oct 2013 22:43:17 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Sun, 27 Oct 2013 22:43:17 +0100
changeset 56
c7adc68350dd
parent 34
d20f7218d53c
child 57
e654970c913e
permissions
-rw-r--r--

Python 2 compatibility for Eric 5.

# -*- coding: utf-8 -*-

# Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to select the template type.
"""

from __future__ import unicode_literals    # __IGNORE_WARNING__

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(FormSelectionDialog, self).__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'''
                ],
            "simple": [self.trUtf8("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.trUtf8("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">&copy; Copyright 2012, Somebody.</div>\n'''
                '''  </div>\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)
        
        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 (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]

eric ide

mercurial