Changeset f310316 in sasview for invariantview


Ignore:
Timestamp:
Jul 29, 2010 6:54:04 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:
178bfea
Parents:
0881f51
Message:

conficts between PIL and py2exe found, fixed report display, and removed the saving as pdf file

Location:
invariantview/perspectives/invariant
Files:
2 edited

Legend:

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

    r51fb7ab rf310316  
    55from xml.dom.minidom import parse 
    66from lxml import etree 
     7""" 
     8try: 
     9    import PIL.Image as Image 
     10    import PIL.PngImagePlugin as PngImagePlugin 
     11    Image._initialized = 2 
     12except: 
     13    try: 
     14        import Image  
     15        import PngImagePlugin 
     16        Image._initialized = 2 
     17    except: 
     18        Image = None     
     19""" 
     20 
    721 
    822from DataLoader.readers.cansas_reader import Reader as CansasReader 
     
    537551        import cStringIO 
    538552        import matplotlib,wx 
    539         matplotlib.use('Agg') 
    540553        import matplotlib.pyplot as plt 
    541         import Image 
    542          
     554        from matplotlib.backends.backend_agg import FigureCanvasAgg 
     555 
    543556        #we use simple plot, not plotpanel 
    544557        #make matlab figure 
    545558        fig = plt.figure() 
     559        fig.set_facecolor('w') 
    546560        graph = fig.add_subplot(111) 
    547          
     561 
    548562        #data plot 
    549563        graph.errorbar(self.data.x, self.data.y, yerr=self.data.dy, fmt='o') 
     
    556570        graph.set_xscale("log", nonposx='clip') 
    557571        graph.set_yscale("log", nonposy='clip') 
    558         plt.xlabel('$\\rm{Q}(\\AA^{-1})$', fontsize = 12) 
    559         plt.ylabel('$\\rm{Intensity}(cm^{-1})$', fontsize = 12) 
    560  
    561         #make python.Image object 
    562         imagedata = cStringIO.StringIO() 
    563         fig.savefig(imagedata,format='png') 
    564         imagedata.seek(0) 
    565         img = Image.open(imagedata)  
     572        graph.set_xlabel('$\\rm{Q}(\\AA^{-1})$', fontsize = 12) 
     573        graph.set_ylabel('$\\rm{Intensity}(cm^{-1})$', fontsize = 12) 
     574        canvas = FigureCanvasAgg(fig) 
     575        #actually make image 
     576        canvas.draw() 
     577         
     578        #make python.Image object  
     579        #size 
     580        w,h =canvas.get_width_height() 
    566581        #convert to wx.Image 
    567         wxim = wx.EmptyImage(img.size[0],img.size[1]) 
    568         wxim.SetData(img.convert("RGB").tostring())   
     582        wximg = wx.EmptyImage(w,h) 
     583        #wxim.SetData(img.convert('RGB').tostring() )  
     584        wximg.SetData(canvas.tostring_rgb())  
    569585        #get the dynamic image for the htmlwindow 
    570         wximbmp = wx.BitmapFromImage(wxim) 
     586        wximgbmp = wx.BitmapFromImage(wximg) 
    571587        #store the image in wx.FileSystem Object  
    572588        wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 
     
    574590        self.imgRAM = wx.MemoryFSHandler() 
    575591        #AddFile, image can be retrieved with 'memory:filename' 
    576         self.imgRAM.AddFile('img_inv.png',wximbmp, wx.BITMAP_TYPE_PNG) 
    577          
    578         self.wximbmp = 'memory:img_inv.png' 
    579         self.image = img 
     592        self.imgRAM.AddFile('img_inv.png',wximgbmp, wx.BITMAP_TYPE_PNG) 
     593         
     594        self.wximgbmp = 'memory:img_inv.png' 
     595        self.image = fig 
    580596 
    581597class Reader(CansasReader): 
  • invariantview/perspectives/invariant/report_dialog.py

    r9fb814a rf310316  
    113113        dlg = wx.FileDialog(self, "Choose a file",\ 
    114114                            wildcard ='HTML files (*.html)|*.html|'+ 
    115                             'Text files (*.txt)|*.txt|'+ 
    116                             'PDF files (*.pdf)|*.pdf', 
     115                            'Text files (*.txt)|*.txt', 
    117116                            style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 
    118117        dlg.SetFilterIndex(0) #Set .html files to be default 
     
    136135            f.close() 
    137136            #save png file using pic_fname 
    138             self.report_list[2].save(pic_fname) 
     137            self.report_list[2].savefig(pic_fname) 
    139138             
    140139        elif dlg.GetFilterIndex()== 1: 
     
    146145            f.write(text) 
    147146            f.close() 
    148              
    149         elif dlg.GetFilterIndex()== 2: 
    150             fName = os.path.splitext(fName)[0] + '.pdf' 
    151             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) 
    174              
     147  
    175148    def onPreview(self,event=None): 
    176149        """ 
Note: See TracChangeset for help on using the changeset viewer.