Changeset 1170492 in sasview
- Timestamp:
- Jul 4, 2015 3:18:40 AM (9 years ago)
- 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
- Location:
- src/sas/plottools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/PlotPanel.py
r7e0f9b5 r1170492 3 3 """ 4 4 import logging 5 import traceback 5 6 import wx 6 7 # Try a normal import first … … 862 863 Implement save image 863 864 """ 864 self.toolbar.save (evt)865 self.toolbar.save_figure(evt) 865 866 866 867 def onContextMenu(self, event): … … 1986 1987 def onPrinterPreview(self, event=None): 1987 1988 """ 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). 1988 1993 """ 1989 1994 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) 1992 2010 except: 2011 traceback.print_exc() 1993 2012 pass 1994 2013 1995 2014 def onPrint(self, event=None): 1996 2015 """ 2016 Matplotlib canvas can no longer print itself so using wx.Printer. 2017 Need therefore to also define a Printout object. 1997 2018 """ 1998 2019 try: 1999 self.canvas.Printer_Print(event=event)2000 self.Update()2020 _printer = wx.Printer() 2021 _printer.Print(self.canvas, PlotPrintout(self,'test'), True) 2001 2022 except: 2023 traceback.print_exc() 2002 2024 pass 2003 2025 … … 2037 2059 self._drawn += 1 2038 2060 self.gui_repaint(drawDC=wx.PaintDC(self)) 2061 2062 class 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 112 112 """ 113 113 try: 114 self. canvas.Printer_Preview(event=event)114 self._parent.onPrint(event=event) 115 115 except: 116 116 logging.error("Plot toolbar could not print")
Note: See TracChangeset
for help on using the changeset viewer.