Changeset eea3ffa in sasview


Ignore:
Timestamp:
Apr 3, 2014 10:21:43 AM (10 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
51f14603
Parents:
caf273b
Message:

Re #216 Fix plot toolbar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sans/plottools/toolbar.py

    ra9d5684 reea3ffa  
    44import wx 
    55from 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) 
    619 
    720class NavigationToolBar(NavigationToolbar2WxAgg): 
     
    1124    def __init__(self, canvas, parent=None): 
    1225        NavigationToolbar2WxAgg.__init__(self, canvas) 
    13         #the panel using this toolbar 
    14         self.parent = parent 
    15         #save canvas 
    16         self.canvas = canvas 
    17         #remove some icones 
    18         self.delete_option() 
    19         #add more icone 
    20         self.add_option() 
    21         
    22     def delete_option(self): 
    23         """ 
    24         remove default toolbar item 
    25         """ 
    26         #delte reset button 
    27         self.DeleteToolByPos(0) 
    28         #delete unwanted button that configures subplot parameters 
    29         self.DeleteToolByPos(5) 
    3026         
    31     def add_option(self): 
    32         """ 
    33         add item to the toolbar 
    34         """ 
    35         #add print button 
    36         id_context = wx.NewId() 
     27    def _init_toolbar(self): 
     28        self._parent = self.canvas.GetParent() 
     29        _NTB2_HOME         = wx.NewId() 
     30        self._NTB2_BACK    = wx.NewId() 
     31        self._NTB2_FORWARD = wx.NewId() 
     32        self._NTB2_PAN     = wx.NewId() 
     33        self._NTB2_ZOOM    = wx.NewId() 
     34        _NTB2_SAVE         = wx.NewId() 
     35        _NTB2_PRINT        = wx.NewId() 
     36        _NTB2_RESET        = wx.NewId() 
     37 
     38        self.SetToolBitmapSize(wx.Size(24,24)) 
     39 
    3740        context_tip = 'Graph Menu: \n' 
    3841        context_tip += '    For more menu options, \n' 
    3942        context_tip += '    right-click the data symbols.' 
    4043        context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 
    41         self.InsertSimpleTool(0, id_context, context, 
    42                                    context_tip, context_tip) 
    43         wx.EVT_TOOL(self, id_context, self.on_menu) 
     44        self.AddSimpleTool(_NTB2_HOME, context, context_tip, context_tip) 
     45 
    4446        self.InsertSeparator(1) 
    4547         
    46         id_print = wx.NewId() 
     48        self.AddSimpleTool(self._NTB2_BACK, _load_bitmap('back.png'), 
     49                           'Back', 'Back navigation view') 
     50        self.AddSimpleTool(self._NTB2_FORWARD, _load_bitmap('forward.png'), 
     51                           'Forward', 'Forward navigation view') 
     52        # todo: get new bitmap 
     53        self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'), 
     54                           shortHelp='Pan', 
     55                           longHelp='Pan with left, zoom with right') 
     56        self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'), 
     57                           shortHelp='Zoom', longHelp='Zoom to rectangle') 
     58 
     59        self.AddSeparator() 
     60        self.AddSimpleTool(_NTB2_SAVE, _load_bitmap('filesave.png'), 
     61                           'Save', 'Save plot contents to file') 
     62         
    4763        print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 
    48         self.AddSimpleTool(id_print, print_bmp, 
    49                            'Print', 'Activate printing') 
    50         wx.EVT_TOOL(self, id_print, self.on_print) 
    51         #add reset button 
    52         id_reset = wx.NewId() 
     64        self.AddSimpleTool(_NTB2_PRINT, print_bmp, 'Print', 'Print plot') 
     65         
    5366        reset_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR) 
    54         self.AddSimpleTool(id_reset, reset_bmp, 
    55                            'Reset Graph Range', 'Reset graph range') 
    56         wx.EVT_TOOL(self, id_reset, self.on_reset) 
     67        self.AddSimpleTool(_NTB2_RESET, reset_bmp, 'Reset', 'Reset graph range') 
     68 
     69        bind(self, wx.EVT_TOOL, self.on_menu, id=_NTB2_HOME) 
     70        bind(self, wx.EVT_TOOL, self.forward, id=self._NTB2_FORWARD) 
     71        bind(self, wx.EVT_TOOL, self.back, id=self._NTB2_BACK) 
     72        bind(self, wx.EVT_TOOL, self.zoom, id=self._NTB2_ZOOM) 
     73        bind(self, wx.EVT_TOOL, self.pan, id=self._NTB2_PAN) 
     74        bind(self, wx.EVT_TOOL, self.save, id=_NTB2_SAVE) 
     75        bind(self, wx.EVT_TOOL, self.on_print, id=_NTB2_PRINT) 
     76        bind(self, wx.EVT_TOOL, self.on_reset, id=_NTB2_RESET) 
     77 
     78        self.Realize() 
    5779         
    5880    def on_menu(self, event): 
    5981        """ 
    60         activate reset 
     82            Plot menu 
    6183        """ 
    6284        try: 
    63             self.parent.onToolContextMenu(event=event) 
     85            self._parent.onToolContextMenu(event=event) 
    6486        except: 
    65             pass 
     87            logging.error("Plot toolbar could not show menu") 
    6688         
    6789    def on_reset(self, event): 
    6890        """ 
    69         activate reset 
     91            Reset plot 
    7092        """ 
    7193        try: 
    72             self.parent.onResetGraph(event=event) 
     94            self._parent.onResetGraph(event=event) 
    7395        except: 
    74             pass 
     96            logging.error("Plot toolbar could not reset plot") 
    7597         
    7698    def on_print(self, event): 
    7799        """ 
    78         activate print 
     100            Print 
    79101        """ 
    80102        try: 
    81             self.canvas.Printer_Print(event=event) 
     103            self.canvas.Printer_Preview(event=event) 
    82104        except: 
    83             pass 
     105            logging.error("Plot toolbar could not print") 
    84106         
Note: See TracChangeset for help on using the changeset viewer.