예제 #1
0
    def section(self, title, fgcol, bgcol, contents, width=6,
                prelude='', marginalia=None, gap=' '):
        """Format a section with a heading."""
        if marginalia is None:
            marginalia = '<tt>' + '&nbsp;' * width + '</tt>'
        result = FlexTable()
        result.setCellPadding(2)
        result.setCellSpacing(0)
        result.prepareRow(2)
        rf = result.getRowFormatter()
        cf = result.getCellFormatter()


        result.prepareCell(0, 1)
        result.setHTML(0, 0, """&nbsp;<br>
<font color="%s" face="helvetica, arial">%s</font>
    """ % (fgcol, title))
        cf.setColSpan(0, 0, 3)

        row = rf.getElement(0)
        DOM.setStyleAttribute(row, "background-color", bgcol) # TODO: add this to api

        if prelude:
            result.prepareRow(3)
            #result.prepareCell(1, 2)
            #result.prepareCell(2, 2)
            result.setHTML(1, 0, marginalia)
            cf.setRowSpan(1, 0, 2)
            result.setHTML(1, 1, prelude)
            cf.setColSpan(1, 1, 2)
            result.setHTML(2, 0, gap)

            #result.prepareCell(2, 1)
            result.setWidget(2, 1, contents)
            cf.setWidth(2, 1, "100%")

            row = rf.getElement(1)
            DOM.setStyleAttribute(row, "background-color", bgcol) # TODO: add this to api
        else:
            #result.prepareCell(1, 3)
            result.setHTML(1, 0, marginalia)
            result.setHTML(1, 1, gap)
            result.setWidget(1, 3, contents)
            cf.setWidth(1, 3, "100%")

            cell = cf.getElement(1, 0)
            DOM.setStyleAttribute(cell, "background-color", bgcol) # TODO: add this to api
        return result
예제 #2
0
def section(title, classname, contents):
    """Format a section with a heading."""
    width=6
    prelude=''
    marginalia=None
    gap='&nbsp;'
    if marginalia is None:
        marginalia = '<tt>'
        for i in range(width):
            marginalia += '&nbsp;' 
        marginalia += '</tt>'
    result = FlexTable()
    result.setCellPadding(2)
    result.setCellSpacing(0)
    result.prepareRow(2)
    rf = result.getRowFormatter()
    cf = result.getFlexCellFormatter()


    result.prepareCell(0, 1)
    cf.setColSpan(0, 0, 3)
    result.setHTML(0, 0, '&nbsp;<br><font face="helvetica, arial">%s</font>' % title)
    cf.setStyleName(0, 0, "title%s" % classname)
    rf.setStyleName(0, "margin%s" % classname)

    if prelude:
        result.prepareRow(3)
        result.prepareCell(1, 2)
        result.prepareCell(2, 2)
        cf.setRowSpan(1, 0, 2)
        cf.setColSpan(1, 1, 2)
        result.setHTML(1, 0, marginalia)
        result.setHTML(1, 1, prelude)
        result.setHTML(2, 0, gap)
        result.setWidget(2, 1, contents)
        cf.setWidth(2, 1, "100%")

        rf.setStyleName(1, "margin%s" % classname)
    else:
        result.prepareCell(1, 2)
        result.setHTML(1, 0, marginalia)
        result.setHTML(1, 1, gap)
        result.setWidget(1, 2, contents)
        cf.setWidth(1, 2, "100%")

        cf.setStyleName(1, 0, "margin%s" % classname)
    return result