'''View graphs in dot-language.'''


import gtk
import gtk.gdk

import sys
import os


class DotView(gtk.Window):

	def __init__(self, parent = None):
		gtk.Window.__init__(self)

		self.set_title('Dot')
		self.set_default_size(500, 500)
		self.connect('delete-event', gtk.main_quit)

		scrolled_window = gtk.ScrolledWindow()
		scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		self.add(scrolled_window)

		self.image = gtk.Image()
		scrolled_window.add_with_viewport(self.image)

		#self.set_property('allow-grow', False)
		
		self.show_all()
	
	def set_dotcode(self, dotcode):
		
		dotin, dotout = os.popen2(['dot', '-Tsvg'], 'rw')

		dotin.write(dotcode)
		dotin.close()

		svgcode = dotout.read()
		dotout.close()

		# See images.py in pygtk demos
		self.pixbuf_loader = gtk.gdk.PixbufLoader('svg')
		self.pixbuf_loader.connect("area_prepared", self.on_pixbuf_loader_area_prepared, self.image)
		self.pixbuf_loader.connect("area_updated", self.on_pixbuf_loader_area_updated, self.image)
	
		self.pixbuf_loader.write(svgcode)
		self.pixbuf_loader.close()
	
	def on_pixbuf_loader_area_prepared(self, loader, image):
		print "area_prepared"
		pixbuf = loader.get_pixbuf()
		#pixbuf.fill(0)
		image.set_from_pixbuf(pixbuf)

	def on_pixbuf_loader_area_updated(self, loader, x, y, width, height, image):
		print "area_updated"
		#self.set_geometry_hints(max_width = width, max_height = height)
		image.queue_draw()


if __name__ == '__main__':
	win = DotView()
	win.set_dotcode(sys.stdin.read())
	gtk.main()

@@ -107,16 +107,75 @@
 indow):%0A
+%09%0A%09# TODO: add zoom/pan as in http://mirageiv.berlios.de/%0A%09
 %0A%09def __
@@ -235,67 +235,82 @@
 lf)%0A
-%0A
 %09%09
-self.set_title('Dot')%0A%09%09self.set_default_size(500, 500)%0A
+if parent is not None:%0A%09%09%09self.set_screen(parent.get_screen())%0A%09%09else:%0A%09
 %09%09se
@@ -327,18 +327,13 @@
 ('de
-lete-event
+stroy
 ', g
@@ -345,16 +345,74 @@
 in_quit)
+%0A%09%09self.set_title('Dot')%0A%09%09self.set_default_size(512, 512)
 %0A%0A%09%09scro
@@ -551,129 +551,232 @@
 ow)%0A
+%09%09
 %0A%09%09
-self.image = gtk.Image()%0A%09%09scrolled_window.add_with_viewport(self.image
+eventbox = gtk.EventBox()%0A%09%09bgcolor = gtk.gdk.color_parse(%22white%22)%0A%09%09eventbox.modify_bg(gtk.STATE_NORMAL, bgcolor)%0A%09%09scrolled_window.add_with_viewport(eventbox)%0A%09%09%09%0A%09%09self.image = gtk.Image(
 )%0A
-%0A
 %09%09
-#self.set_property('allow-grow', Fals
+eventbox.add(self.imag
 e)%0A
-%09%09
 %0A%09%09s
@@ -1000,21 +1000,16 @@
 demos%0A%09%09
-self.
 pixbuf_l
@@ -1042,29 +1042,24 @@
 er('svg')%0A%09%09
-self.
 pixbuf_loade
@@ -1124,29 +1124,12 @@
 ared
-, self.image)%0A%09%09self.
+)%0A%09%09
 pixb
@@ -1200,31 +1200,14 @@
 ated
-, self.image
 )%0A%09%0A%09%09
-self.
 pixb
@@ -1233,21 +1233,16 @@
 code)%0A%09%09
-self.
 pixbuf_l
@@ -1303,59 +1303,42 @@
 lf, 
-loader, image):%0A%09%09print %22area_prepared%22%0A%09%09
+pixbuf_loader):%0A%09%09pixbuf = 
 pixbuf
- = 
+_
 load
@@ -1359,26 +1359,13 @@
 )%0A%09%09
-#pixbuf.fill(0)%0A%09%09
+self.
 imag
@@ -1432,16 +1432,23 @@
 d(self, 
+pixbuf_
 loader, 
@@ -1470,110 +1470,18 @@
 ight
-, image):%0A%09%09print %22area_updated%22%0A%09%09#self.set_geometry_hints(max_width = width, max_height = height)%0A%09%09
+):%0A%09%09self.
 imag
@@ -1495,16 +1495,19 @@
 _draw()%0A
+%09%09%0A
 %0A%0Aif __n

Set white BG color. Cleanup.