Changeset d3d67f0 in sasview
- Timestamp:
- Jul 10, 2015 6:27:04 PM (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:
- a7aa5c7
- Parents:
- 098f3d2
- Location:
- src/sas/plottools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/PlotPanel.py
r098f3d2 rd3d67f0 22 22 23 23 from plottables import Graph 24 from plottables import Text25 24 from TextDialog import TextDialog 26 25 from LabelDialog import LabelDialog … … 33 32 import numpy 34 33 35 from sas.guiframe.events import StatusEvent 34 from ..guiframe.events import StatusEvent 35 from .toolbar import NavigationToolBar, PlotPrintout, bind 36 36 37 37 def show_tree(obj, d=0): … … 89 89 lo, hi = math.pow(10., lo), math.pow(10., hi) 90 90 return (lo, hi) 91 92 93 def CopyImage(canvas):94 """95 0: matplotlib plot96 1: wx.lib.plot97 2: other98 """99 bmp = wx.BitmapDataObject()100 bmp.SetBitmap(canvas.bitmap)101 102 wx.TheClipboard.Open()103 wx.TheClipboard.SetData(bmp)104 wx.TheClipboard.Close()105 91 106 92 … … 334 320 """ 335 321 self.enable_toolbar = True 336 from toolbar import NavigationToolBar337 322 self.toolbar = NavigationToolBar(parent=self, canvas=self.canvas) 323 bind(self.toolbar, wx.EVT_TOOL, self.onResetGraph, id=self.toolbar._NTB2_RESET) 324 bind(self.toolbar, wx.EVT_TOOL, self.onContextMenu, id=self.toolbar._NTB2_HOME) 338 325 self.toolbar.Realize() 339 326 ## The 'SetToolBar()' is not working on MAC: JHC … … 1966 1953 self.toolbar.update() 1967 1954 1955 def onPrint(self, event=None): 1956 self.toolbar.print_figure(event) 1957 1968 1958 def onPrinterSetup(self, event=None): 1969 1959 """ … … 1988 1978 1989 1979 #now create the printpeview object 1990 _preview = wx.PrintPreview(PlotPrintout(self ,'test'),1991 PlotPrintout(self ,'test'))1980 _preview = wx.PrintPreview(PlotPrintout(self.canvas), 1981 PlotPrintout(self.canvas)) 1992 1982 #and tie it to a printpreview frame then show it 1993 1983 _frame = wx.PreviewFrame(_preview, _plot, "Print Preview", wx.Point(100, 100), wx.Size(600, 650)) … … 1999 1989 pass 2000 1990 2001 def onPrint(self, event=None): 2002 """ 2003 Matplotlib canvas can no longer print itself so using wx.Printer. 2004 Need therefore to also define a Printout object. 1991 def OnCopyFigureMenu(self, evt): 1992 """ 1993 Copy the current figure to clipboard 2005 1994 """ 2006 1995 try: 2007 _printer = wx.Printer() 2008 _printer.Print(self.canvas, PlotPrintout(self,'test'), True) 2009 except: 2010 traceback.print_exc() 2011 pass 2012 2013 def OnCopyFigureMenu(self, evt): 2014 """ 2015 Copy the current figure to clipboard 2016 """ 2017 try: 2018 CopyImage(self.canvas) 1996 self.toolbar.copy_figure() 2019 1997 except: 2020 1998 print "Error in copy Image" … … 2046 2024 self._drawn += 1 2047 2025 self.gui_repaint(drawDC=wx.PaintDC(self)) 2048 2049 class PlotPrintout(wx.Printout):2050 """2051 Create the wx.Printout object for matplotlib figure from the PlotPanel.2052 Provides the required OnPrintPage and HasPage overrides. Other methods2053 may be added/overriden in the future.2054 :TODO: this needs LOTS of TLC .. but fixes immediate problem2055 """2056 def __init__(self, figure, title, size=None, dpi=None, **kwargs):2057 """2058 Initialize wx.Printout and get passed figure object2059 """2060 wx.Printout.__init__(self)2061 self.figure = figure2062 2063 def OnPrintPage(self, page):2064 """2065 Most rudimentry OnPrintPage overide. instatiates a dc object, gets2066 its size, gets the size of the figure object, scales it to the dc2067 canvas size keeping the aspect ratio intact, then prints as bitmap2068 """2069 _dc = self.GetDC()2070 (_dcX, _dcY) = _dc.GetSizeTuple()2071 (_bmpX,_bmpY) = self.figure.canvas.GetSize()2072 _scale = min(_dcX/_bmpX, _dcY/_bmpY)2073 _dc.SetUserScale(_scale, _scale)2074 _dc.DrawBitmap(self.figure.canvas.bitmap, 0, 0, False,)2075 return True2076 2077 def GetPageInfo(self):2078 """2079 just sets the page to 1 - no flexibility for now2080 """2081 return (1, 1, 1, 1) -
src/sas/plottools/config.py
r79492222 rd3d67f0 58 58 matplotlib.rcParams[param] = 0.05 59 59 matplotlib.rcParams['legend.numpoints'] = 1 60 61 # this should happen after initial matplotlib configuration 62 from .toolbar import NavigationToolBar 63 from matplotlib.backends import backend_wxagg 64 backend_wxagg.NavigationToolbar2WxAgg = NavigationToolBar 65 66 # CRUFT: bumps 0.7.5.6 and older uses wrong toolbar 67 backend_wxagg.NavigationToolbar2Wx = NavigationToolBar -
src/sas/plottools/toolbar.py
r1170492 rd3d67f0 31 31 def _init_toolbar(self): 32 32 self._parent = self.canvas.GetParent() 33 _NTB2_HOME = wx.NewId()33 self._NTB2_HOME = wx.NewId() 34 34 self._NTB2_BACK = wx.NewId() 35 35 self._NTB2_FORWARD = wx.NewId() 36 36 self._NTB2_PAN = wx.NewId() 37 37 self._NTB2_ZOOM = wx.NewId() 38 _NTB2_SAVE = wx.NewId()39 _NTB2_PRINT = wx.NewId()40 _NTB2_RESET = wx.NewId()38 self._NTB2_SAVE = wx.NewId() 39 self._NTB2_PRINT = wx.NewId() 40 self._NTB2_RESET = wx.NewId() 41 41 42 42 # for mpl 1.2+ compatibility … … 53 53 context_tip += ' right-click the data symbols.' 54 54 context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 55 self.AddSimpleTool( _NTB2_HOME, context, context_tip, context_tip)55 self.AddSimpleTool(self._NTB2_HOME, context, context_tip, context_tip) 56 56 57 57 self.InsertSeparator(1) … … 69 69 70 70 self.AddSeparator() 71 self.AddSimpleTool( _NTB2_SAVE, _load_bitmap('filesave.png'),71 self.AddSimpleTool(self._NTB2_SAVE, _load_bitmap('filesave.png'), 72 72 'Save', 'Save plot contents to file') 73 73 74 74 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 75 self.AddSimpleTool( _NTB2_PRINT, print_bmp, 'Print', 'Print plot')75 self.AddSimpleTool(self._NTB2_PRINT, print_bmp, 'Print', 'Print plot') 76 76 77 77 reset_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR) 78 self.AddSimpleTool( _NTB2_RESET, reset_bmp, 'Reset', 'Reset graph range')78 self.AddSimpleTool(self._NTB2_RESET, reset_bmp, 'Reset', 'Reset graph range') 79 79 80 bind(self, wx.EVT_TOOL, self. on_menu, id=_NTB2_HOME)80 bind(self, wx.EVT_TOOL, self.context_menu, id=self._NTB2_HOME) 81 81 bind(self, wx.EVT_TOOL, self.forward, id=self._NTB2_FORWARD) 82 82 bind(self, wx.EVT_TOOL, self.back, id=self._NTB2_BACK) 83 83 bind(self, wx.EVT_TOOL, self.zoom, id=self._NTB2_ZOOM) 84 84 bind(self, wx.EVT_TOOL, self.pan, id=self._NTB2_PAN) 85 bind(self, wx.EVT_TOOL, self.save_figure, id= _NTB2_SAVE)86 bind(self, wx.EVT_TOOL, self. on_print, id=_NTB2_PRINT)87 bind(self, wx.EVT_TOOL, self. on_reset, id=_NTB2_RESET)85 bind(self, wx.EVT_TOOL, self.save_figure, id=self._NTB2_SAVE) 86 bind(self, wx.EVT_TOOL, self.print_figure, id=self._NTB2_PRINT) 87 bind(self, wx.EVT_TOOL, self.home, id=self._NTB2_RESET) 88 88 89 89 self.Realize() 90 90 91 91 def on_menu(self, event): 92 """93 Plot menu94 """95 92 try: 96 93 self._parent.onToolContextMenu(event=event) … … 98 95 logging.error("Plot toolbar could not show menu") 99 96 100 def on_reset(self, event):97 def context_menu(self, event): 101 98 """ 102 Reset plot 99 Default context menu for a plot panel 100 103 101 """ 102 # Slicer plot popup menu 103 wx_id = wx.NewId() 104 popup = wx.Menu() 105 popup.Append(wx_id, '&Save image', 'Save image as PNG') 106 wx.EVT_MENU(self, wx_id, self.save_figure) 107 108 wx_id = wx.NewId() 109 popup.Append(wx_id, '&Print image', 'Print image ') 110 wx.EVT_MENU(self, wx_id, self.print_figure) 111 112 wx_id = wx.NewId() 113 popup.Append(wx_id, '&Copy to Clipboard', 'Copy image to the clipboard') 114 wx.EVT_MENU(self, wx_id, self.copy_figure) 115 116 # Show the popup menu relative to the location of the toolbar 117 self.PopupMenu(popup, (0,0)) 118 119 120 def print_figure(self, event): 104 121 try: 105 self._parent.onResetGraph(event=event) 122 _printer = wx.Printer() 123 _printer.Print(self.canvas, PlotPrintout(self.canvas), True) 106 124 except: 107 logging.error("Plot toolbar could not reset plot") 125 import traceback 126 logging.error(traceback.format_exc()) 108 127 109 def on_print(self, event): 128 def copy_figure(self, event): 129 copy_image_to_clipboard(self.canvas) 130 131 class PlotPrintout(wx.Printout): 132 """ 133 Create the wx.Printout object for matplotlib figure from the PlotPanel. 134 Provides the required OnPrintPage and HasPage overrides. Other methods 135 may be added/overriden in the future. 136 :TODO: this needs LOTS of TLC .. but fixes immediate problem 137 """ 138 def __init__(self, canvas): 110 139 """ 111 Print140 Initialize wx.Printout and get passed figure object 112 141 """ 113 try: 114 self._parent.onPrint(event=event) 115 except: 116 logging.error("Plot toolbar could not print") 142 wx.Printout.__init__(self) 143 self.canvas = canvas 144 145 def OnPrintPage(self, page): 146 """ 147 Most rudimentry OnPrintPage overide. instatiates a dc object, gets 148 its size, gets the size of the figure object, scales it to the dc 149 canvas size keeping the aspect ratio intact, then prints as bitmap 150 """ 151 _dc = self.GetDC() 152 (_dcX, _dcY) = _dc.GetSizeTuple() 153 (_bmpX,_bmpY) = self.canvas.GetSize() 154 _scale = min(_dcX/_bmpX, _dcY/_bmpY) 155 _dc.SetUserScale(_scale, _scale) 156 _dc.DrawBitmap(self.canvas.bitmap, 0, 0, False,) 157 return True 158 159 def GetPageInfo(self): 160 """ 161 just sets the page to 1 - no flexibility for now 162 """ 163 return (1, 1, 1, 1) 164 165 166 def copy_image_to_clipboard(canvas): 167 bmp = wx.BitmapDataObject() 168 bmp.SetBitmap(canvas.bitmap) 169 170 wx.TheClipboard.Open() 171 wx.TheClipboard.SetData(bmp) 172 wx.TheClipboard.Close() 173 174
Note: See TracChangeset
for help on using the changeset viewer.