| 1 | # Copyright (C) 2008 Adriano Monteiro Marques. |
|---|
| 2 | # |
|---|
| 3 | # Author: Luis A. Bastiao Silva <luis.kop@gmail.com> |
|---|
| 4 | # |
|---|
| 5 | # This program is free software; you can redistribute it and/or modify |
|---|
| 6 | # it under the terms of the GNU General Public License as published by |
|---|
| 7 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | # (at your option) any later version. |
|---|
| 9 | # |
|---|
| 10 | # This program is distributed in the hope that it will be useful, |
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | # GNU General Public License for more details. |
|---|
| 14 | # |
|---|
| 15 | # You should have received a copy of the GNU General Public License |
|---|
| 16 | # along with this program; if not, write to the Free Software |
|---|
| 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | HEADER = "<html>" |
|---|
| 21 | HEADER_C = "<html>" |
|---|
| 22 | TITLE = "<title>" |
|---|
| 23 | TITLE_C = "</title>" |
|---|
| 24 | BL = "<br />" |
|---|
| 25 | |
|---|
| 26 | STYLE = """ |
|---|
| 27 | |
|---|
| 28 | body { |
|---|
| 29 | margin-left:auto; margin-right:auto; |
|---|
| 30 | text-align:center; |
|---|
| 31 | font:12px Arial, Helvetica, sans-serif; |
|---|
| 32 | background-color:#FFCC66; |
|---|
| 33 | color: #000000; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | h1 |
|---|
| 37 | { |
|---|
| 38 | font:14px Arial, Helvetica, sans-serif; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | h2 |
|---|
| 43 | { |
|---|
| 44 | font-style:oblique; |
|---|
| 45 | font-weight:bold; |
|---|
| 46 | font:13px Arial, Helvetica, sans-serif; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | tr |
|---|
| 51 | { |
|---|
| 52 | /* |
|---|
| 53 | border-style: hidden;*/ |
|---|
| 54 | font:11px Arial, Helvetica, sans-serif; |
|---|
| 55 | } |
|---|
| 56 | td |
|---|
| 57 | { |
|---|
| 58 | /* |
|---|
| 59 | border-color: black; |
|---|
| 60 | border-style: solid;*/ |
|---|
| 61 | font:11px Arial, Helvetica, sans-serif; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | pre |
|---|
| 66 | { |
|---|
| 67 | background-color: #FFFFCC; |
|---|
| 68 | margin-left: auto; |
|---|
| 69 | margin-right: auto; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | table |
|---|
| 73 | { |
|---|
| 74 | |
|---|
| 75 | font-family: sans; |
|---|
| 76 | font-size: 9pt; |
|---|
| 77 | |
|---|
| 78 | background-color: #FFFFCC; |
|---|
| 79 | border-style: hidden; |
|---|
| 80 | margin-left: auto; |
|---|
| 81 | margin-right: auto; |
|---|
| 82 | border-color: green; |
|---|
| 83 | border: 0.5px solid black; |
|---|
| 84 | border-collapse: collapse; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | """ |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | """ |
|---|
| 93 | Tree of HTML tags |
|---|
| 94 | <html> |
|---|
| 95 | childs |
|---|
| 96 | ... |
|---|
| 97 | ... |
|---|
| 98 | ... |
|---|
| 99 | ... |
|---|
| 100 | </html> |
|---|
| 101 | |
|---|
| 102 | """ |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | class Node(object): |
|---|
| 106 | def __init__(self, tag_name, attr=None, text = "" ): |
|---|
| 107 | """ |
|---|
| 108 | @param tag_name name of tag (could be None) |
|---|
| 109 | @param attr is a list that contains dicts [{name and value}, ...] |
|---|
| 110 | """ |
|---|
| 111 | |
|---|
| 112 | self.tag = tag_name |
|---|
| 113 | self.attr = attr |
|---|
| 114 | self.childs = [] |
|---|
| 115 | self.text = text |
|---|
| 116 | def add_child(self, node): |
|---|
| 117 | """ |
|---|
| 118 | Add Childs |
|---|
| 119 | """ |
|---|
| 120 | assert node != None |
|---|
| 121 | self.childs.append(node) |
|---|
| 122 | def get_childs(self): |
|---|
| 123 | return self.childs |
|---|
| 124 | |
|---|
| 125 | def get_html(self): |
|---|
| 126 | """ |
|---|
| 127 | -- recursive code |
|---|
| 128 | returns a html string |
|---|
| 129 | """ |
|---|
| 130 | if self.tag == None : |
|---|
| 131 | return self.text |
|---|
| 132 | |
|---|
| 133 | str = self.tag |
|---|
| 134 | |
|---|
| 135 | # Fill Attributes of tag |
|---|
| 136 | if self.attr!=None: |
|---|
| 137 | for attr in self.attr: |
|---|
| 138 | str = str + " " |
|---|
| 139 | str = str + attr['name'] + "=\"" + attr['value']+"\"" |
|---|
| 140 | |
|---|
| 141 | ch = "" |
|---|
| 142 | for child in self.childs: |
|---|
| 143 | s = child.get_html() |
|---|
| 144 | ch = ch + "\n" + s |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | open = "<%s>" % str |
|---|
| 148 | close = "</%s>" % self.tag |
|---|
| 149 | if self.text == "": |
|---|
| 150 | result = open + ch + "\n" + close |
|---|
| 151 | else: |
|---|
| 152 | result = open + ch + self.text + "\n" + close |
|---|
| 153 | return result |
|---|
| 154 | |
|---|
| 155 | # DELME? |
|---|
| 156 | class CodesHTML(object): |
|---|
| 157 | def get_title(title): |
|---|
| 158 | return TITLE+"%s"% title + TITLE_C |
|---|
| 159 | |
|---|
| 160 | title = staticmethod(get_title) |
|---|