root/branch/PreferencesWindow/umitExport/HTML/Codes.py @ 3650

Revision 3650, 3.1 kB (checked in by luis, 5 years ago)

Changed locate of style and fix table style

Line 
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
20HEADER = "<html>"
21HEADER_C = "<html>"
22TITLE = "<title>"
23TITLE_C = "</title>"
24BL = "<br />"
25
26STYLE = """
27
28body {
29margin-left:auto; margin-right:auto;
30text-align:center;
31font:12px Arial, Helvetica, sans-serif;
32background-color:#FFCC66;
33color: #000000;
34}
35
36h1
37{
38font:14px Arial, Helvetica, sans-serif;
39}
40
41
42h2
43{
44font-style:oblique;
45font-weight:bold;
46font:13px Arial, Helvetica, sans-serif;
47}
48
49
50tr
51{
52/*
53border-style: hidden;*/
54font:11px Arial, Helvetica, sans-serif;
55}
56td
57{
58/*
59border-color: black;
60border-style: solid;*/
61font:11px Arial, Helvetica, sans-serif;
62}
63
64
65pre
66{
67background-color: #FFFFCC;
68margin-left: auto;
69margin-right: auto;
70}
71
72table
73{
74
75font-family: sans;
76font-size: 9pt;
77
78background-color: #FFFFCC;
79border-style: hidden;
80margin-left: auto;
81margin-right: auto;
82border-color: green;
83border: 0.5px solid black;
84border-collapse: collapse;
85}
86
87
88"""
89
90
91
92"""
93Tree of HTML tags
94<html>
95  childs
96    ...
97       ...
98       ...
99       ...
100</html>
101
102"""
103
104
105class 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?
156class CodesHTML(object):
157    def get_title(title):
158        return TITLE+"%s"% title + TITLE_C
159   
160    title = staticmethod(get_title)
Note: See TracBrowser for help on using the browser.