Changeset a94c4e1 in sasview for invariantview


Ignore:
Timestamp:
Jul 25, 2010 12:20:47 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:
55f5a77
Parents:
cb463b4
Message:

added plot in html window

Location:
invariantview
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • invariantview/media/report_template.html

    rcb463b4 ra94c4e1  
    206206<p class=MsoNormal>&nbsp;</p> 
    207207 
     208<center> 
     209<br>Invariant Computation<br> 
     210<br>Data name: "%s"<br> 
     211<img src="%s" height=450 width=600> 
     212 
     213</center> 
     214 
    208215</div> 
    209216 
  • invariantview/perspectives/invariant/invariant_panel.py

    rcb463b4 ra94c4e1  
    77 
    88import sys,os 
     9 
    910from wx.lib.scrolledpanel import ScrolledPanel 
    1011from sans.invariant import invariant 
     
    8182        self.new_state = False 
    8283        self.is_power_out = False 
    83          
     84 
    8485        #container of invariant value 
    8586        self.inv_container = None 
     
    9596        ## Default file location for save 
    9697        self._default_save_location = os.getcwd() 
    97   
     98         
    9899    def err_check_on_data(self): 
    99100        """ 
     
    648649        from report_dialog import ReportDialog 
    649650 
    650         report_string = self.state.report_str 
     651        self.state.set_report_string() 
     652        report_string = self.state.report_str  
    651653        dialog = ReportDialog(report_string, None, -1, "") 
    652654        dialog.ShowModal() 
     
    11381140        else: 
    11391141            return False 
     1142 
    11401143         
    11411144    def _reset_output(self): 
     
    17011704        """  
    17021705        import sans.perspectives.invariant as invariant 
     1706        #from wx.lib.buttons import GenBitmapTextButton 
     1707 
    17031708        path = invariant.get_data_path(media='media') 
    17041709        self.undo_png = os.path.join(path,"undo.png") 
     
    17111716        self.button_undo = wx.BitmapButton(self, id,wx.Bitmap(self.undo_png))#wx.Button(self, id, "Undo",size=(50,20)) 
    17121717        self.button_undo.SetToolTipString("Undo") 
     1718        #self.button_undo.SetBackgroundColour('#c2e6f8') 
     1719 
    17131720        self.Bind(wx.EVT_BUTTON, self.undo, id=id) 
    17141721        self.button_undo.Disable() 
     
    17241731        self.button_bookmark.SetToolTipString("Bookmark: right-click on the panel to retrieve") 
    17251732        self.Bind(wx.EVT_BUTTON, self._on_bookmark, id=id) 
    1726         #self.button_bookmark.Disable() 
    17271733        #report button 
    17281734        id = wx.NewId() 
  • invariantview/perspectives/invariant/invariant_state.py

    rcb463b4 ra94c4e1  
    9393        self.timestamp = "('00:00:00', '00/00/0000')" 
    9494        self.container = None 
     95        #plot image 
     96        self.wximbmp = None 
    9597        # report_html strings 
    9698        import sans.perspectives.invariant as invariant 
     
    487489                    continue 
    488490 
    489         self.report_str = str(self.template_str)% (s_1,s_2,s_3,s_4,s_5,s_6,s_7,s_8,s_9,s_10,s_11,s_12,s_13,s_14,s_15,s_16,s_17,s_18) 
    490  
     491        # make plot image 
     492        self.set_plot_state(extra_high=bool_0[1],extra_low=bool_1[1]) 
     493         
     494        # get ready for report with setting all the html strings 
     495        self.report_str = str(self.template_str)% (s_1,s_2,s_3,s_4,s_5,s_6,s_7,s_8,s_9,s_10,s_11,s_12,s_13,s_14,s_15,s_16,s_17,s_18,self.file,self.wximbmp) 
     496     
     497     
    491498    def set_saved_state(self, name, value): 
    492499        """ 
     
    520527            pass 
    521528 
    522  
     529    def set_plot_state(self,extra_high=False,extra_low=False): 
     530        """ 
     531        Build image state that wx.html understand 
     532        by plotting, putting it into wx.FileSystem image object 
     533         
     534        : extrap_high,extra_low: low/high extrapolations are possible extra-plots 
     535        """ 
     536        # some imports 
     537        import cStringIO 
     538        import matplotlib,wx 
     539        matplotlib.use('Agg') 
     540        import matplotlib.pyplot as plt 
     541        import Image 
     542         
     543        #we use simple plot, not plotpanel 
     544        #make matlab figure 
     545        fig = plt.figure() 
     546        graph = fig.add_subplot(111) 
     547         
     548        #data plot 
     549        graph.errorbar(self.data.x, self.data.y, yerr=self.data.dy, fmt='o') 
     550        #low Q extrapolation fit plot 
     551        if not extra_low == 'False': 
     552            graph.plot(self.theory_lowQ.x,self.theory_lowQ.y) 
     553        #high Q extrapolation fit plot 
     554        if not extra_high == 'False': 
     555            graph.plot(self.theory_highQ.x,self.theory_highQ.y) 
     556        graph.set_xscale("log", nonposx='clip') 
     557        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)  
     566        #convert to wx.Image 
     567        wxim = wx.EmptyImage(img.size[0],img.size[1]) 
     568        wxim.SetData(img.convert("RGB").tostring())   
     569        #get the dynamic image for the htmlwindow 
     570        wximbmp = wx.BitmapFromImage(wxim) 
     571        #store the image in wx.FileSystem Object  
     572        wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 
     573        # use wx.MemoryFSHandler 
     574        self.imgRAM = wx.MemoryFSHandler() 
     575        #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             
    523580 
    524581class Reader(CansasReader): 
  • invariantview/perspectives/invariant/report_dialog.py

    rcb463b4 ra94c4e1  
    1818import sys,os 
    1919import wx.html as html 
    20  
     20import Image 
    2121if sys.platform.count("win32")>0: 
    2222    _STATICBOX_WIDTH = 450 
     
    4545        kwds["style"] = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE 
    4646        wx.Dialog.__init__(self, *args, **kwds) 
     47        kwds["image"] = 'Dynamic Image' 
    4748        # title 
    4849        self.SetTitle("Report: Invariant computaion") 
     
    5556        # layout 
    5657        self._setup_layout() 
    57  
     58         
    5859    def _setup_layout(self): 
    5960        """ 
     
    7576        button_preview.SetToolTipString("Print preview this report.") 
    7677        button_preview.Bind(wx.EVT_BUTTON, self.onPreview, id = button_preview.GetId())  
    77         #hbox.Add(button_preview) 
     78        hbox.Add(button_preview) 
    7879 
    7980        id = wx.NewId() 
     
    100101        self.Show(True) 
    101102 
    102     def onSave(self,event): 
     103    def onSave(self,event=None): 
    103104        """ 
     105        Save 
    104106        """ 
    105         pass 
     107        #todo: complete saving fig file and as a txt file 
     108        dlg = wx.FileDialog(self, "Choose a file",\ 
     109                            wildcard ='HTML files (*.html)|*.html|'+ 
     110                            'Text files (*.txt)|*.txt', 
     111                            style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 
     112        dlg.SetFilterIndex(0) #Set .html files to be default 
     113 
     114        if dlg.ShowModal() != wx.ID_OK: 
     115          dlg.Destroy() 
     116          return 
     117        fName = dlg.GetPath() 
     118        fName = os.path.splitext(fName)[0] + '.html' 
     119        dlg.Destroy() 
    106120     
    107     def onPreview(self,event): 
     121        html = self.report_string 
     122        f = open(fName, 'w') 
     123        f.write(html) 
     124        f.close() 
     125 
     126     
     127    def onPreview(self,event=None): 
    108128        """ 
     129        Preview 
     130         
     131        : event: Preview button event 
    109132        """ 
    110         pass 
     133        previewh=html.HtmlEasyPrinting(name="Printing", parentWindow=self) 
     134        previewh.PreviewText(self.report_string) 
    111135     
    112     def onPrint(self,event): 
     136    def onPrint(self,event=None): 
    113137        """ 
     138        Print 
     139         
     140        : event: Print button event 
    114141        """ 
    115         gg=html.HtmlEasyPrinting(name="Printing", parentWindow=self) 
    116          
    117         gg.PreviewText(self.report_string) 
     142        printh=html.HtmlEasyPrinting(name="Printing", parentWindow=self) 
     143        printh.PrintText(self.report_string) 
     144 
    118145         
    119146         
Note: See TracChangeset for help on using the changeset viewer.