source: sasview/src/sas/plottools/toolbar.py @ 7e0f9b5

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 7e0f9b5 was 3477478, checked in by Mathieu Doucet <doucetm@…>, 10 years ago

pylint fixes

  • 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':
[3477478]11    def bind(actor, event, action, **kw):
12        actor.Bind(event, action, **kw)
[eea3ffa]13else:
[3477478]14    def bind(actor, event, action, id=None):
[eea3ffa]15        if id is not None:
16            event(actor, id, action)
17        else:
[3477478]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
[3477478]30   
[eea3ffa]31    def _init_toolbar(self):
32        self._parent = self.canvas.GetParent()
[3477478]33        _NTB2_HOME = wx.NewId()
34        self._NTB2_BACK = wx.NewId()
[eea3ffa]35        self._NTB2_FORWARD = wx.NewId()
[3477478]36        self._NTB2_PAN = wx.NewId()
37        self._NTB2_ZOOM = wx.NewId()
38        _NTB2_SAVE = wx.NewId()
39        _NTB2_PRINT = wx.NewId()
40        _NTB2_RESET = wx.NewId()
[eea3ffa]41
[da6c9847]42        # for mpl 1.2+ compatibility
43        self.wx_ids = {}
44        self.wx_ids['Back'] = self._NTB2_BACK
45        self.wx_ids['Forward'] = self._NTB2_FORWARD
46        self.wx_ids['Pan'] = self._NTB2_PAN
47        self.wx_ids['Zoom'] = self._NTB2_ZOOM
48
[3477478]49        self.SetToolBitmapSize(wx.Size(24, 24))
[eea3ffa]50
[a9d5684]51        context_tip = 'Graph Menu: \n'
52        context_tip += '    For more menu options, \n'
53        context_tip += '    right-click the data symbols.'
54        context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR)
[eea3ffa]55        self.AddSimpleTool(_NTB2_HOME, context, context_tip, context_tip)
56
[a9d5684]57        self.InsertSeparator(1)
[3477478]58
[eea3ffa]59        self.AddSimpleTool(self._NTB2_BACK, _load_bitmap('back.png'),
60                           'Back', 'Back navigation view')
61        self.AddSimpleTool(self._NTB2_FORWARD, _load_bitmap('forward.png'),
62                           'Forward', 'Forward navigation view')
63        # todo: get new bitmap
64        self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'),
[3477478]65                          shortHelp='Pan',
66                          longHelp='Pan with left, zoom with right')
[eea3ffa]67        self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'),
[3477478]68                          shortHelp='Zoom', longHelp='Zoom to rectangle')
[eea3ffa]69
70        self.AddSeparator()
71        self.AddSimpleTool(_NTB2_SAVE, _load_bitmap('filesave.png'),
72                           'Save', 'Save plot contents to file')
[3477478]73
[a9d5684]74        print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR)
[eea3ffa]75        self.AddSimpleTool(_NTB2_PRINT, print_bmp, 'Print', 'Print plot')
[3477478]76
[a9d5684]77        reset_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR)
[eea3ffa]78        self.AddSimpleTool(_NTB2_RESET, reset_bmp, 'Reset', 'Reset graph range')
79
80        bind(self, wx.EVT_TOOL, self.on_menu, id=_NTB2_HOME)
81        bind(self, wx.EVT_TOOL, self.forward, id=self._NTB2_FORWARD)
82        bind(self, wx.EVT_TOOL, self.back, id=self._NTB2_BACK)
83        bind(self, wx.EVT_TOOL, self.zoom, id=self._NTB2_ZOOM)
84        bind(self, wx.EVT_TOOL, self.pan, id=self._NTB2_PAN)
[da6c9847]85        bind(self, wx.EVT_TOOL, self.save_figure, id=_NTB2_SAVE)
[eea3ffa]86        bind(self, wx.EVT_TOOL, self.on_print, id=_NTB2_PRINT)
87        bind(self, wx.EVT_TOOL, self.on_reset, id=_NTB2_RESET)
88
89        self.Realize()
[da6c9847]90
[a9d5684]91    def on_menu(self, event):
92        """
[eea3ffa]93            Plot menu
[a9d5684]94        """
95        try:
[eea3ffa]96            self._parent.onToolContextMenu(event=event)
[a9d5684]97        except:
[eea3ffa]98            logging.error("Plot toolbar could not show menu")
[da6c9847]99
[a9d5684]100    def on_reset(self, event):
101        """
[eea3ffa]102            Reset plot
[a9d5684]103        """
104        try:
[eea3ffa]105            self._parent.onResetGraph(event=event)
[a9d5684]106        except:
[eea3ffa]107            logging.error("Plot toolbar could not reset plot")
[da6c9847]108
[a9d5684]109    def on_print(self, event):
110        """
[eea3ffa]111            Print
[a9d5684]112        """
113        try:
[eea3ffa]114            self.canvas.Printer_Preview(event=event)
[a9d5684]115        except:
[eea3ffa]116            logging.error("Plot toolbar could not print")
Note: See TracBrowser for help on using the repository browser.