import os
class DisplayHTMLRaw(object):
def __init__(self, html=''):
self.html = html
def setRawHTML(self, html):
self.html = html
def _build(self, f, html):
if html: f.write(html)
def build(self, f):
self._build(self.html)
class DisplayHTMLBlock(DisplayHTMLRaw):
def __init__(self, title=''):
super(DisplayHTMLBlock, self).__init__(html='')
self.title = title
self.cssclass = 'iwla_block'
self.title_cssclass = 'iwla_block_title'
self.value_cssclass = 'iwla_block_value'
def getTitle(self):
return self.title
def setTitle(self, value):
self.title = value
def setCSSClass(self, cssclass):
self.cssclass = cssclass
def setTitleCSSClass(self, cssclass):
self.title_cssclass = cssclass
def setValueCSSClass(self, cssclass):
self.value_cssclass = cssclass
def build(self, f):
html = '
' % (self.cssclass)
if self.title:
html += '
%s
' % (self.title_cssclass, self.title)
html += '
%s
' % (self.value_cssclass, self.html)
html += '
'
self._build(f, html)
class DisplayHTMLBlockTable(DisplayHTMLBlock):
def __init__(self, title, cols):
super(DisplayHTMLBlockTable, self).__init__(title=title)
self.cols = cols
self.rows = []
self.cols_cssclasses = ['' for e in cols]
self.rows_cssclasses = []
def appendRow(self, row):
self.rows.append(listToStr(row))
self.rows_cssclasses.append(['' for e in row])
def getCellValue(row, col):
if row < 0 or col < 0 or\
row >= len(self.rows) or col >= len(self.cols):
raise ValueError('Invalid indices')
return self.rows[row][col]
def setCellValue(row, col, value):
if row < 0 or col < 0 or\
row >= len(self.rows) or col >= len(self.cols):
raise ValueError('Invalid indices')
return self.rows[row][col]
def setCellCSSClass(row, col, value):
if row < 0 or col < 0 or\
row >= len(self.rows) or col >= len(self.cols):
raise ValueError('Invalid indices')
self.rows_cssclasses[row][col] = value
def setRowCSSClass(row, value):
if row < 0 or row >= len(self.rows):
raise ValueError('Invalid indice')
for i in range(0, self.rows_cssclasses[row]):
self.rows_cssclasses[row][i] = value
def build(self, f):
if not self.html:
html = ''
html += ''
for title in self.cols:
html += '%s | ' % (title)
html += '
'
for row in self.rows:
html += ''
for v in row:
html += '%s | ' % (v)
html += '
'
html += '
'
self.html = html
super(DisplayHTMLBlockTable, self).build(f)
class DisplayHTMLPage(object):
def __init__(self, title, filename):
self.title = title
self.filename = filename
self.blocks = []
def getFilename(self):
return self.filename;
def getBlock(self, title):
for b in self.blocks:
if title == b.getTitle():
return b
return None
def appendBlock(self, block):
self.blocks.append(block)
def build(self, root):
filename = root + self.filename
base = os.path.dirname(filename)
if not os.path.exists(base):
os.makedirs(base)
f = open(filename, 'w')
f.write('')
f.write('')
f.write('')
f.write('')
if self.title:
f.write('%s' % (self.title))
f.write('')
for block in self.blocks:
block.build(f)
f.write('