Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ep_formater_html.py
diff options
context:
space:
mode:
authorThomas Jourdan <b.vehikel@googlemail.com>2009-12-06 12:40:41 (GMT)
committer Thomas Jourdan <b.vehikel@googlemail.com>2009-12-06 12:40:41 (GMT)
commit7ce7155dead3893e572006588fc342fb3af7ec60 (patch)
tree2bb234d6d159aa797767bf1ceccea53117dc773a /ep_formater_html.py
parentbcde11455168a07de8a3b17f2a4d77ce8931e75d (diff)
Layers are now arranged as a tree data structure.
Diffstat (limited to 'ep_formater_html.py')
-rw-r--r--ep_formater_html.py135
1 files changed, 95 insertions, 40 deletions
diff --git a/ep_formater_html.py b/ep_formater_html.py
index 8db6de7..be421fb 100644
--- a/ep_formater_html.py
+++ b/ep_formater_html.py
@@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+"""Generate HTML describing the genome."""
+
import os
import sys
import ka_debug
@@ -25,7 +27,7 @@ import exon_direction
ICON_WIDTH = ICON_HEIGHT = 48
class HtmlFormater(object):
- """HtmlFormater
+ """Html formater
inv: self._indent >= 0
"""
@@ -39,7 +41,6 @@ class HtmlFormater(object):
self._indent = 0
self._page = u''
self.id_count = 0
-# self.strategy = {}
self._header_occured = False # debugging only
self._footer_occured = False # debugging only
file_path = os.path.join(base_folder, unique_id)
@@ -51,6 +52,10 @@ class HtmlFormater(object):
def _escape(self, text):
+ """Quote special characters '<' and '&'.
+ This must be done to produce correct HTML.
+ pre: text is not None
+ """
utext = unicode(text)
quoted = u''
for uchar in utext:
@@ -63,32 +68,44 @@ class HtmlFormater(object):
return quoted
def _append(self, lines):
+ """Append lines to HTML page.
+ pre: lines is not None
+ """
indenting = u' '*(2*self._indent)
for line in lines:
self._page += indenting + line + u'\n'
def _append_escaped(self, text):
+ """Append text to HTML page.
+ pre: text is not None
+ """
self._page += self._escape(text)
def _get_id(self):
+ """Returns a unique id.
+ All elements generated are decorated with an id.
+ We need this to use the HTML page like a tree widget.
+ """
self.id_count += 1
return u'id_' + unicode(self.id_count)
def get_pathname(self, extension, postfix=None):
+ """Returns path appended by filename of the generated HTML page."""
return os.path.join(self._base_folder,
self.unique_id,
self.get_filename(extension, postfix))
def get_filename(self, extension, postfix=None):
+ """Returns the filename only of the generated HTML page."""
postfix = '' if postfix is None else '_' + postfix
return self._base_name + postfix + '.' + extension
def header(self, title):
- """
+ """Generate starting sequence to the HTML page.
pre: not self._header_occured
pre: not self._footer_occured
"""
- self._append( ( \
+ self._append( (
u'<?xml version="1.0" encoding="UTF-8"?>',
u'<?xml-stylesheet href="treestyles.css" type="text/css"?>',
u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"',
@@ -99,8 +116,8 @@ class HtmlFormater(object):
u' <meta name="generator" content="' + HtmlFormater.generator +'" />',
u'',
u' <title>' + title + u'</title>',
- u' <link rel="stylesheet" href="' + self._base_name + u'_files/treestyles.css" type="text/css" />',
- u' <script type="text/javascript" src="' + self._base_name + u'_files/marktree.js">',
+ u' <link rel="stylesheet" href="marktree/treestyles.css" type="text/css" />',
+ u' <script type="text/javascript" src="marktree/marktree.js">',
u'//<![CDATA[',
u'',
u' //]]>',
@@ -120,12 +137,12 @@ class HtmlFormater(object):
self._header_occured = True
def footer(self):
- """
+ """Generate finishing sequence to the HTML page.
pre: self._indent == 0
pre: self._header_occured
pre: not self._footer_occured
"""
- self._append( ( \
+ self._append( (
u' </ul>',
u' </div>',
u'</body>',
@@ -134,31 +151,37 @@ class HtmlFormater(object):
self._footer_occured = True
def _begin_list_item(self, identification):
- """
+ """Start a list item.
pre: self._header_occured
pre: not self._footer_occured
"""
- self._append( ( \
+ self._append( (
u' <li class="basic" style="" id="id_' + identification + u'" >',
u' <span style="">',
) )
def _end_list_item(self):
- """
+ """Close a list item.
pre: self._header_occured
pre: not self._footer_occured
"""
- self._append( ( \
+ self._append( (
u' </span>',
u' </li>',
) )
def _image_item(self, filename, width, height, description, newline=True):
+ """Append an image tag to the page.
+ pre: filename is not None
+ pre: width is not None
+ pre: height is not None
+ pre: description is not None
+ """
if newline:
- self._append( ( \
+ self._append( (
u' <br />',
) )
- self._append( ( \
+ self._append( (
u' <img src="' + filename + u'"' \
+ u' width="' + unicode(width) + u'"' \
+ u' height="' + unicode(height) + u'"' \
@@ -167,41 +190,44 @@ class HtmlFormater(object):
) )
def begin_list(self, text):
- """
+ """Start a list.
pre: self._header_occured
pre: not self._footer_occured
+ pre: text is not None
"""
self._indent += 1
- self._append( ( \
+ self._append( (
u' <li class="col" style="" id="' + self._get_id() + u'">',
self._escape(text),
u' <ul class="subexp">',
) )
def end_list(self):
- """
+ """Close a list.
pre: self._header_occured
pre: not self._footer_occured
"""
- self._append( ( \
+ self._append( (
u' </ul>',
u' </li>',
) )
self._indent -= 1
def text_item(self, text):
- """
+ """Generate an item for using in text lists.
pre: self._header_occured
pre: not self._footer_occured
+ pre: text is not None
"""
self._begin_list_item(self._get_id())
self._append_escaped(text)
self._end_list_item()
def text_list(self, title, text_list):
- """
+ """Generate a text list.
pre: self._header_occured
pre: not self._footer_occured
+ pre: text_list is not None
"""
self._begin_list_item(self._get_id())
self._append_escaped(title)
@@ -209,44 +235,52 @@ class HtmlFormater(object):
self._append_escaped(text + u', ')
self._end_list_item()
- def color_item(self, color, text, alfa=True):
- """
+ def color_item(self, color, text, alpha=True):
+ """Generate a preview icon showing colors.
pre: self._header_occured
pre: not self._footer_occured
+ pre: color is not None
+ pre: text is not None
"""
identification = self._get_id()
pathname = self.get_pathname('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
- surface = exon_color.Color.make_icon(color.rgba, alfa, ICON_WIDTH, ICON_HEIGHT)
+ surface = exon_color.Color.make_icon(color.rgba, alpha,
+ ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
- description = color.explain(alfa)
+ description = color.explain(alpha)
self._begin_list_item(identification)
self._append_escaped(text)
self._image_item(filename, ICON_WIDTH, ICON_HEIGHT, description)
self._end_list_item()
- def alfa_item(self, alfa, text):
- """
+ def alpha_item(self, alpha, text):
+ """Generate a preview icon showing transparency.
pre: self._header_occured
pre: not self._footer_occured
+ pre: alpha is not None
+ pre: text is not None
"""
identification = self._get_id()
pathname = self.get_pathname('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
- surface = exon_color.Color.make_icon((1.0, 1.0, 1.0, alfa), True, ICON_WIDTH, ICON_HEIGHT)
+ surface = exon_color.Color.make_icon((1.0, 1.0, 1.0, alpha), True,
+ ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
- description = '%d%% opaque' % (100*alfa)
+ description = '%d%% opaque' % (100*alpha)
self._begin_list_item(self._get_id())
self._append_escaped(text)
self._image_item(filename, ICON_WIDTH, ICON_HEIGHT, description)
self._end_list_item()
- def color_array(self, color_list, text, alfa=True):
- """
+ def color_array(self, color_list, text, alpha=True):
+ """Generate some preview icons showing colors.
pre: self._header_occured
pre: not self._footer_occured
+ pre: color_list is not None
+ pre: text is not None
"""
self._begin_list_item(self._get_id())
self._append_escaped(text)
@@ -255,21 +289,29 @@ class HtmlFormater(object):
identification = self._get_id()
pathname = self.get_pathname('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
- surface = color.make_icon(color.rgba, alfa, ICON_WIDTH, ICON_HEIGHT)
+ surface = color.make_icon(color.rgba, alpha,
+ ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
- description = color.explain(alfa)
+ description = color.explain(alpha)
self._image_item(filename, ICON_WIDTH, ICON_HEIGHT, \
description, newline=False)
self._end_list_item()
def position_item(self, position, text):
+ """Generate a preview icon showing a position.
+ pre: self._header_occured
+ pre: not self._footer_occured
+ pre: position is not None
+ pre: text is not None
+ """
self.position_array([position], text)
def position_array(self, position_list, text):
- """
+ """Generate some preview icons showing positions.
pre: self._header_occured
pre: not self._footer_occured
- pre: len(position_list) >= 0
+ pre: position_list is not None
+ pre: text is not None
"""
description = u'['
for position in position_list:
@@ -281,19 +323,27 @@ class HtmlFormater(object):
identification = self._get_id()
pathname = self.get_pathname('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
- surface = exon_position.Position.make_icon(position_list, ICON_WIDTH, ICON_HEIGHT)
+ surface = exon_position.Position.make_icon(position_list,
+ ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
self._image_item(filename, ICON_WIDTH, ICON_HEIGHT, description)
self._end_list_item()
def direction_item(self, direction, text):
+ """Generate a preview icon showing one direction vectors.
+ pre: self._header_occured
+ pre: not self._footer_occured
+ pre: direction is not None
+ pre: text is not None
+ """
self.direction_array([direction], text)
def direction_array(self, direction_list, text):
- """
+ """Generate some preview icons showing direction vectors.
pre: self._header_occured
pre: not self._footer_occured
- pre: len(direction_list) >= 0
+ pre: direction_list is not None
+ pre: text is not None
"""
description = u'['
for direction in direction_list:
@@ -305,15 +355,19 @@ class HtmlFormater(object):
identification = self._get_id()
pathname = self.get_pathname('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
- surface = exon_direction.Direction.make_icon(direction_list, ICON_WIDTH, ICON_HEIGHT)
+ surface = exon_direction.Direction.make_icon(direction_list,
+ ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
self._image_item(filename, ICON_WIDTH, ICON_HEIGHT, description)
self._end_list_item()
def surface_item(self, surface, text, description):
- """
+ """Generate a preview icon of the layers surface.
pre: self._header_occured
pre: not self._footer_occured
+ pre: surface is not None
+ pre: text is not None
+ pre: description is not None
"""
identification = self._get_id()
pathname = self.get_pathname('png', postfix=identification)
@@ -328,10 +382,11 @@ class HtmlFormater(object):
self._end_list_item()
def write_html_file(self, file_path):
- """
+ """Write HTML to the file system.
pre: self._header_occured
pre: self._footer_occured
pre: self._indent == 0
+ pre: file_path is not None
"""
out_file = None
try: