Very nice result
This commit is contained in:
111
display.py
111
display.py
@@ -1,51 +1,70 @@
|
||||
|
||||
def createPage(display, filename, title):
|
||||
page = {}
|
||||
page['title'] = title;
|
||||
page['blocks'] = []
|
||||
display[filename] = page
|
||||
class DisplayHTMLBlock(object):
|
||||
|
||||
return page
|
||||
def __init__(self, title):
|
||||
self.title = title
|
||||
|
||||
def appendBlockToPage(page, block):
|
||||
page['blocks'].append(block)
|
||||
def build(self, f):
|
||||
pass
|
||||
|
||||
def createTable(title, cols):
|
||||
table = {'type' : 'table', 'title' : title}
|
||||
table['cols'] = cols
|
||||
table['rows'] = []
|
||||
|
||||
return table
|
||||
|
||||
def appendRowToTable(table, row):
|
||||
table['rows'].append(row)
|
||||
|
||||
def buildTable(block, f):
|
||||
print 'Write table %s' % block['title']
|
||||
f.write('<table>')
|
||||
f.write('<tr>')
|
||||
for title in block['cols']:
|
||||
f.write('<th>%s</th>' % (title))
|
||||
f.write('</tr>')
|
||||
for row in block['rows']:
|
||||
f.write('<tr>')
|
||||
for v in row:
|
||||
f.write('<td>%s</td>' % (v))
|
||||
f.write('</tr>')
|
||||
f.write('</table>')
|
||||
class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
||||
|
||||
def buildPages(display_root, display):
|
||||
for filename in display.keys():
|
||||
page = display[filename]
|
||||
print "OPEN %s" % (display_root + filename)
|
||||
with open(display_root + filename, 'w') as f:
|
||||
f.write('<html><title>%s</title><body>' % (page['title']))
|
||||
for block in page['blocks']:
|
||||
print "Bluid block"
|
||||
print block
|
||||
print "End block"
|
||||
if block['type'] == 'html':
|
||||
f.write(block['value'])
|
||||
elif block['type'] == 'table':
|
||||
buildTable(block, f)
|
||||
f.write('</body></html>')
|
||||
def __init__(self, title, cols):
|
||||
super(DisplayHTMLBlockTable, self).__init__(title)
|
||||
self.cols = cols
|
||||
self.rows = []
|
||||
|
||||
def appendRow(self, row):
|
||||
self.rows.append(row)
|
||||
|
||||
def build(self, f):
|
||||
f.write('<table>')
|
||||
f.write('<tr>')
|
||||
for title in self.cols:
|
||||
f.write('<th>%s</th>' % (title))
|
||||
f.write('</tr>')
|
||||
for row in self.rows:
|
||||
f.write('<tr>')
|
||||
for v in row:
|
||||
f.write('<td>%s</td>' % (v))
|
||||
f.write('</tr>')
|
||||
f.write('</table>')
|
||||
|
||||
class DisplayHTMLPage(object):
|
||||
|
||||
def __init__(self, title, filename):
|
||||
self.title = title
|
||||
self.filename = filename
|
||||
self.blocks = []
|
||||
|
||||
def getFilename(self):
|
||||
return self.filename;
|
||||
|
||||
def appendBlock(self, block):
|
||||
self.blocks.append(block)
|
||||
|
||||
def build(self, root):
|
||||
f = open(root + self.filename, 'w')
|
||||
f.write('<html><title>%s</title><body>' % (self.title))
|
||||
for block in self.blocks:
|
||||
block.build(f)
|
||||
f.write('</body></html>')
|
||||
f.close()
|
||||
|
||||
class DisplayHTMLBuild(object):
|
||||
|
||||
def __init__(self):
|
||||
self.pages = []
|
||||
|
||||
def getPage(self, filename):
|
||||
for page in self.pages:
|
||||
if page.getFilename() == filename:
|
||||
return page
|
||||
return None
|
||||
|
||||
def addPage(self, page):
|
||||
self.pages.append(page)
|
||||
|
||||
def build(self, root):
|
||||
for page in self.pages:
|
||||
page.build(root)
|
||||
|
||||
Reference in New Issue
Block a user