Changeset dec793e in sasview


Ignore:
Timestamp:
Apr 5, 2011 7:32:45 PM (13 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:
4b470cf
Parents:
8da09f4
Message:

fixed the html report doc

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • invariantview/media/report_template.html

    rb281210 rdec793e  
    4343 <tr> 
    4444  <td width=170 valign=top > 
    45   <p class=MsoNormal > porod  constant</p> 
     45  <p class=MsoNormal > porod constant</p> 
    4646  </td> 
    4747  <td width=213 valign=top > 
  • invariantview/perspectives/invariant/report_dialog.py

    rcf9b6950 rdec793e  
    2424    PANEL_HEIGHT = 700 
    2525    FONT_VARIANT = 0 
     26    ISMAC = False 
    2627else: 
    2728    _STATICBOX_WIDTH = 480 
     
    2930    PANEL_HEIGHT = 700 
    3031    FONT_VARIANT = 1 
    31      
    32  
    33          
     32    ISMAC = True 
     33   
    3434class ReportDialog(wx.Dialog): 
    3535    """ 
     
    5353        # font size  
    5454        self.SetWindowVariant(variant=FONT_VARIANT) 
     55 
     56        # check if tit is MAC 
     57        self.is_mac = ISMAC 
     58         
    5559        # report string 
    5660        self.report_list = list 
     
    5963        # layout 
    6064        self._setup_layout() 
     65        # wild card 
     66        # pdf supporting only on MAC 
     67        if self.is_mac: 
     68                self.wild_card = ' PDF files (*.pdf)|*.pdf|' 
     69        else: 
     70                self.wild_card = '' 
     71        self.wild_card += 'HTML files (*.html)|*.html|' 
     72        self.wild_card += 'Text files (*.txt)|*.txt' 
     73   
     74         
    6175         
    6276    def _setup_layout(self): 
     
    109123        self.Centre() 
    110124        self.Show(True) 
    111  
     125                 
    112126 
    113127    def onSave(self, event=None): 
     
    117131        #todo: complete saving fig file and as a txt file 
    118132        dlg = wx.FileDialog(self, "Choose a file", 
    119                             wildcard='HTML files (*.html)|*.html|'+ 
    120                             'Text files (*.txt)|*.txt', 
     133                            wildcard=self.wild_card, 
    121134                            style=wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 
    122135        dlg.SetFilterIndex(0) #Set .html files to be default 
     
    125138            dlg.Destroy() 
    126139            return 
    127          
     140 
    128141        fName = dlg.GetPath() 
    129         ext_num = dlg.GetFilterIndex()      
    130  
     142        ext_num = dlg.GetFilterIndex()   
     143        # index correction  
     144        if not self.is_mac: 
     145                ind_cor = 1  
     146        else: 
     147                ind_cor = 0  
    131148        #set file extensions   
    132         if ext_num == 0: 
     149        if ext_num == (0 + 2 * ind_cor): 
     150                        # TODO: Sort this case out 
     151            ext = '.pdf' 
     152            img_ext = '_img.png' 
     153            fName = os.path.splitext(fName)[0] + ext 
     154            dlg.Destroy() 
     155 
     156            #pic (png) file path/name 
     157            pic_fname = os.path.splitext(fName)[0] + img_ext 
     158            # save the image for use with pdf writer 
     159            self.report_list[2].savefig(pic_fname) 
     160 
     161            # put the image file path in the html data 
     162            html = self.report_list[0] % str(pic_fname) 
     163             
     164            # make/open file in case of absence 
     165            f = open(fName, 'w') 
     166            f.close() 
     167            # write pdf as a pdf file 
     168            pdf = self.HTML2PDF(data=html, filename=fName) 
     169             
     170            #open pdf 
     171            if pdf: 
     172                os.startfile(str(fName)) 
     173            #delete image file 
     174            os.remove(pic_fname) 
     175            return 
     176        elif ext_num == (1 - ind_cor): 
    133177            ext = '.html' 
    134178            img_ext = '_img4html.png' 
    135179            report_frame = self.report_list[0] 
    136         elif ext_num == 1: 
     180        elif ext_num == (2 - ind_cor): 
    137181            ext = '.txt'    
    138182            # changing the image extension actually changes the image 
     
    142186        else: 
    143187            return 
    144          
     188 
    145189        #file name      
    146190        fName = os.path.splitext(fName)[0] + ext 
     
    149193        pic_fname = os.path.splitext(fName)[0] + img_ext 
    150194        #put the image path in html string 
    151         if ext_num == 0: 
     195        if ext_num == (1 - ind_cor): 
    152196            report = report_frame % pic_fname 
     197 
    153198        f = open(fName, 'w') 
    154199        f.write(report) 
  • sansview/perspectives/fitting/report_dialog.py

    r2296316 rdec793e  
    2424    PANEL_HEIGHT = 700 
    2525    FONT_VARIANT = 0 
     26    ISMAC = False 
    2627else: 
    2728    _STATICBOX_WIDTH = 480 
     
    2930    PANEL_HEIGHT = 700 
    3031    FONT_VARIANT = 1 
     32    ISMAC = True 
    3133     
    3234 
     
    5355        # font size  
    5456        self.SetWindowVariant(variant=FONT_VARIANT) 
     57        # check if tit is MAC 
     58        self.is_mac = ISMAC 
    5559        # report string 
    5660        self.report_list = list 
     
    6468                                    "memory:img_fit0.png" 
    6569            elif len(list[2]) == 2: 
    66                 #print "self.report_list[0]",self.report_list[0] 
    6770                self.report_html = self.report_list[0] % \ 
    6871                                    ("memory:img_fit0.png",  
     
    133136        Save 
    134137        """ 
     138        # pdf supporting only on MAC, not on exe 
     139        if self.is_mac: 
     140            wild_card = ' PDF files (*.pdf)|*.pdf|' 
     141            ind_cor = 0  
     142        else: 
     143            wild_card = '' 
     144            ind_cor = 1  
     145        wild_card += 'HTML files (*.html)|*.html|' 
     146        wild_card += 'Text files (*.txt)|*.txt' 
     147 
    135148        #todo: complete saving fig file and as a txt file 
    136149        dlg = wx.FileDialog(self, "Choose a file", 
    137                             wildcard='HTML files (*.html)|*.html|'+ 
    138                             'Text files (*.txt)|*.txt', 
     150                            wildcard=wild_card, 
    139151                            style=wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 
    140152        dlg.SetFilterIndex(0) #Set .html files to be default 
     
    149161        #set file extensions  
    150162        img_ext = [] 
    151         if ext_num == 0: 
     163        pic_fname = [] 
     164        #PDF  
     165        if ext_num == (0 + 2 * ind_cor): 
     166            # TODO: Sort this case out 
     167            ext = '.pdf' 
     168             
     169            fName = os.path.splitext(fName)[0] + ext 
     170            dlg.Destroy() 
     171            #pic (png) file path/name 
     172            for num in range(self.nimages): 
     173                im_ext = '_img%s.png' % num 
     174                #img_ext.append(im_ext) 
     175                pic_name = os.path.splitext(fName)[0] + im_ext 
     176                pic_fname.append(pic_name) 
     177                # save the image for use with pdf writer 
     178                self.report_list[2][num].savefig(pic_name) 
     179 
     180            #put the image path in html string 
     181            report_frame = self.report_list[0] 
     182            #put image name strings into the html file 
     183            #Note:The str for pic_fname shouldn't be removed. 
     184            if self.nimages == 1: 
     185                html = report_frame % str(pic_fname[0]) 
     186            elif self.nimages == 2: 
     187                html = report_frame % (str(pic_fname[0]), str(pic_fname[1])) 
     188            elif self.nimages == 3: 
     189                html = report_frame % (str(pic_fname[0]), str(pic_fname[1]), 
     190                                          str(pic_fname[2])) 
     191 
     192            # make/open file in case of absence 
     193            f = open(fName, 'w') 
     194            f.close() 
     195            # write pdf as a pdf file 
     196            pdf = self.HTML2PDF(data=html, filename=fName) 
     197             
     198            #open pdf 
     199            if pdf: 
     200                os.startfile(str(fName)) 
     201            #delete image file 
     202            for num in range(self.nimages): 
     203                os.remove(pic_fname[num]) 
     204            return 
     205        #HTML + png(graph) 
     206        elif ext_num == (1 - ind_cor): 
    152207            ext = '.html' 
    153208            for num in range(self.nimages): 
    154209                img_ext.append('_img4html%s.png' % num) 
    155210            report_frame = self.report_list[0] 
    156         elif ext_num == 1: 
     211        #TEXT + pdf(graph) 
     212        elif ext_num == (2 - ind_cor): 
    157213            ext = '.txt'    
    158214            # changing the image extension actually changes the image 
     
    167223        fName = os.path.splitext(fName)[0] + ext 
    168224        dlg.Destroy() 
    169         pic_fname = [] 
     225         
    170226        #pic (png) file path/name 
    171227        for num in range(self.nimages): 
     
    173229            pic_fname.append(pic_name) 
    174230        #put the image path in html string 
    175         if ext_num == 0: 
     231        if ext_num == (1 - ind_cor): 
    176232            if self.nimages == 1: 
    177233                report = report_frame % pic_fname[0] 
     
    234290        # pisa requires some extra packages, see their web-site 
    235291        pdf = pisa.CreatePDF(data, f) 
     292 
    236293        # close the file here otherwise it will be open until quitting 
    237294        #the application. 
Note: See TracChangeset for help on using the changeset viewer.