tools/docco/graphdocpy.py
branchpy33
changeset 3794 398ea04239b5
parent 3723 99aa837b6703
child 3848 86095f63b397
equal deleted inserted replaced
3793:cc3f9cc828f7 3794:398ea04239b5
     8 """
     8 """
     9 __version__ = '0.8'
     9 __version__ = '0.8'
    10 
    10 
    11 import sys
    11 import sys
    12 sys.path.insert(0, '.')
    12 sys.path.insert(0, '.')
    13 import os, re, types, string, getopt, pickle, copy, time, pprint, traceback
    13 import os, re, types, getopt, pickle, copy, time, pprint, traceback
    14 from string import find, join, split, replace, expandtabs, rstrip
       
    15 import reportlab
    14 import reportlab
    16 from reportlab import rl_config
    15 from reportlab import rl_config
    17 
    16 
    18 from .docpy import PackageSkeleton0, ModuleSkeleton0
    17 from .docpy import PackageSkeleton0, ModuleSkeleton0
    19 from .docpy import DocBuilder0, PdfDocBuilder0, HtmlDocBuilder0
    18 from .docpy import DocBuilder0, PdfDocBuilder0, HtmlDocBuilder0
    72     canvas.line(2*cm, 2*cm, A4[0]-2*cm, 2*cm)
    71     canvas.line(2*cm, 2*cm, A4[0]-2*cm, 2*cm)
    73     if pageNumber > 1:
    72     if pageNumber > 1:
    74         canvas.setFont('Times-Roman', 12)
    73         canvas.setFont('Times-Roman', 12)
    75         canvas.drawString(4 * inch, cm, "%d" % pageNumber)
    74         canvas.drawString(4 * inch, cm, "%d" % pageNumber)
    76         if hasattr(canvas, 'headerLine'): # hackish
    75         if hasattr(canvas, 'headerLine'): # hackish
    77             headerline = string.join(canvas.headerLine, ' \xc2\x8d ')
    76             headerline = ' \xc2\x8d '.join(canvas.headerLine)
    78             canvas.drawString(2*cm, A4[1]-1.75*cm, headerline)
    77             canvas.drawString(2*cm, A4[1]-1.75*cm, headerline)
    79 
    78 
    80     canvas.setFont('Times-Roman', 8)
    79     canvas.setFont('Times-Roman', 8)
    81     msg = "Generated with docpy. See http://www.reportlab.com!"
    80     msg = "Generated with docpy. See http://www.reportlab.com!"
    82     canvas.drawString(2*cm, 1.65*cm, msg)
    81     canvas.drawString(2*cm, 1.65*cm, msg)
   351             self._showDrawingDemo(drawing)
   350             self._showDrawingDemo(drawing)
   352             self.story.append(Spacer(0*cm, 0.5*cm))
   351             self.story.append(Spacer(0*cm, 0.5*cm))
   353 
   352 
   354 
   353 
   355     def beginFunctions(self, names):
   354     def beginFunctions(self, names):
   356         srch = string.join(names, ' ')
   355         srch = ' '.join(names)
   357         if string.find(string.join(names, ' '), ' sample') > -1:
   356         if ' '.join(names).find(' sample') > -1:
   358             PdfDocBuilder0.beginFunctions(self, names)
   357             PdfDocBuilder0.beginFunctions(self, names)
   359 
       
   360 
   358 
   361     # Skip non-sample functions.
   359     # Skip non-sample functions.
   362     def beginFunction(self, name, doc, sig):
   360     def beginFunction(self, name, doc, sig):
   363         "Skip function for 'uninteresting' names."
   361         "Skip function for 'uninteresting' names."
   364 
   362 
   471             value = props[key]
   469             value = props[key]
   472 
   470 
   473             f = getBytesIO()
   471             f = getBytesIO()
   474             pprint.pprint(value, f)
   472             pprint.pprint(value, f)
   475             value = f.getvalue()[:-1]
   473             value = f.getvalue()[:-1]
   476             valueLines = string.split(value, '\n')
   474             valueLines = value.split('\n')
   477             for i in range(1, len(valueLines)):
   475             for i in range(1, len(valueLines)):
   478                 valueLines[i] = ' '*(len(key)+3) + valueLines[i]
   476                 valueLines[i] = ' '*(len(key)+3) + valueLines[i]
   479             value = string.join(valueLines, '\n')
   477             value = '\n'.join(valueLines)
   480 
   478 
   481             lines.append('%s = %s' % (key, value))
   479             lines.append('%s = %s' % (key, value))
   482 
   480 
   483         text = join(lines, '\n')
   481         text = '\n'.join(lines)
   484         self.story.append(Paragraph("<i>Properties of Example Widget</i>", self.bt))
   482         self.story.append(Paragraph("<i>Properties of Example Widget</i>", self.bt))
   485         self.story.append(Paragraph("", self.bt))
   483         self.story.append(Paragraph("", self.bt))
   486         self.story.append(Preformatted(text, self.code))
   484         self.story.append(Preformatted(text, self.code))
   487 
   485 
   488 
   486 
   547             self._showWidgetDemo(widget)
   545             self._showWidgetDemo(widget)
   548             self._showWidgetProperties(widget)
   546             self._showWidgetProperties(widget)
   549 
   547 
   550 
   548 
   551     def beginFunctions(self, names):
   549     def beginFunctions(self, names):
   552         if string.find(string.join(names, ' '), ' sample') > -1:
   550         if ' '.join(names).find(' sample') > -1:
   553             HtmlDocBuilder0.beginFunctions(self, names)
   551             HtmlDocBuilder0.beginFunctions(self, names)
   554 
   552 
   555 
   553 
   556     # Skip non-sample functions.
   554     # Skip non-sample functions.
   557     def beginFunction(self, name, doc, sig):
   555     def beginFunction(self, name, doc, sig):
   655 
   653 
   656             # Method 3
   654             # Method 3
   657             f = getBytesIO()
   655             f = getBytesIO()
   658             pprint.pprint(value, f)
   656             pprint.pprint(value, f)
   659             value = f.getvalue()[:-1]
   657             value = f.getvalue()[:-1]
   660             valueLines = string.split(value, '\n')
   658             valueLines = value.split('\n')
   661             for i in range(1, len(valueLines)):
   659             for i in range(1, len(valueLines)):
   662                 valueLines[i] = ' '*(len(key)+3) + valueLines[i]
   660                 valueLines[i] = ' '*(len(key)+3) + valueLines[i]
   663             value = string.join(valueLines, '\n')
   661             value = '\n'.join(valueLines)
   664 
   662 
   665             lines.append('%s = %s' % (key, value))
   663             lines.append('%s = %s' % (key, value))
   666         text = join(lines, '\n')
   664         text = '\n'.join(lines)
   667         self.outLines.append('<H3>Properties of Example Widget</H3>')
   665         self.outLines.append('<H3>Properties of Example Widget</H3>')
   668         self.outLines.append('<PRE>%s</PRE>' % text)
   666         self.outLines.append('<PRE>%s</PRE>' % text)
   669         self.outLines.append('')
   667         self.outLines.append('')
   670 
   668 
   671 
   669 
   715     def beginClass(self, name, doc, bases):
   713     def beginClass(self, name, doc, bases):
   716         bt = self.bt
   714         bt = self.bt
   717         story = self.story
   715         story = self.story
   718         if bases:
   716         if bases:
   719             bases = [b.__name__ for b in bases] # hack
   717             bases = [b.__name__ for b in bases] # hack
   720             story.append(Paragraph('%s(%s)' % (name, join(bases, ', ')), bt))
   718             story.append(Paragraph('%s(%s)' % (name, ', '.join(bases)), bt))
   721         else:
   719         else:
   722             story.append(Paragraph(name, bt))
   720             story.append(Paragraph(name, bt))
   723 
   721 
   724         story.append(XPreformatted(doc, bt))
   722         story.append(XPreformatted(doc, bt))
   725 
   723 
   883     else:
   881     else:
   884         name = pathOrName
   882         name = pathOrName
   885         package = __import__(name)
   883         package = __import__(name)
   886         # Some special care needed for dotted names.
   884         # Some special care needed for dotted names.
   887         if '.' in name:
   885         if '.' in name:
   888             subname = 'package' + name[find(name, '.'):]
   886             subname = 'package' + name[namefind('.'):]
   889             package = eval(subname)
   887             package = eval(subname)
   890         path = os.path.dirname(package.__file__)
   888         path = os.path.dirname(package.__file__)
   891 
   889 
   892     cwd = os.getcwd()
   890     cwd = os.getcwd()
   893     os.chdir(path)
   891     os.chdir(path)