Fixed version number (for 0release)
[dom-editor.git] / Dome / HTML.py
blobce9ecd287b638c862da7a3609875dede10ee656b
1 #from gtk import *
2 #from GDK import *
3 from gtkmozembed import GtkMozEmbed
5 import sys
6 import traceback
8 import os
9 from support import *
11 os.environ['MOZILLA_FIVE_HOME'] = '/usr/lib/mozilla/'
13 # Starting Moz twice is slow and makes us crash.
14 # Therefore, create a dummy widget when we're first
15 # loaded and never let go...
16 dummy_html = GtkMozEmbed()
18 class HTML(GtkWindow):
19 def __init__(self, model, node):
20 GtkWindow.__init__(self)
21 self.model = model
22 self.display_root = node
24 self.html = GtkMozEmbed()
26 self.set_title(self.display_root.nodeName)
27 self.model.add_view(self)
28 self.connect('destroy', self.destroyed)
30 self.show()
31 idle_add(self.put_in)
32 self.set_default_size(600, 400)
34 def put_in(self):
35 print "Add"
36 self.add(self.html)
37 self.html.show()
38 self.update_all()
40 def update_replace(self, old, new):
41 if old == self.display_root:
42 self.display_root = new
43 self.update_all()
45 def update_all(self, node = None):
46 print "Update HTML"
47 doc = node_to_html(self.display_root)
48 self.output_data = ''
49 ext.PrettyPrint(doc, stream = self)
50 data = self.output_data
51 self.output_data = ''
52 uri = self.model.get_base_uri(self.display_root)
53 if not uri:
54 uri = 'http://localhost/'
55 if uri[:7] != 'http://':
56 uri = 'file://' + uri
57 print "Base URI:", uri
58 print "Data:", data
59 self.html.render_data(data, uri, 'text/html')
61 return 0
63 def destroyed(self, widget):
64 print "Gone!"
65 self.model.remove_view(self)
67 def write(self, text):
68 self.output_data = self.output_data + text