Synopsis - Synopsis/Formatters/HTML/Frame.py

File: Synopsis/Formatters/HTML/Frame.py

     1#
     2# Copyright (C) 2006 Stefan Seefeld
     3# All rights reserved.
     4# Licensed to the public under the terms of the GNU LGPL (>= 2),
     5# see the file COPYING for details.
     6#
     7
     8from Synopsis.Formatters.HTML.Tags import *
     9import sys, time
    10
    11class Frame:
    12    """A Frame is a mediator for views that get displayed in it (as well
    13    as other frames. It supports the creation of links across views."""
    14
    15    def __init__(self, processor, views, noframes = False):
    16
    17        self.processor = processor
    18        self.views = views
    19        self.noframes = noframes
    20        if self.noframes:
    21            self.views[0].main = True
    22        for v in self.views:
    23            v.register(self)
    24
    25    def process(self):
    26
    27        for v in self.views:
    28            v.register_filenames()
    29
    30        for v in self.views:
    31            if self.processor.profile:
    32                print 'Time for %s:'%v.__class__.__name__,
    33                sys.stdout.flush()
    34                start_time = time.time()
    35            v.process()
    36            if self.processor.profile:
    37                print '%f seconds'%(time.time() - start_time)
    38
    39
    40    def navigation_bar(self, view):
    41        """Generates a navigation bar for the given view."""
    42
    43        # Only include views that set a root title.
    44        views = [v for v in self.views if v.root()[1]]
    45
    46        def item(v):
    47            """Generate a navigation bar item."""
    48
    49            url, label = v.root()
    50            if url == view.filename():
    51                return span('selected', label) + '\n'
    52            else:
    53                return span('normal', href(rel(view.filename(), url), label)) + '\n'
    54
    55        items = [item(v) for v in views]
    56        return items and div('navigation', '\n' + ''.join(items)) or ''
    57
    58
    59
    60

Generated on Thu Apr 16 16:27:16 2009 by
synopsis (version devel)