Changeset 9fb814a in sasview for invariantview


Ignore:
Timestamp:
Jul 27, 2010 12:40:18 PM (14 years ago)
Author:
Jae Cho <jhjcho@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
83ee3851
Parents:
aa5617d
Message:

added save report as pdf: pisa-3.0.33, html5lib-0.9.0, and reportlab-2.4 require

Location:
invariantview
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • invariantview/perspectives/invariant/report_dialog.py

    rb281210 r9fb814a  
    1313Dialog report panel to show and summarize the results of the invariant calculation. 
    1414""" 
    15      
    16  
    1715import wx 
    1816import sys,os 
    1917import wx.html as html 
    20 import Image 
    2118 
    2219if sys.platform.count("win32")>0: 
     
    116113        dlg = wx.FileDialog(self, "Choose a file",\ 
    117114                            wildcard ='HTML files (*.html)|*.html|'+ 
    118                             'Text files (*.txt)|*.txt', 
    119                             #'PDF files (*.pdf)|*.pdf', 
     115                            'Text files (*.txt)|*.txt|'+ 
     116                            'PDF files (*.pdf)|*.pdf', 
    120117                            style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 
    121118        dlg.SetFilterIndex(0) #Set .html files to be default 
     
    140137            #save png file using pic_fname 
    141138            self.report_list[2].save(pic_fname) 
     139             
    142140        elif dlg.GetFilterIndex()== 1: 
    143141            fName = os.path.splitext(fName)[0] + '.txt' 
     
    149147            f.close() 
    150148             
    151         else: 
     149        elif dlg.GetFilterIndex()== 2: 
     150            fName = os.path.splitext(fName)[0] + '.pdf' 
    152151            dlg.Destroy() 
     152 
     153            #pic (png) file path/name 
     154            pic_fname = os.path.splitext(fName)[0] + '_img.png' 
     155            # save the image for use with pdf writer 
     156            self.report_list[2].save(pic_fname) 
     157             
     158            # put the image file path in the html data 
     159            html = self.report_list[0] % str(pic_fname) 
     160             
     161            open_pdf = True 
     162            # make/open file in case of absence 
     163            f = open(fName, 'w') 
     164            f.close() 
     165            # write pdf as a pdf file 
     166            pdf = self.HTML2PDF(data=html, filename=fName) 
     167             
     168            #open pdf 
     169            if open_pdf and pdf: 
     170                os.startfile(str(fName)) 
     171 
     172            #delete image file 
     173            os.remove(pic_fname) 
    153174             
    154175    def onPreview(self,event=None): 
     
    179200         
    180201        self.Close() 
    181            
    182          
     202     
     203    def HTML2PDF(self, data, filename): 
     204        """ 
     205        Create a PDF file from html source string.  
     206         
     207        : data: html string 
     208        : filename: name of file to be saved 
     209        """ 
     210        import ho.pisa as pisa 
     211        f = file(filename, "wb") 
     212        # pisa requires some extra packages, see their web-site 
     213        pdf = pisa.CreatePDF(data,f) 
     214        # close the file here otherwise it will be open until quitting the application. 
     215        f.close() 
     216 
     217        return not pdf.err 
     218 
     219         
     220         
Note: See TracChangeset for help on using the changeset viewer.