Changeset d0ce666f in sasview


Ignore:
Timestamp:
Sep 6, 2018 2:11:25 PM (13 months ago)
Author:
krzywon
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, unittest-saveload
Children:
44e8f48
Parents:
fa412df
Message:

Remove image references when report is closed and point to correct file locations when saving reports to PDF.

Location:
src/sas/sasgui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/report_dialog.py

    r91552b5 rd0ce666f  
    77import sys 
    88import wx.html as html 
     9from sas.sasgui.guiframe.report_image_handler import ReportImageHandler 
    910 
    1011logger = logging.getLogger(__name__) 
     
    7071        button_close = wx.Button(self, wx.ID_OK, "Close") 
    7172        button_close.SetToolTipString("Close this report window.") 
     73        button_close.Bind(wx.EVT_BUTTON, self.onClose, 
     74                          id=button_close.GetId()) 
    7275        hbox.Add(button_close) 
    7376        button_close.SetFocus() 
     
    117120 
    118121 
    119     def OnClose(self, event=None): 
     122    def onClose(self, event=None): 
    120123        """ 
    121124        Close the Dialog 
     
    123126        """ 
    124127        for fig in self.fig_urls: 
    125             self.imgRAM.RemoveFile(fig) 
     128            ReportImageHandler.remove_figure(fig) 
    126129 
    127         self.Close() 
     130        self.Destroy() 
    128131 
    129132    def HTML2PDF(self, data, filename): 
  • src/sas/sasgui/guiframe/report_image_handler.py

    rfa412df rd0ce666f  
    11import wx 
     2import logging 
     3 
     4logger = logging.getLogger(__name__) 
    25 
    36 
     
    912 
    1013        def __init__(self): 
     14            wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 
    1115            self.img_holder = wx.MemoryFSHandler() 
    12             wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 
    1316            self.refs = {} 
    1417            self.indices = [] 
     
    6063 
    6164    @staticmethod 
     65    def check_for_empty_instance(): 
     66        if ReportImageHandler.instance is None: 
     67            ReportImageHandler.instance = \ 
     68                ReportImageHandler._ReportImageHandler() 
     69 
     70    @staticmethod 
    6271    def set_figs(figs, bitmaps, perspective): 
    63         if not ReportImageHandler.instance: 
    64             ReportImageHandler.instance = ReportImageHandler._ReportImageHandler() 
     72        ReportImageHandler.check_for_empty_instance() 
    6573        return ReportImageHandler.instance.set_figs(figs, bitmaps, perspective) 
     74 
     75    @staticmethod 
     76    def remove_figure(fig_url): 
     77        try: 
     78            ReportImageHandler.check_for_empty_instance() 
     79            ReportImageHandler.instance.refs.pop(fig_url) 
     80        except Exception as e: 
     81            logger.warn(e) 
  • src/sas/sasgui/perspectives/fitting/report_dialog.py

    r69a6897 rd0ce666f  
    7474        # save figures 
    7575        pictures = [] 
    76         for num in range(self.nimages): 
    77             pic_name = basename + '_img%s.png' % num 
     76        i = 0 
     77        for url in self.fig_urls: 
     78            append_me = url.split(':')[1] 
     79            pic_name = basename + '_{}'.format(append_me) 
    7880            # save the image for use with pdf writer 
    79             self.report_list[2][num].savefig(pic_name) 
     81            self.report_list[2][i].savefig(pic_name) 
    8082            pictures.append(pic_name) 
     83            i += 1 
    8184 
    8285        # translate png references int html from in-memory name to on-disk name 
    83         html = self.report_html.replace("memory:img_fit", basename+'_img') 
     86        html = self.report_html.replace("memory:", basename+'_') 
    8487 
    8588        #set file extensions 
  • src/sas/sasgui/perspectives/invariant/report_dialog.py

    r959eb01 rd0ce666f  
    4141 
    4242        # put image path in the report string 
    43         self.report_html = self.report_list[0] % "memory:img_inv.png" 
     43        self.report_html = self.report_list[0] % self.fig_urls[0] 
    4444        # layout 
    4545        self._setup_layout() 
Note: See TracChangeset for help on using the changeset viewer.