Changeset 1170492 in sasview for src/sas


Ignore:
Timestamp:
Jul 4, 2015 5:18:40 AM (9 years ago)
Author:
butler
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:
be34c71
Parents:
649806d
Message:

2 fixes:
1)Fix the save feature from plot panels — replace canvas.save with new
canvas.save_figure.

2)Fix printing problem .. kindof. Works but a bit ugly.

Location:
src/sas/plottools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/plottools/PlotPanel.py

    r7e0f9b5 r1170492  
    33""" 
    44import logging 
     5import traceback 
    56import wx 
    67# Try a normal import first 
     
    862863        Implement save image 
    863864        """ 
    864         self.toolbar.save(evt) 
     865        self.toolbar.save_figure(evt) 
    865866 
    866867    def onContextMenu(self, event): 
     
    19861987    def onPrinterPreview(self, event=None): 
    19871988        """ 
     1989        Matplotlib camvas can no longer print itself.  Thus need to do 
     1990        everything ourselves: need to create a printpreview frame to to 
     1991        see the preview but needs a parent frame object.  Also needs a 
     1992        printout object (just as any printing task). 
    19881993        """ 
    19891994        try: 
    1990             self.canvas.Printer_Preview(event=event) 
    1991             self.Update() 
     1995            #check if parent is a frame.  If not keep getting the higher 
     1996            #parent till we find a frame 
     1997            _plot = self 
     1998            while not isinstance(_plot, wx.Frame): 
     1999                _plot = _plot.GetParent() 
     2000                assert _plot is not None 
     2001 
     2002            #now create the printpeview object 
     2003            _preview = wx.PrintPreview(PlotPrintout(self,'test'), 
     2004                                       PlotPrintout(self,'test')) 
     2005            #and tie it to a printpreview frame then show it 
     2006            _frame = wx.PreviewFrame(_preview, _plot, "Print Preview", wx.Point(100, 100), wx.Size(600, 650)) 
     2007            _frame.Centre(wx.BOTH) 
     2008            _frame.Initialize() 
     2009            _frame.Show(True) 
    19922010        except: 
     2011            traceback.print_exc() 
    19932012            pass 
    19942013 
    19952014    def onPrint(self, event=None): 
    19962015        """ 
     2016        Matplotlib canvas can no longer print itself so using wx.Printer.   
     2017        Need therefore to also define a Printout object. 
    19972018        """ 
    19982019        try: 
    1999             self.canvas.Printer_Print(event=event) 
    2000             self.Update() 
     2020            _printer = wx.Printer() 
     2021            _printer.Print(self.canvas, PlotPrintout(self,'test'), True) 
    20012022        except: 
     2023            traceback.print_exc() 
    20022024            pass 
    20032025 
     
    20372059            self._drawn += 1 
    20382060        self.gui_repaint(drawDC=wx.PaintDC(self)) 
     2061 
     2062class PlotPrintout(wx.Printout): 
     2063    """ 
     2064    Create the wx.Printout object for matplotlib figure from the PlotPanel. 
     2065    Provides the required OnPrintPage and HasPage overrides.  Other methods 
     2066    may be added/overriden in the future. 
     2067    :TODO: this needs LOTS of TLC .. but fixes immediate problem 
     2068    """ 
     2069    def __init__(self, figure, title, size=None, dpi=None, **kwargs): 
     2070        """ 
     2071        Initialize wx.Printout and get passed figure object 
     2072        """ 
     2073        wx.Printout.__init__(self) 
     2074        self.figure = figure 
     2075 
     2076    def OnPrintPage(self, page): 
     2077        """ 
     2078        Most rudimentry OnPrintPage overide.  instatiates a dc object, gets 
     2079        its size, gets the size of the figure object, scales it to the dc 
     2080        canvas size keeping the aspect ratio intact, then prints as bitmap 
     2081        """ 
     2082        _dc = self.GetDC() 
     2083        (_dcX, _dcY) = _dc.GetSizeTuple() 
     2084        (_bmpX,_bmpY) = self.figure.canvas.GetSize() 
     2085        _scale = min(_dcX/_bmpX, _dcY/_bmpY) 
     2086        _dc.SetUserScale(_scale, _scale) 
     2087        _dc.DrawBitmap(self.figure.canvas.bitmap, 0, 0, False,) 
     2088        return True 
     2089 
     2090    def GetPageInfo(self): 
     2091        """ 
     2092        just sets the page to 1 - no flexibility for now 
     2093        """ 
     2094        return (1, 1, 1, 1) 
  • src/sas/plottools/toolbar.py

    r3477478 r1170492  
    112112        """ 
    113113        try: 
    114             self.canvas.Printer_Preview(event=event) 
     114            self._parent.onPrint(event=event) 
    115115        except: 
    116116            logging.error("Plot toolbar could not print") 
Note: See TracChangeset for help on using the changeset viewer.