simplify

Changeset

119:b6bc953b39f9
2006-10-29 paulb raw files shortlog changelog graph Added Discard node support. Added raised exception information to functions/methods. Added invocation hyperlinking. Added if/elif invocation details.
viewer.py (file)
     1.1 --- a/viewer.py	Sun Oct 29 21:23:39 2006 +0100
     1.2 +++ b/viewer.py	Sun Oct 29 21:25:08 2006 +0100
     1.3 @@ -115,8 +115,7 @@
     1.4      .comment { color: blue; }
     1.5      .str { color: #FF00FF; }
     1.6      .doc { color: #FF00FF; margin-bottom: 1em; }
     1.7 -    .ref { color: cyan; }
     1.8 -    .ref a { color: cyan; text-decoration: none; }
     1.9 +    .invocation a { color: white; text-decoration: none; }
    1.10  
    1.11      .popup {
    1.12        display: none; z-index: 2;
    1.13 @@ -134,6 +133,11 @@
    1.14        float: right;
    1.15      }
    1.16  
    1.17 +    .raises {
    1.18 +      padding: 0.5em; background-color: #7700FF;
    1.19 +      float: right;
    1.20 +    }
    1.21 +
    1.22      .scopes {
    1.23        padding: 0.5em; background-color: #007700;
    1.24        float: left;
    1.25 @@ -141,14 +145,16 @@
    1.26  
    1.27      .op,
    1.28      .name,
    1.29 -    .attr
    1.30 +    .attr,
    1.31 +    .conditional
    1.32      {
    1.33        position: relative;
    1.34      }
    1.35  
    1.36      .op:hover > .popup,
    1.37      .name:hover > .popup,
    1.38 -    .attr:hover > .popup
    1.39 +    .attr:hover > .popup,
    1.40 +    .conditional:hover > .popup
    1.41      {
    1.42         display: block;
    1.43      }
    1.44 @@ -265,6 +271,11 @@
    1.45          self._keyword("continue")
    1.46          self.stream.write("</div>\n")
    1.47  
    1.48 +    def visitDiscard(self, node):
    1.49 +        self.stream.write("<div class='discard'>\n")
    1.50 +        self.default(node)
    1.51 +        self.stream.write("</div>\n")
    1.52 +
    1.53      def visitFor(self, node):
    1.54          self.stream.write("<div class='if'>\n")
    1.55          self.stream.write("<div>\n")
    1.56 @@ -296,6 +307,7 @@
    1.57          self._name_start(subprogram.name)
    1.58          self._popup_start()
    1.59          self._scopes(definition)
    1.60 +        self._raises(subprogram)
    1.61          self._popup_end()
    1.62          self._name_end()
    1.63          self.stream.write("(")
    1.64 @@ -314,18 +326,28 @@
    1.65      def visitIf(self, node):
    1.66          self.stream.write("<div class='if'>\n")
    1.67          first = 1
    1.68 +        conditional = node._node
    1.69          for compare, stmt in node.tests:
    1.70              self.stream.write("<div>\n")
    1.71 +            self.stream.write("<span class='conditional'>\n")
    1.72              if first:
    1.73                  self._keyword("if")
    1.74              else:
    1.75                  self._keyword("elif")
    1.76 +            self._popup_start()
    1.77 +            self._invocations(conditional.test)
    1.78 +            self._popup_end()
    1.79 +            self.stream.write("<span>\n")
    1.80              self.dispatch(compare)
    1.81              self.stream.write(":\n")
    1.82              self.stream.write("</div>\n")
    1.83              self.stream.write("<div class='body'>\n")
    1.84              self.dispatch(stmt)
    1.85              self.stream.write("</div>\n")
    1.86 +            if conditional.else_:
    1.87 +                conditional = conditional.else_[0]
    1.88 +            else:
    1.89 +                conditional = None
    1.90              first = 0
    1.91          if node.else_ is not None:
    1.92              self.stream.write("<div>\n")
    1.93 @@ -682,8 +704,12 @@
    1.94          self.stream.write("<div class='invocations'>\n")
    1.95          for invocation in invocations:
    1.96              fn = invocation.full_name()
    1.97 +            module = invocation.module.name
    1.98 +            name = invocation.name
    1.99              self.stream.write("<div class='invocation'>")
   1.100 -            self.stream.write(self._text(fn)) 
   1.101 +            self.stream.write("<a href='%s.html#%s'>" % (self._url(module), self._url(fn)))
   1.102 +            self.stream.write("%s.%s" % (self._text(module), self._text(name)))
   1.103 +            self.stream.write("</a>")
   1.104              self.stream.write("</div>\n")
   1.105          self.stream.write("</div>\n")
   1.106  
   1.107 @@ -699,8 +725,8 @@
   1.108              self.stream.write("unvisited\n")
   1.109              self.stream.write("</div>\n")
   1.110  
   1.111 -    def _types_list(self, types):
   1.112 -        self.stream.write("<div class='types'>\n")
   1.113 +    def _types_list(self, types, style_class="types"):
   1.114 +        self.stream.write("<div class='%s'>\n" % style_class)
   1.115          for type in types:
   1.116              fn = type.type.full_name()
   1.117              self.stream.write("<div class='type'>")
   1.118 @@ -708,6 +734,10 @@
   1.119              self.stream.write("</div>\n")
   1.120          self.stream.write("</div>\n")
   1.121  
   1.122 +    def _raises(self, node):
   1.123 +        if hasattr(node, "namespace") and hasattr(node.namespace, "raises") and node.namespace.raises:
   1.124 +            self._types_list(node.namespace.raises, style_class="raises")
   1.125 +
   1.126      def _scopes(self, node):
   1.127          if not isinstance(node, LoadName):
   1.128              if hasattr(node, "writes") or hasattr(node, "accesses"):