def write(self, *ignored): self.init_document_data() if self.config.pdf_verbosity > 1: log.setLevel(logging.DEBUG) elif self.config.pdf_verbosity > 0: log.setLevel(logging.INFO) for entry in self.document_data: try: docname, targetname, title, author = entry[:4] # Custom options per document if len(entry)>4 and isinstance(entry[4],dict): opts=entry[4] else: opts={} self.spinx_logger.info("processing " + targetname + "... ") self.opts = opts class dummy: extensions=self.config.pdf_extensions createpdf.add_extensions(dummy()) self.page_template=opts.get('pdf_page_template',self.config.pdf_page_template) docwriter = PDFWriter(self, stylesheets=opts.get('pdf_stylesheets',self.config.pdf_stylesheets), language=opts.get('pdf_language',self.config.pdf_language), breaklevel=opts.get('pdf_break_level',self.config.pdf_break_level), breakside=opts.get('pdf_breakside',self.config.pdf_breakside), fontpath=opts.get('pdf_font_path',self.config.pdf_font_path), fitmode=opts.get('pdf_fit_mode',self.config.pdf_fit_mode), compressed=opts.get('pdf_compressed',self.config.pdf_compressed), inline_footnotes=opts.get('pdf_inline_footnotes',self.config.pdf_inline_footnotes), splittables=opts.get('pdf_splittables',self.config.pdf_splittables), repeat_table_rows=opts.get('pdf_repeat_table_rows',self.config.pdf_repeat_table_rows), default_dpi=opts.get('pdf_default_dpi',self.config.pdf_default_dpi), page_template=self.page_template, invariant=opts.get('pdf_invariant',self.config.pdf_invariant), real_footnotes=opts.get('pdf_real_footnotes',self.config.pdf_real_footnotes), use_toc=opts.get('pdf_use_toc',self.config.pdf_use_toc), toc_depth=opts.get('pdf_toc_depth',self.config.pdf_toc_depth), use_coverpage=opts.get('pdf_use_coverpage',self.config.pdf_use_coverpage), use_numbered_links=opts.get('pdf_use_numbered_links',self.config.pdf_use_numbered_links), fit_background_mode=opts.get('pdf_fit_background_mode',self.config.pdf_fit_background_mode), baseurl=opts.get('pdf_baseurl',self.config.pdf_baseurl), section_header_depth=opts.get('section_header_depth',self.config.section_header_depth), srcdir=self.srcdir, style_path=opts.get('pdf_style_path', self.config.pdf_style_path), config=self.config, ) tgt_file = path.join(self.outdir, targetname + self.out_suffix) destination = FileOutput(destination=open(tgt_file,'wb'), encoding='utf-8') doctree = self.assemble_doctree(docname,title,author, appendices=opts.get('pdf_appendices', self.config.pdf_appendices) or []) doctree.settings.author=author doctree.settings.title=title self.spinx_logger.info("done") self.spinx_logger.info("writing " + targetname + "... ") docwriter.write(doctree, destination) self.spinx_logger.info("done") except Exception as e: log.exception(e) self.spinx_logger.info(red("FAILED"))
def write(self, *ignored): self.init_document_data() if self.config.pdf_verbosity > 1: log.setLevel(logging.DEBUG) elif self.config.pdf_verbosity > 0: log.setLevel(logging.INFO) for entry in self.document_data: try: docname, targetname, title, author = entry[:4] # Custom options per document if len(entry)>4 and isinstance(entry[4],dict): opts=entry[4] else: opts={} self.info("processing " + targetname + "... ", nonl=1) self.opts = opts class dummy: extensions=self.config.pdf_extensions createpdf.add_extensions(dummy()) self.page_template=opts.get('pdf_page_template',self.config.pdf_page_template) docwriter = PDFWriter(self, stylesheets=opts.get('pdf_stylesheets',self.config.pdf_stylesheets), language=opts.get('pdf_language',self.config.pdf_language), breaklevel=opts.get('pdf_break_level',self.config.pdf_break_level), breakside=opts.get('pdf_breakside',self.config.pdf_breakside), fontpath=opts.get('pdf_font_path',self.config.pdf_font_path), fitmode=opts.get('pdf_fit_mode',self.config.pdf_fit_mode), compressed=opts.get('pdf_compressed',self.config.pdf_compressed), inline_footnotes=opts.get('pdf_inline_footnotes',self.config.pdf_inline_footnotes), splittables=opts.get('pdf_splittables',self.config.pdf_splittables), default_dpi=opts.get('pdf_default_dpi',self.config.pdf_default_dpi), page_template=self.page_template, invariant=opts.get('pdf_invariant',self.config.pdf_invariant), real_footnotes=opts.get('pdf_real_footnotes',self.config.pdf_real_footnotes), use_toc=opts.get('pdf_use_toc',self.config.pdf_use_toc), toc_depth=opts.get('pdf_toc_depth',self.config.pdf_toc_depth), use_coverpage=opts.get('pdf_use_coverpage',self.config.pdf_use_coverpage), use_numbered_links=opts.get('pdf_use_numbered_links',self.config.pdf_use_numbered_links), fit_background_mode=opts.get('pdf_fit_background_mode',self.config.pdf_fit_background_mode), baseurl=opts.get('pdf_baseurl',self.config.pdf_baseurl), section_header_depth=opts.get('section_header_depth',self.config.section_header_depth), srcdir=self.srcdir, style_path=opts.get('pdf_style_path', self.config.pdf_style_path), config=self.config, ) tgt_file = path.join(self.outdir, targetname + self.out_suffix) destination = FileOutput(destination=open(tgt_file,'wb'), encoding='utf-8') doctree = self.assemble_doctree(docname,title,author, appendices=opts.get('pdf_appendices', self.config.pdf_appendices) or []) doctree.settings.author=author doctree.settings.title=title self.info("done") self.info("writing " + targetname + "... ", nonl=1) docwriter.write(doctree, destination) self.info("done") except Exception, e: log.error(str(e)) print_exc() self.info(red("FAILED"))
Additional documentation available at: http://code.google.com/p/rson/ ''' from __future__ import unicode_literals from __future__ import print_function from __future__ import division from __future__ import absolute_import from future.utils import implements_iterator from builtins import str, bytes, next, object from past.builtins import basestring import logging from rst2pdf.log import log log.setLevel(logging.DEBUG) __version__ = '0.08' __author__ = 'Patrick Maupin <*****@*****.**>' __copyright__ = ''' Copyright (c) 2010, Patrick Maupin. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
def summary_cover(self, sub_id=None, out_file=None): """ Generates a cover page with subject information """ from mriqc import __version__ import datetime import numpy as np from logging import CRITICAL from rst2pdf.createpdf import RstToPdf from rst2pdf.log import log import pkg_resources as pkgr failed = self.failed if failed is None: failed = [] log.setLevel(CRITICAL) newdf = self.dataframe.copy() # Format the size #pylint: disable=E1101 newdf[['size_x', 'size_y', 'size_z']] = newdf[['size_x', 'size_y', 'size_z']].astype(np.uint16) formatter = lambda row: '%d \u00D7 %d \u00D7 %d' % ( row['size_x'], row['size_y'], row['size_z']) newdf['size'] = newdf[['size_x', 'size_y', 'size_z']].apply(formatter, axis=1) # Format spacing newdf[['spacing_x', 'spacing_y', 'spacing_z']] = newdf[[ 'spacing_x', 'spacing_y', 'spacing_z']].astype(np.float32) #pylint: disable=E1101 formatter = lambda row: '%.3f \u00D7 %.3f \u00D7 %.3f' % ( row['spacing_x'], row['spacing_y'], row['spacing_z']) newdf['spacing'] = newdf[['spacing_x', 'spacing_y', 'spacing_z']].apply(formatter, axis=1) # columns cols = ['session_id', 'run_id', 'size', 'spacing'] colnames = ['Session', 'Run', 'Size', 'Spacing'] if 'tr' in newdf.columns.ravel(): cols.append('tr') colnames.append('TR (sec)') if 'size_t' in newdf.columns.ravel(): cols.append('size_t') colnames.append('# Timepoints') # Format parameters table if sub_id is None: cols.insert(0, 'subject_id') colnames.insert(0, 'Subject') else: newdf = newdf[newdf.subject_id == sub_id] newdf = newdf[cols] colsizes = [] for col, colname in zip(cols, colnames): try: newdf[[col]] = newdf[[col]].astype(str) except NameError: newdf[[col]] = newdf[[col]].astype(str) colsize = np.max([len('{}'.format(val)) for val in newdf.loc[:, col]]) # colsize = newdf.loc[:, col].map(len).max() colsizes.append(colsize if colsize > len(colname) else len(colname)) colformat = ' '.join('{:<%d}' % c for c in colsizes) formatter = lambda row: colformat.format(*row) rowsformatted = newdf[cols].apply(formatter, axis=1).ravel().tolist() # rowsformatted = [formatter.format(*row) for row in newdf.iterrows()] header = colformat.format(*colnames) sep = colformat.format(*['=' * c for c in colsizes]) ptable = '\n'.join([sep, header, sep] + rowsformatted + [sep]) title = 'MRIQC: %s MRI %s report' % ( self.qctype, 'group' if sub_id is None else 'individual') # Substitution dictionary context = { 'title': title + '\n' + ''.join(['='] * len(title)), 'timestamp': datetime.datetime.now().strftime("%Y-%m-%d, %H:%M"), 'version': __version__, 'failed': failed, 'imparams': ptable } if sub_id is not None: context['sub_id'] = sub_id if sub_id is None: template = ConfigGen(pkgr.resource_filename( 'mriqc', op.join('data', 'reports', 'cover_group.rst'))) else: template = ConfigGen(pkgr.resource_filename( 'mriqc', op.join('data', 'reports', 'cover_individual.rst'))) RstToPdf().createPdf( text=template.compile(context), output=out_file)
"""The user interface for our app""" import os,sys,tempfile,re,functools,time,types,glob,codecs from pprint import pprint from copy import copy from multiprocessing import Process, Queue from queue import Empty from hashlib import md5 from io import StringIO from rst2pdf.createpdf import RstToPdf from rst2pdf.styles import StyleSheet from rst2pdf.log import log import logging import reportlab.lib.pagesizes as pagesizes log.setLevel(logging.INFO) import docutils # Import Qt modules from PyQt4 import QtCore,QtGui from pypoppler import QtPoppler # Syntax HL from highlighter import Highlighter # Import the compiled UI module from Ui_main import Ui_MainWindow from Ui_pdf import Ui_Form try:
def summary_cover(self, sub_id=None, out_file=None): """ Generates a cover page with subject information """ from mriqc import __version__ import datetime import numpy as np from rst2pdf.createpdf import RstToPdf from rst2pdf.log import log import pkg_resources as pkgr failed = self.failed if failed is None: failed = [] log.setLevel(logging.CRITICAL) newdf = self.dataframe.copy() # Format the size #pylint: disable=E1101 newdf[['size_x', 'size_y', 'size_z']] = newdf[['size_x', 'size_y', 'size_z']].astype(np.uint16) formatter = lambda row: '%d \u00D7 %d \u00D7 %d' % ( row['size_x'], row['size_y'], row['size_z']) newdf['size'] = newdf[['size_x', 'size_y', 'size_z']].apply(formatter, axis=1) # Format spacing newdf[['spacing_x', 'spacing_y', 'spacing_z']] = newdf[[ 'spacing_x', 'spacing_y', 'spacing_z']].astype(np.float32) #pylint: disable=E1101 formatter = lambda row: '%.3f \u00D7 %.3f \u00D7 %.3f' % ( row['spacing_x'], row['spacing_y'], row['spacing_z']) newdf['spacing'] = newdf[['spacing_x', 'spacing_y', 'spacing_z']].apply(formatter, axis=1) # columns cols = ['session_id', 'run_id', 'size', 'spacing'] colnames = ['Session', 'Run', 'Size', 'Spacing'] if 'tr' in newdf.columns.ravel(): cols.append('tr') colnames.append('TR (sec)') if 'size_t' in newdf.columns.ravel(): cols.append('size_t') colnames.append('# Timepoints') # Format parameters table if sub_id is None: cols.insert(0, 'subject_id') colnames.insert(0, 'Subject') else: newdf = newdf[newdf.subject_id == sub_id] newdf = newdf[cols] colsizes = [] for col, colname in zip(cols, colnames): try: newdf[[col]] = newdf[[col]].astype(str) except NameError: newdf[[col]] = newdf[[col]].astype(str) colsize = np.max([len('{}'.format(val)) for val in newdf.loc[:, col]]) # colsize = newdf.loc[:, col].map(len).max() colsizes.append(colsize if colsize > len(colname) else len(colname)) colformat = ' '.join('{:<%d}' % c for c in colsizes) formatter = lambda row: colformat.format(*row) rowsformatted = newdf[cols].apply(formatter, axis=1).ravel().tolist() # rowsformatted = [formatter.format(*row) for row in newdf.iterrows()] header = colformat.format(*colnames) sep = colformat.format(*['=' * c for c in colsizes]) ptable = '\n'.join([sep, header, sep] + rowsformatted + [sep]) title = 'MRIQC: %s MRI %s report' % ( self.qctype, 'group' if sub_id is None else 'individual') # Substitution dictionary context = { 'title': title + '\n' + ''.join(['='] * len(title)), 'timestamp': datetime.datetime.now().strftime("%Y-%m-%d, %H:%M"), 'version': __version__, 'failed': failed, 'imparams': ptable } if sub_id is not None: context['sub_id'] = sub_id if sub_id is None: template = ConfigGen(pkgr.resource_filename( 'mriqc', op.join('data', 'reports', 'cover_group.rst'))) else: template = ConfigGen(pkgr.resource_filename( 'mriqc', op.join('data', 'reports', 'cover_individual.rst'))) RstToPdf().createPdf( text=template.compile(context), output=out_file)