source: sasview/src/sas/plottools/toolbar.py @ 54b9ad2

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 54b9ad2 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
Line 
1"""
2    This module overwrites matplotlib toolbar
3"""
4import wx
5from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
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)
19
20class NavigationToolBar(NavigationToolbar2WxAgg):
21    """
22    Overwrite matplotlib toolbar
23    """
24    def __init__(self, canvas, parent=None):
25        NavigationToolbar2WxAgg.__init__(self, canvas)
26
27    # CRUFT: mpl 1.1 uses save rather than save_figure
28    try: save_figure = NavigationToolbar2WxAgg.save
29    except AttributeError: pass
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
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
48        self.SetToolBitmapSize(wx.Size(24,24))
49
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)
54        self.AddSimpleTool(_NTB2_HOME, context, context_tip, context_tip)
55
56        self.InsertSeparator(1)
57       
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       
73        print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR)
74        self.AddSimpleTool(_NTB2_PRINT, print_bmp, 'Print', 'Print plot')
75       
76        reset_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR)
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)
84        bind(self, wx.EVT_TOOL, self.save_figure, id=_NTB2_SAVE)
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()
89
90    def on_menu(self, event):
91        """
92            Plot menu
93        """
94        try:
95            self._parent.onToolContextMenu(event=event)
96        except:
97            logging.error("Plot toolbar could not show menu")
98
99    def on_reset(self, event):
100        """
101            Reset plot
102        """
103        try:
104            self._parent.onResetGraph(event=event)
105        except:
106            logging.error("Plot toolbar could not reset plot")
107
108    def on_print(self, event):
109        """
110            Print
111        """
112        try:
113            self.canvas.Printer_Preview(event=event)
114        except:
115            logging.error("Plot toolbar could not print")
116       
Note: See TracBrowser for help on using the repository browser.