Exemplo n.º 1
0
class PageEmpty(Container):
    """
    Widget for minimalistic web pages. Simplified variant with less
    arguments, but otherwise similar to Page.

    Arguments:
        headers: list of entries for the <head> section.

    Example:
        page = CTK.PageEmpty ()
        page += CTK.RawHTML ('<p>Nothing to see here.</p>')
        return page.Render()
    """
    def __init__(self, headers=[], **kwargs):
        Container.__init__(self, **kwargs)

        self.headers = headers[:]
        self.template = Template(content=PAGE_TEMPLATE_MINI)

    def Render(self):
        # Get the content render
        render = Container.Render(self)

        # Build the <head> text
        self.headers += render.headers
        head = "\n".join(uniq(self.headers))

        self.template['head'] = head
        self.template['body'] = render.html

        # Render
        txt = self.template.Render()
        return Postprocess(txt)
Exemplo n.º 2
0
class PageEmpty (Container):
    def __init__ (self, headers=[], **kwargs):
        Container.__init__ (self, **kwargs)

        self.headers  = headers[:]
        self.template = Template (content = PAGE_TEMPLATE_MINI)

    def Render(self):
        # Get the content render
        render = Container.Render(self)

        # Build the <head> text
        self.headers += render.headers
        head = "\n".join (uniq(self.headers))

        self.template['head']  = head
        self.template['body']  = render.html

        # Render
        txt = self.template.Render()
        return Postprocess (txt)
Exemplo n.º 3
0
class Page(Container):
    """
    Base widget for web pages. Typically an instance of this class (or
    a class inheriting from it) is used as top level container to
    which every other CTK widget is added.

    Arguments:
        template: custom CTK Template for the pages
        headers: list of entries for the <head> section.
        helps: parameters for CTK HelpMenu, if any.

    Example:
        page = CTK.Page ()
        page += CTK.RawHTML ('<p>Nothing to see here.</p>')
        return page.Render()
    """
    def __init__(self, template=None, headers=None, helps=None, **kwargs):
        Container.__init__(self, **kwargs)
        self.js_header_end = True

        if headers:
            self._headers = HEADERS[:] + headers[:]
        else:
            self._headers = HEADERS[:]

        if template:
            self._template = template
        else:
            self._template = Template(content=PAGE_TEMPLATE_DEFAULT)

        self._helps = []
        for entry in helps or []:
            self._helps.append(HelpEntry(entry[1], entry[0]))

    def AddHeaders(self, headers):
        if type(headers) == list:
            self._headers += headers
        else:
            self._headers.append(headers)

    def Render(self):
        # Get the content render
        render = Container.Render(self)

        # Build the <head> text
        self._headers += render.headers

        if self.js_header_end:
            head = "\n".join(
                filter(lambda l: not '<script' in l, uniq(self._headers)))
        else:
            head = "\n".join(uniq(self._headers))

        # Helps
        all_helps = self._helps
        all_helps += render.helps

        render_helps = HelpMenu(all_helps).Render().html

        # Javascript
        js = ''

        if self.js_header_end:
            js += "\n".join(
                filter(lambda l: '<script' in l, uniq(self._headers)))

        if render.js:
            js += formatter(HTML_JS_ON_READY_BLOCK, render.js)

        # Build the <body>
        body = render.html + render_helps
        if render.js:
            body += js

        # Set up the template
        self._template['head'] = head
        self._template['html'] = render.html
        self._template['js'] = js
        self._template['body'] = body
        self._template['helps'] = render_helps

        if not self._template['body_props']:
            self._template['body_props'] = ''

        txt = self._template.Render()
        return Postprocess(txt)
Exemplo n.º 4
0
class Page (Container):
    def __init__ (self, template=None, headers=None, helps=[], **kwargs):
        Container.__init__ (self, **kwargs)
        self.js_header_end = True

        if headers:
            self._headers = HEADERS + headers
        else:
            self._headers = HEADERS

        if template:
            self._template = template
        else:
            self._template = Template (content = PAGE_TEMPLATE_DEFAULT)

        self._helps = []
        for entry in helps:
            self._helps.append (HelpEntry (entry[1], entry[0]))

    def AddHeaders (self, headers):
        if type(headers) == list:
            self._headers += headers
        else:
            self._headers.append (headers)

    def Render(self):
        # Get the content render
        render = Container.Render(self)

        # Build the <head> text
        self._headers += render.headers

        if self.js_header_end:
            head = "\n".join (filter (lambda l: not '<script' in l, uniq(self._headers)))
        else:
            head = "\n".join (uniq(self._headers))

        # Helps
        all_helps  = self._helps
        all_helps += render.helps

        render_helps = HelpMenu(all_helps).Render().html

        # Javascript
        js = ''

        if self.js_header_end:
            js += "\n".join (filter (lambda l: '<script' in l, uniq(self._headers)))

        if render.js:
            js += formater (HTML_JS_ON_READY_BLOCK, render.js)

        # Build the <body>
        body = render.html + render_helps
        if render.js:
            body += js

        # Set up the template
        self._template['head']  = head
        self._template['html']  = render.html
        self._template['js']    = js
        self._template['body']  = body
        self._template['helps'] = render_helps

        if not self._template['body_props']:
            self._template['body_props'] = ''

        txt = self._template.Render()
        return Postprocess (txt)