Changeset 3b7b218 in sasview for src/sas/qtgui/PlotterBase.py


Ignore:
Timestamp:
Dec 9, 2016 9:46:23 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
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
Children:
c4e5400
Parents:
fecfe28
Message:

Code review from TN + more unit tests for plotters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/PlotterBase.py

    rb4b8589 r3b7b218  
    2727        self.figure = plt.figure() 
    2828 
    29         # this is the Canvas Widget that displays the `figure` 
    30         # it takes the `figure` instance as a parameter to __init__ 
     29        # Define canvas for the figure to be placed on 
    3130        self.canvas = FigureCanvas(self.figure) 
    3231 
    33         # this is the Navigation widget 
    34         # it takes the Canvas widget and a parent 
     32        # ... and the toolbar with all the default MPL buttons 
    3533        self.toolbar = NavigationToolbar(self.canvas, self) 
    3634 
    37         self.properties = ScaleProperties(self) 
    38  
    39         # set the layout 
     35        # Set the layout and place the canvas widget in it. 
    4036        layout = QtGui.QVBoxLayout() 
    4137        layout.setMargin(0) 
    4238        layout.addWidget(self.canvas) 
    4339 
    44         # defaults 
     40        # 1D plotter defaults 
    4541        self.current_plot = 111 
    4642        self._data = [] # Original 1D/2D object 
     
    5652        self.y_label = "log10(y)" 
    5753 
     54        # Pre-define the Scale properties dialog 
     55        self.properties = ScaleProperties(self, 
     56                                          init_scale_x=self.x_label, 
     57                                          init_scale_y=self.y_label) 
     58 
    5859        # default color map 
    5960        self.cmap = DEFAULT_CMAP 
    6061 
     62        # Add the axes object -> subplot 
     63        # TODO: self.ax will have to be tracked and exposed 
     64        # to enable subplot specific operations 
    6165        self.ax = self.figure.add_subplot(self.current_plot) 
     66 
     67        # Set the background color to white 
    6268        self.canvas.figure.set_facecolor('#FFFFFF') 
    6369 
     
    6571            # set the layout 
    6672            layout.addWidget(self.toolbar) 
    67             # Notify the helper 
    68             PlotHelper.addPlot(self) 
    6973            # Add the context menu 
    7074            self.contextMenu() 
    71             # Notify the listeners 
    72             self.manager.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots()) 
     75            # Notify PlotHelper about the new plot 
     76            self.upatePlotHelper() 
    7377        else: 
    7478            self.contextMenuQuickPlot() 
     
    8387    @data.setter 
    8488    def data(self, data=None): 
    85         """ virtual data setter """ 
    86         raise ImportError("Data setter must be implemented in derived class.") 
     89        """ Pure virtual data setter """ 
     90        raise NotImplementedError("Data setter must be implemented in derived class.") 
    8791 
    8892    def title(self, title=""): 
     
    132136        self._xscale = scale 
    133137 
     138    def upatePlotHelper(self): 
     139        """ 
     140        Notify the plot helper about the new plot 
     141        """ 
     142        # Notify the helper 
     143        PlotHelper.addPlot(self) 
     144        # Notify the listeners about a new graph 
     145        self.manager.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots()) 
     146 
    134147    def contextMenu(self): 
    135148        """ 
    136         Define context menu and associated actions for the MPL widget 
     149        Define common context menu and associated actions for the MPL widget 
     150        TODO: move to plotter1d/plotter2d 
    137151        """ 
    138152        # Actions 
     
    152166        Define context menu and associated actions for the quickplot MPL widget 
    153167        """ 
    154         raise ImportError("Context menu method must be implemented in derived class.") 
     168        raise NotImplementedError("Context menu method must be implemented in derived class.") 
    155169 
    156170    def contextMenuEvent(self, event): 
     
    169183    def plot(self, marker=None, linestyle=None): 
    170184        """ 
    171         VIRTUAL 
     185        PURE VIRTUAL 
    172186        Plot the content of self._data 
    173187        """ 
    174         raise ImportError("Plot method must be implemented in derived class.") 
     188        raise NotImplementedError("Plot method must be implemented in derived class.") 
    175189 
    176190    def closeEvent(self, event): 
Note: See TracChangeset for help on using the changeset viewer.