Changeset 5330be2 in sasview for src/sas


Ignore:
Timestamp:
Jul 31, 2018 4:06:15 AM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
4453043
Parents:
933f9e9
git-author:
Piotr Rozyczko <rozyczko@…> (07/31/18 04:04:46)
git-committer:
Piotr Rozyczko <rozyczko@…> (07/31/18 04:06:15)
Message:

Fix 2D chart failures with reporting. SASVIEW-950

Location:
src/sas/qtgui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/ReportPageLogic.py

    r30bc96eb r5330be2  
    44import re 
    55import sys 
     6import tempfile 
     7 
    68import logging 
    79from io import BytesIO 
     
    911 
    1012from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas 
    11  
    12 from sas.qtgui.Plotting.Plotter import Plotter 
    13 from sas.qtgui.Plotting.Plotter2D import Plotter2D 
    14 from sas.qtgui.Plotting.PlotterData import Data1D 
    15 from sas.qtgui.Plotting.PlotterData import Data2D 
    1613 
    1714import sas.qtgui.Utilities.GuiUtils as GuiUtils 
     
    10299            canvas = FigureCanvas(fig) 
    103100            png_output = BytesIO() 
    104             canvas.print_png(png_output) 
    105             data = png_output.getvalue() 
    106             data64 = base64.b64encode(data) 
     101 
     102            # Create a "safe" location - system tmp 
     103            tmp_file = tempfile.TemporaryFile(suffix=".png") 
     104            try: 
     105                fig.savefig(tmp_file.name, dpi=75) 
     106                fig.savefig(png_output, dpi=75) 
     107            except PermissionError: 
     108                # sometimes one gets "permission denied" for temp files 
     109                # mainly on Windows 7 *gasp*. Let's try local directory 
     110                tmp_file = open("_tmp.png", "w+") 
     111                try: 
     112                    fig.savefig(tmp_file.name, dpi=75) 
     113                    fig.savefig(png_output, dpi=75) 
     114                except Exception as ex: 
     115                    logging.error("Creating of the report failed: %s"%str(ex)) 
     116                    return 
     117 
     118            data_to_print = png_output.getvalue() == open(tmp_file.name, 'rb').read() 
     119            tmp_file.close() 
     120            data64 = base64.b64encode(png_output.getvalue()) 
    107121            data_to_print = urllib.parse.quote(data64) 
    108             feet=FEET_2 
     122 
     123            feet = FEET_2 
    109124            if sys.platform == "darwin":  # Mac 
    110125                feet = FEET_3 
     
    153168        if not modelname or self._index is None: 
    154169            return None 
    155         plots = GuiUtils.plotsFromModel(modelname, self._index) 
    156         # Call show on requested plots 
    157         # All same-type charts in one plot 
    158         for plot_set in plots: 
    159             if isinstance(plot_set, Data1D): 
    160                 if 'residuals' in plot_set.title.lower(): 
    161                     res_plot = Plotter(self, quickplot=True) 
    162                     res_plot.plot(plot_set) 
    163                     graphs.append(res_plot.figure) 
    164                     continue 
    165                 if not 'new_plot' in locals(): 
    166                     new_plot = Plotter(self, quickplot=True) 
    167                 new_plot.plot(plot_set) 
    168             elif isinstance(plot_set, Data2D): 
    169                 plot2D = Plotter2D(self, quickplot=True) 
    170                 plot2D.item = self._index 
    171                 plot2D.plot(plot_set) 
    172                 graphs.append(plot2D.figure) 
    173  
    174             else: 
    175                 msg = "Incorrect data type passed to Plotting" 
    176                 raise AttributeError(msg) 
    177  
    178         if 'new_plot' in locals() and isinstance(new_plot.data, Data1D): 
    179             graphs.append(new_plot.figure) 
     170        plot_ids = [plot.id for plot in GuiUtils.plotsFromModel(modelname, self._index)] 
     171 
     172        # Active plots 
     173        import sas.qtgui.Plotting.PlotHelper as PlotHelper 
     174        shown_plot_names = PlotHelper.currentPlots() 
     175 
     176        # current_plots = list of graph names of currently shown plots 
     177        # which are related to this dataset 
     178        current_plots = [name for name in shown_plot_names if PlotHelper.plotById(name).data.id in plot_ids] 
     179 
     180        for name in current_plots: 
     181            # get the plotter object first 
     182            plotter = PlotHelper.plotById(name) 
     183            graphs.append(plotter.figure) 
    180184 
    181185        return graphs 
  • src/sas/qtgui/Utilities/ReportDialog.py

    r30bc96eb r5330be2  
    101101 
    102102        # translate png references into html from base64 string to on-disk name 
    103         cleanr = re.compile('<img src="data:image.*>') 
     103        cleanr = re.compile('<img src.*$') 
    104104        replacement_name = "" 
     105        html = self.data_html 
    105106        for picture in pictures: 
    106107            replacement_name += '<img src="'+ picture + '"><p></p>' 
    107  
    108108        # <img src="data:image/png;.*>  => <img src=filename> 
    109109        html = re.sub(cleanr, replacement_name, self.data_html) 
Note: See TracChangeset for help on using the changeset viewer.