pypy / dotviewer / graphpage.py

class GraphPage(object):
    """Base class for the client-side content of one of the 'pages'
    (one graph) sent over to and displayed by the external process.
    """
    save_tmp_file = None

    def __init__(self, *args, **kwds):
        self.args = args
        self.kwds = kwds

    def content(self):
        """Compute the content of the page.
        This doesn't modify the page in place; it returns a new GraphPage.
        """
        if hasattr(self, 'source'):
            return self
        else:
            new = self.__class__()
            new.source = ''  # '''dot source'''
            new.links  = {}  # {'word': 'statusbar text'}
            new.compute(*self.args, **self.kwds)   # defined in subclasses
            return new

    def followlink(self, word):
        raise KeyError

    def display(self):
        "Display a graph page."
        import graphclient, msgstruct
        try:
            graphclient.display_page(self, save_tmp_file=self.save_tmp_file)
        except msgstruct.RemoteError, e:
            import sys
            print >> sys.stderr, "Exception in the graph viewer:", str(e)

    def display_background(self):
        "Display a graph page in a background thread."
        try:
            import thread
            thread.start_new_thread(self.display, ())
        except ImportError:
            self.display()

class DotFileGraphPage(GraphPage):
    def compute(self, dotfile):
        import codecs
        from strunicode import RAW_ENCODING
        f = codecs.open(dotfile, 'r', RAW_ENCODING)
        self.source = f.read()
        f.close()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.