Source code for sas.sasgui.plottools.toolbar

"""
    This module overwrites matplotlib toolbar
"""
import wx
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
from matplotlib.backends.backend_wx import _load_bitmap
import logging

logger = logging.getLogger(__name__)

# Event binding code changed after version 2.5
if wx.VERSION_STRING >= '2.5':
    def bind(actor, event, action, **kw):
        actor.Bind(event, action, **kw)
else:
[docs] def bind(actor, event, action, id=None): if id is not None: event(actor, id, action) else: event(actor, action)
[docs]class PlotPrintout(wx.Printout): """ Create the wx.Printout object for matplotlib figure from the PlotPanel. Provides the required OnPrintPage and HasPage overrides. Other methods may be added/overriden in the future. :TODO: this needs LOTS of TLC .. but fixes immediate problem """ def __init__(self, canvas): """ Initialize wx.Printout and get passed figure object """ wx.Printout.__init__(self) self.canvas = canvas
[docs] def OnPrintPage(self, page): """ Most rudimentry OnPrintPage override. instatiates a dc object, gets its size, gets the size of the figure object, scales it to the dc canvas size keeping the aspect ratio intact, then prints as bitmap """ _dc = self.GetDC() (_dcX, _dcY) = _dc.GetSizeTuple() (_bmpX,_bmpY) = self.canvas.GetSize() _scale = min(_dcX/_bmpX, _dcY/_bmpY) _dc.SetUserScale(_scale, _scale) _dc.DrawBitmap(self.canvas.bitmap, 0, 0, False,) return True
[docs] def GetPageInfo(self): """ just sets the page to 1 - no flexibility for now """ return (1, 1, 1, 1)
[docs]def copy_image_to_clipboard(canvas): bmp = wx.BitmapDataObject() bmp.SetBitmap(canvas.bitmap) wx.TheClipboard.Open() wx.TheClipboard.SetData(bmp) wx.TheClipboard.Close()