Changeset 116

Show
Ignore:
Timestamp:
06/29/07 14:14:10 (1 year ago)
Author:
apdavison
Message:

Added API doc section to poster

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • doc/CNS2007/poster_cns2007.py

    r112 r116  
    77from reportlab.lib.pagesizes import A0, landscape 
    88from reportlab.lib.units import cm 
    9 from reportlab.lib.colors import grey, black 
     9from reportlab.lib import colors 
    1010from reportlab.platypus import * 
    1111from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle 
     
    1313import PIL 
    1414import pysvn 
     15import imp, os 
    1516 
    1617class Author(object): 
     
    133134 
    134135def make_users_guide(x,y,width,height,_debug=False): 
    135     global poster 
     136    global poster, styles 
    136137    svn_client = pysvn.Client() 
    137138    svn_client.checkout(svnpath, "pyNN") 
     
    167168        user_guide_frame.addFromList(paragraph_list, poster) 
    168169 
     170def make_apidocs(x,y,width,height,scale_factor=0.5,_debug=False): 
     171    global poster, styles 
     172    svn_client = pysvn.Client() 
     173    svn_client.checkout(svnpath, "pyNN") 
     174    wikidoc = imp.load_source('wikidoc', os.path.join('pyNN','doc','wikidoc.py')) 
     175    import re 
     176    from pyNN import __version__ 
     177    __version__ = ".".join(__version__.split('.')[0:2]) # x.y.z --> x.y 
     178    paragraph_template = re.compile(r'<para( style="(?P<style>\S*)")?>(?P<content>.*?)</para>',re.DOTALL) 
     179     
     180    for style_name,parent in [('APIBody', 'BodyText'), ('FunctionDef','Heading3'), 
     181                              ('Category','Heading1'),('Class','Heading2')]: 
     182        newstyle = ParagraphStyle(style_name, parent=styles[parent]) 
     183        scale_style(newstyle, scale_factor) 
     184        styles.add(newstyle) 
     185        styles[style_name].alignment = TA_LEFT 
     186    styles['FunctionDef'].textColor = colors.blue 
     187    styles['FunctionDef'].fontName = styles['APIBody'].fontName 
     188    styles['FunctionDef'].spaceBefore *= 0.3 
     189    styles['FunctionDef'].spaceAfter *= 0.3 
     190    styles['Category'].spaceBefore = styles['FunctionDef'].spaceBefore*2 
     191    styles['Class'].textColor = colors.darkgreen 
     192    styles['Class'].spaceBefore *= 0.3 
     193    styles['Class'].spaceAfter *= 0.3 
     194    styles['APIBody'].spaceBefore = 0 
     195    styles['APIBody'].fontSize += 1 
     196    styles['APIBody'].leading += 1 
     197    print "APIBody ", styles['APIBody'].fontSize 
     198    ##print styles['FunctionDef'].listAttrs() 
     199     
     200    apidoc = wikidoc.apidoc('reportlab_xml') 
     201    #print apidoc 
     202    margin = 0.03 
     203    subcol_width = width*(1-margin)/2.0 
     204     
     205     
     206    paragraph_list = [Paragraph("API reference <font size=14>(version %s)</font>" % __version__, styles['UsersGuideHeading1'])] 
     207    for match in paragraph_template.finditer(apidoc): 
     208        groups = match.groupdict() 
     209        content = groups['content'] 
     210        if groups['style'] is None: 
     211            style = "APIBody" 
     212        else: 
     213            style = groups['style'] 
     214        paragraph_list += [Paragraph(content, styles[style])] 
     215        #apidoc_frame.add(Paragraph(content, styles[style]), poster) 
     216    pad = 0.5*cm 
     217    f_height = 0 
     218    for p in paragraph_list: 
     219        f_height += p.wrap(subcol_width-pad, pageheight)[1] + p.getSpaceAfter() + p.getSpaceBefore() 
     220    f_height = f_height/2.0 + 2*pad 
     221    apidoc_frame1 = Frame(x, y - height, subcol_width, f_height, showBoundary=_debug, 
     222                          leftPadding=pad, rightPadding=0, bottomPadding=pad, 
     223                          topPadding=pad) 
     224    apidoc_frame2 = Frame(x+width-subcol_width, y - height, subcol_width, f_height, showBoundary=_debug, 
     225                          leftPadding=0, rightPadding=pad, bottomPadding=pad, 
     226                          topPadding=pad) 
     227    apidoc_frame1.addFromList(paragraph_list, poster) 
     228    apidoc_frame2.addFromList(paragraph_list, poster) 
     229    assert len(paragraph_list) == 0 
     230    poster.roundRect(x,y-height,width,f_height,1*cm) 
     231 
    169232# ============================================================================== 
    170233 
    171234if __name__ == "__main__": 
    172235    svnpath = "https://neuralensemble.kip.uni-heidelberg.de/svn/PyNN/branches/0.3" 
    173     DEBUG = Tru
     236    DEBUG = Fals
    174237     
    175238    TITLE = "PyNN: Towards a universal neural simulator API in Python" 
     
    217280    colsep = 2*cm 
    218281    titlesep = 2*cm 
    219     styles = getStyleSheet(3.6) 
     282    scale_factor = 3.6 
     283    styles = getStyleSheet(scale_factor) 
    220284 
    221285    poster = Canvas("poster_cns2007.pdf", 
     
    238302    make_abstract(ABSTRACT, margins['left'], title_bottom, colwidth, pageheight, DEBUG) 
    239303    make_users_guide(margins['left']+colwidth+colsep, title_bottom, colwidth, pageheight, DEBUG) 
     304    apiwidth = 0.25*pagewidth 
     305    make_apidocs(margins['left']+pagewidth-apiwidth, title_bottom, apiwidth, 
     306                 title_bottom-margins['bottom'], 0.8/scale_factor, DEBUG) 
    240307 
    241308    poster.save()