File: graphpage.py

package info (click to toggle)
pypy 5.6.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 97,040 kB
  • ctags: 185,069
  • sloc: python: 1,147,862; ansic: 49,642; cpp: 5,245; asm: 5,169; makefile: 529; sh: 481; xml: 232; lisp: 45
file content (51 lines) | stat: -rw-r--r-- 1,604 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

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()