My favorites | Sign in
Project Logo
                
Search
for
Updated May 24, 2009 by Jose.R.Fonseca
Labels: Script, Python, Featured
XDot  
Interactive viewer for Graphviz dot files

About

xdot.py is an interactive viewer for graphs written in Graphviz's dot language.

It uses internally the graphviz's xdot output format as an intermediate format, and PyGTK and Cairo for rendering.

xdot.py can be used either as a standalone application from command line, or as a library embedded in your python application.

Status

Features

Changelog

Known Issues

Screenshots

Requirements

Windows users

Debian/Ubuntu users

Usage

Command Line

Usage: 
	xdot.py [file]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -f FILTER, --filter=FILTER
                        graphviz filter: dot, neato, twopi, circo, or fdp
                        [default: dot]

If no input file is given then it will read the dot graph from the standard input.

Shortcuts

Embedding

Sample code

#!/usr/bin/env python

import gtk
import gtk.gdk

import xdot

class MyDotWindow(xdot.DotWindow):

    def __init__(self):
        xdot.DotWindow.__init__(self)
        self.widget.connect('clicked', self.on_url_clicked)

    def on_url_clicked(self, widget, url, event):
        dialog = gtk.MessageDialog(
                parent = self, 
                buttons = gtk.BUTTONS_OK,
                message_format="%s clicked" % url)
        dialog.connect('response', lambda dialog, response: dialog.destroy())
        dialog.run()
        return True

dotcode = """
digraph G {
  Hello [URL="http://en.wikipedia.org/wiki/Hello"]
  World [URL="http://en.wikipedia.org/wiki/World"]
    Hello -> World
}
"""

def main():
    window = MyDotWindow()
    window.set_dotcode(dotcode)
    window.connect('destroy', gtk.main_quit)
    gtk.main()

if __name__ == '__main__':
    main()

Result

Download

Links


Comment by mgedmin, Jul 10, 2008

Having spent today immersed in pypy's dotviewer's internals I can tell that it doesn't use 'xdot' as the intermediate format; it uses the simplest and most crippled 'plain' format, and that causes problems.

Comment by darethehair, Jan 05, 2009

This is so cool! I have experimentally compiled Graphviz for the Maemo operating system, put it on my Nokia N800, and then used 'xDot' to successfully navigate around some sample 'dot' files with it! To enable the use of the device's zoom buttons, I added some F7 and F8 'keysymbs'. Does xDot use the GPL license?

Comment by Jose.R.Fonseca, Jan 06, 2009

darethehair,

XDot uses the LGPL license, which means you can use it in closed source projects as long as the xdot module itself is kept open source. Of course, it is difficult to conceive closed source python software unless one goes out of its way and uses byte code, or code obfuscators, etc.

Comment by shamal.faily, Jan 09, 2009

I do like this tool. Well done! I'm actually using this inside a wxPython application of all places, as this seems to be a nice alternative to the wx floatcanvas package.

The only comment I have is that shapefile nodes aren't supported, as XDotAttrParser::parse writes "unknown xdot opcode 'I' " when it encounters the draw field . If I had the time to dig around the internals (alas there are only 24 in the day) I would have a shot at trying to implement this myself. In the meantime, if you are looking for more xdot features to implement, you could do a lot worse than add shapefile support :-)

Comment by Metal3d, Jan 12, 2009

Really good !!!

I now can see my UML that I create parsing PHP files easier than before. Now you only have to implement an editor on the left :)

Comment by arpad.zsuzsi, Mar 30, 2009

I downloaded version 0.4 from SVN. But the sample.py have not worked for me earlier. I changed two rows in 3 places (filled=True; handle_ellipse; EllipseShape?), and now it works well. (Upper rows are the good rows.)

$ diff xdot.py xdot2.py 
625c625
<     def handle_ellipse(self, x0, y0, w, h, filled=True):
---
>     def handle_ecllipse(self, x0, y0, w, h):
629c629
<         self.shapes.append(EllipseShape(self.pen, x0, y0, w, h))
---
>         self.shapes.append(EclipseShape(self.pen, x0, y0, w, h))

I like it.

Comment by Jose.R.Fonseca, Mar 30, 2009

Thanks arpad. I really need to make a testsuite to catch this kind of problems earlier on.

Comment by eldmannen, Apr 03, 2009

Please provide some more samples.

How do I add a node? Does it have to re-process all the code i want to add a node? Can I remove a node?

Comment by Jose.R.Fonseca, Apr 04, 2009

eldmannen,

Xdot.py is just a viewer for graphviz's dot language. It does not support editing. To change the graph you'll need to regenerate another dot file.

See http://www.graphviz.org/Documentation.php for the dot languange documentation and examples; and see http://code.google.com/p/yapgvb/ , http://software.inl.fr/trac/wiki/GvGen , and http://code.google.com/p/pydot/ for python libraries that can help generate those graphs in the dot language.

Comment by peterbjorgensen, Apr 24, 2009

Hey very cool and fairly lightweight (no JAVA yaaay \o/ :D) dot viewer. I've made a tiny patch that reloads the file on the 'r' key and I find it quite useful :) It would be even nicer if it was able to watch the file for changes automatically. Maybe I'll add that later.

1553a1554,1558
>         if event.keyval == gtk.keysyms.r:
>             win = self.get_toplevel()
>             if win.openfilename is not None:
>                 win.open_file(win.openfilename)
>             return True
1713a1719,1720
>         
>         self.openfilename = None
1731a1739
>             self.openfilename = filename
Comment by butterfoss, Apr 27, 2009

Great tool, very light weight. I hacked in a "Find" button to search through node text. I've never used gtk or python before so its probably a little rough, but it does work. Any where I can send code back to contribute?

Comment by Jose.R.Fonseca, Apr 27, 2009

butterfoss,

Please open an issue and attached a patch or the modified source code.

Comment by amascarell, Jun 30, 2009

Simplemente, es perfecto. Justo lo que andaba buscando.


Sign in to add a comment
Hosted by Google Code