Changeset d3d67f0 in sasview for src/sas/plottools/PlotPanel.py


Ignore:
Timestamp:
Jul 10, 2015 6:27:04 PM (9 years ago)
Author:
Paul Kienzle <pkienzle@…>
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
Message:

fix toolbar on bumps/tools graphs

File:
1 edited

Legend:

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

    r098f3d2 rd3d67f0  
    2222 
    2323from plottables import Graph 
    24 from plottables import Text 
    2524from TextDialog import TextDialog 
    2625from LabelDialog import LabelDialog 
     
    3332import numpy 
    3433 
    35 from sas.guiframe.events import StatusEvent 
     34from ..guiframe.events import StatusEvent 
     35from .toolbar import NavigationToolBar, PlotPrintout, bind 
    3636 
    3737def show_tree(obj, d=0): 
     
    8989            lo, hi = math.pow(10., lo), math.pow(10., hi) 
    9090    return (lo, hi) 
    91  
    92  
    93 def CopyImage(canvas): 
    94     """ 
    95     0: matplotlib plot 
    96     1: wx.lib.plot 
    97     2: other 
    98     """ 
    99     bmp = wx.BitmapDataObject() 
    100     bmp.SetBitmap(canvas.bitmap) 
    101  
    102     wx.TheClipboard.Open() 
    103     wx.TheClipboard.SetData(bmp) 
    104     wx.TheClipboard.Close() 
    10591 
    10692 
     
    334320        """ 
    335321        self.enable_toolbar = True 
    336         from toolbar import NavigationToolBar 
    337322        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) 
    338325        self.toolbar.Realize() 
    339326        ## The 'SetToolBar()' is not working on MAC: JHC 
     
    19661953        self.toolbar.update() 
    19671954 
     1955    def onPrint(self, event=None): 
     1956        self.toolbar.print_figure(event) 
     1957 
    19681958    def onPrinterSetup(self, event=None): 
    19691959        """ 
     
    19881978 
    19891979            #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)) 
    19921982            #and tie it to a printpreview frame then show it 
    19931983            _frame = wx.PreviewFrame(_preview, _plot, "Print Preview", wx.Point(100, 100), wx.Size(600, 650)) 
     
    19991989            pass 
    20001990 
    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 
    20051994        """ 
    20061995        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() 
    20191997        except: 
    20201998            print "Error in copy Image" 
     
    20462024            self._drawn += 1 
    20472025        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 methods 
    2053     may be added/overriden in the future. 
    2054     :TODO: this needs LOTS of TLC .. but fixes immediate problem 
    2055     """ 
    2056     def __init__(self, figure, title, size=None, dpi=None, **kwargs): 
    2057         """ 
    2058         Initialize wx.Printout and get passed figure object 
    2059         """ 
    2060         wx.Printout.__init__(self) 
    2061         self.figure = figure 
    2062  
    2063     def OnPrintPage(self, page): 
    2064         """ 
    2065         Most rudimentry OnPrintPage overide.  instatiates a dc object, gets 
    2066         its size, gets the size of the figure object, scales it to the dc 
    2067         canvas size keeping the aspect ratio intact, then prints as bitmap 
    2068         """ 
    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 True 
    2076  
    2077     def GetPageInfo(self): 
    2078         """ 
    2079         just sets the page to 1 - no flexibility for now 
    2080         """ 
    2081         return (1, 1, 1, 1) 
Note: See TracChangeset for help on using the changeset viewer.