Fixed a bug in HTML table widths; allow args to make_basic_stylesheet; add scrollbars to tabbed items

svn: r13660
This commit is contained in:
Doug Blank 2009-11-23 01:39:29 +00:00
parent 8e0593d7ad
commit 2ed9ac56e4
3 changed files with 68 additions and 7 deletions

View File

@ -73,9 +73,17 @@ class SimpleDoc(object):
"""
self.__write('Normal', text)
def make_basic_stylesheet():
def make_basic_stylesheet(**kwargs):
"""
Create the basic style sheet for the SimpleDoc class
Create the basic style sheet for the SimpleDoc class.
kwargs - a dictionary of the form:
item={method: value, ...}, ...
Example:
make_basic_stylesheet(Table={"set_width": 90})
"""
sheet = StyleSheet()
@ -86,6 +94,12 @@ def make_basic_stylesheet():
fstyle.set_bold(True)
pstyle.set_font(fstyle)
pstyle.set_alignment(PARA_ALIGN_LEFT)
# Handle args:
if "Title" in kwargs:
for method in kwargs["Title"]:
value = kwargs["Title"][method]
if value is not None:
getattr(pstyle, method)(value)
sheet.add_paragraph_style('Title', pstyle)
pstyle = ParagraphStyle()
@ -96,6 +110,12 @@ def make_basic_stylesheet():
pstyle.set_font(fstyle)
pstyle.set_alignment(PARA_ALIGN_LEFT)
pstyle.set_tabs([4, 8, 12, 16])
# Handle args:
if "Header1" in kwargs:
for method in kwargs["Header1"]:
value = kwargs["Header1"][method]
if value is not None:
getattr(pstyle, method)(value)
sheet.add_paragraph_style('Header1', pstyle)
pstyle = ParagraphStyle()
@ -106,6 +126,12 @@ def make_basic_stylesheet():
pstyle.set_font(fstyle)
pstyle.set_alignment(PARA_ALIGN_LEFT)
pstyle.set_tabs([4, 8, 12, 16])
# Handle args:
if "Header2" in kwargs:
for method in kwargs["Header2"]:
value = kwargs["Header2"][method]
if value is not None:
getattr(pstyle, method)(value)
sheet.add_paragraph_style('Header2', pstyle)
pstyle = ParagraphStyle()
@ -117,10 +143,22 @@ def make_basic_stylesheet():
pstyle.set_font(fstyle)
pstyle.set_alignment(PARA_ALIGN_LEFT)
pstyle.set_tabs([4, 8, 12, 16])
# Handle args:
if "Header3" in kwargs:
for method in kwargs["Header3"]:
value = kwargs["Header3"][method]
if value is not None:
getattr(pstyle, method)(value)
sheet.add_paragraph_style('Header3', pstyle)
pstyle = ParagraphStyle()
pstyle.set_tabs([4, 8, 12, 16])
# Handle args:
if "Normal" in kwargs:
for method in kwargs["Normal"]:
value = kwargs["Normal"][method]
if value is not None:
getattr(pstyle, method)(value)
sheet.add_paragraph_style('Normal', pstyle)
# Styles for tables:
@ -129,18 +167,42 @@ def make_basic_stylesheet():
tbl.set_columns(2)
tbl.set_column_width(0,20)
tbl.set_column_width(1,80)
# Handle args:
if "Table" in kwargs:
for method in kwargs["Table"]:
value = kwargs["Table"][method]
if value is not None:
getattr(tbl, method)(value)
sheet.add_table_style("Table",tbl)
cell = TableCellStyle()
cell.set_top_border(1)
cell.set_bottom_border(1)
# Handle args:
if "TableHead" in kwargs:
for method in kwargs["TableHead"]:
value = kwargs["TableHead"][method]
if value is not None:
getattr(cell, method)(value)
sheet.add_cell_style("TableHead",cell)
cell = TableCellStyle()
# Handle args:
if "TableHeaderCell" in kwargs:
for method in kwargs["TableHeaderCell"]:
value = kwargs["TableHeaderCell"][method]
if value is not None:
getattr(cell, method)(value)
sheet.add_cell_style("TableHeaderCell",cell)
cell = TableCellStyle()
cell.set_longlist(1)
# Handle args:
if "TableDataCell" in kwargs:
for method in kwargs["TableDataCell"]:
value = kwargs["TableDataCell"][method]
if value is not None:
getattr(cell, method)(value)
sheet.add_cell_style("TableDataCell",cell)
return sheet

View File

@ -339,7 +339,7 @@ class HtmlDoc(BaseDoc, TextDoc):
"""
styles = self.get_style_sheet()
self._tbl = styles.get_table_style(style)
self.htmllist += [Html('table', width=str(self._tbl.get_width())+'%%',
self.htmllist += [Html('table', width=str(self._tbl.get_width())+'%',
cellspacing='0')]
def end_table(self):
@ -373,7 +373,7 @@ class HtmlDoc(BaseDoc, TextDoc):
else:
self.htmllist += (Html('td', colspan=str(span),
width=str(self._tbl.get_column_width(
self._col))+ '%%',
self._col))+ '%',
class_=style_name),)
self._col += 1

View File

@ -83,11 +83,10 @@ class Table(object):
def __init__(self, doc):
self.doc = doc
# None is paperstyle, which is ignored:
self.doc = Doc(HtmlDoc.HtmlDoc(make_basic_stylesheet(), None))
self.doc = Doc(HtmlDoc.HtmlDoc(make_basic_stylesheet(Table={"set_width":95}), None))
self.doc.doc._backend = HtmlBackend()
# You can set elements id, class, etc:
# self.doc.doc.htmllist += [Html('div', id="grampstextdoc")]
self.doc.doc.htmllist += [Html('div')]
self.doc.doc.htmllist += [Html('div', style="overflow: auto; height:150px; background-color: white;")]
def columns(self, *args):
self.table.columns(*args)