source: sasview/src/sas/plottools/toolbar.py @ 27ab091

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 27ab091 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[a9d5684]1"""
2    This module overwrites matplotlib toolbar
3"""
4import wx
5from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
[eea3ffa]6from matplotlib.backends.backend_wx import _load_bitmap
7import logging
8
9# Event binding code changed after version 2.5
10if wx.VERSION_STRING >= '2.5':
11    def bind(actor,event,action,**kw):
12        actor.Bind(event,action,**kw)
13else:
14    def bind(actor,event,action,id=None):
15        if id is not None:
16            event(actor, id, action)
17        else:
18            event(actor,action)
[a9d5684]19
20class NavigationToolBar(NavigationToolbar2WxAgg):
21    """
22    Overwrite matplotlib toolbar
23    """
24    def __init__(self, canvas, parent=None):
25        NavigationToolbar2WxAgg.__init__(self, canvas)
[da6c9847]26
27    # CRUFT: mpl 1.1 uses save rather than save_figure
28    try: save_figure = NavigationToolbar2WxAgg.save
29    except AttributeError: pass
[eea3ffa]30    def _init_toolbar(self):
31        self._parent = self.canvas.GetParent()
32        _NTB2_HOME         = wx.NewId()
33        self._NTB2_BACK    = wx.NewId()
34        self._NTB2_FORWARD = wx.NewId()
35        self._NTB2_PAN     = wx.NewId()
36        self._NTB2_ZOOM    = wx.NewId()
37        _NTB2_SAVE         = wx.NewId()
38        _NTB2_PRINT        = wx.NewId()
39        _NTB2_RESET        = wx.NewId()
40
[da6c9847]41        # for mpl 1.2+ compatibility
42        self.wx_ids = {}
43        self.wx_ids['Back'] = self._NTB2_BACK
44        self.wx_ids['Forward'] = self._NTB2_FORWARD
45        self.wx_ids['Pan'] = self._NTB2_PAN
46        self.wx_ids['Zoom'] = self._NTB2_ZOOM
47
[eea3ffa]48        self.SetToolBitmapSize(wx.Size(24,24))
49
[a9d5684]50        context_tip = 'Graph Menu: \n'
51        context_tip += '    For more menu options, \n'
52        context_tip += '    right-click the data symbols.'
53        context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR)
[eea3ffa]54        self.AddSimpleTool(_NTB2_HOME, context, context_tip, context_tip)
55
[a9d5684]56        self.InsertSeparator(1)
57       
[eea3ffa]58        self.AddSimpleTool(self._NTB2_BACK, _load_bitmap('back.png'),
59                           'Back', 'Back navigation view')
60        self.AddSimpleTool(self._NTB2_FORWARD, _load_bitmap('forward.png'),
61                           'Forward', 'Forward navigation view')
62        # todo: get new bitmap
63        self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'),
64                           shortHelp='Pan',
65                           longHelp='Pan with left, zoom with right')
66        self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'),
67                           shortHelp='Zoom', longHelp='Zoom to rectangle')
68
69        self.AddSeparator()
70        self.AddSimpleTool(_NTB2_SAVE, _load_bitmap('filesave.png'),
71                           'Save', 'Save plot contents to file')
72       
[a9d5684]73        print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR)
[eea3ffa]74        self.AddSimpleTool(_NTB2_PRINT, print_bmp, 'Print', 'Print plot')
75       
[a9d5684]76        reset_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR)
[eea3ffa]77        self.AddSimpleTool(_NTB2_RESET, reset_bmp, 'Reset', 'Reset graph range')
78
79        bind(self, wx.EVT_TOOL, self.on_menu, id=_NTB2_HOME)
80        bind(self, wx.EVT_TOOL, self.forward, id=self._NTB2_FORWARD)
81        bind(self, wx.EVT_TOOL, self.back, id=self._NTB2_BACK)
82        bind(self, wx.EVT_TOOL, self.zoom, id=self._NTB2_ZOOM)
83        bind(self, wx.EVT_TOOL, self.pan, id=self._NTB2_PAN)
[da6c9847]84        bind(self, wx.EVT_TOOL, self.save_figure, id=_NTB2_SAVE)
[eea3ffa]85        bind(self, wx.EVT_TOOL, self.on_print, id=_NTB2_PRINT)
86        bind(self, wx.EVT_TOOL, self.on_reset, id=_NTB2_RESET)
87
88        self.Realize()
[da6c9847]89
[a9d5684]90    def on_menu(self, event):
91        """
[eea3ffa]92            Plot menu
[a9d5684]93        """
94        try:
[eea3ffa]95            self._parent.onToolContextMenu(event=event)
[a9d5684]96        except:
[eea3ffa]97            logging.error("Plot toolbar could not show menu")
[da6c9847]98
[a9d5684]99    def on_reset(self, event):
100        """
[eea3ffa]101            Reset plot
[a9d5684]102        """
103        try:
[eea3ffa]104            self._parent.onResetGraph(event=event)
[a9d5684]105        except:
[eea3ffa]106            logging.error("Plot toolbar could not reset plot")
[da6c9847]107
[a9d5684]108    def on_print(self, event):
109        """
[eea3ffa]110            Print
[a9d5684]111        """
112        try:
[eea3ffa]113            self.canvas.Printer_Preview(event=event)
[a9d5684]114        except:
[eea3ffa]115            logging.error("Plot toolbar could not print")
[a9d5684]116       
Note: See TracBrowser for help on using the repository browser.