Changeset 3b7b218 in sasview


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

Location:
src/sas/qtgui
Files:
1 added
6 edited

Legend:

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

    r64f1e93 r3b7b218  
    1010from UnitTesting import TestUtilsTest 
    1111from UnitTesting import PlotHelperTest 
     12from UnitTesting import PlotterBaseTest 
    1213from UnitTesting import PlotterTest 
    1314from UnitTesting import Plotter2DTest 
     
    2829        unittest.makeSuite(TestUtilsTest.TestUtilsTest,        'test'), 
    2930        unittest.makeSuite(PlotHelperTest.PlotHelperTest,       'test'), 
     31        unittest.makeSuite(PlotterBaseTest.PlotterBaseTest,     'test'), 
    3032        unittest.makeSuite(PlotterTest.PlotterTest,          'test'), 
    3133        unittest.makeSuite(Plotter2DTest.Plotter2DTest,        'test'), 
  • src/sas/qtgui/Plotter.py

    rfecfe28 r3b7b218  
    6767 
    6868        # Include scaling (log vs. linear) 
    69         ax.set_yscale(self.xscale) 
    7069        ax.set_xscale(self.xscale) 
     70        ax.set_yscale(self.yscale) 
    7171 
    7272        # refresh canvas 
  • 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): 
  • src/sas/qtgui/ScaleProperties.py

    • Property mode changed from 100755 to 100644
    r6d05e1d r3b7b218  
    1919} 
    2020class ScaleProperties(QtGui.QDialog, Ui_scalePropertiesUI): 
    21     def __init__(self, parent=None): 
     21    def __init__(self, parent=None, init_scale_x='x', init_scale_y='y'): 
    2222        super(ScaleProperties, self).__init__(parent) 
    2323        self.setupUi(self) 
     
    2929        # Resize the dialog only AFTER the boxes are populated 
    3030        self.setFixedSize(self.minimumSizeHint()) 
     31 
     32        # Set up the initial values for x and y. 
     33        # This avoids keeping a QModel instance here. 
     34        if init_scale_x in x_values and init_scale_y in y_values: 
     35            self.cbX.setCurrentIndex(x_values.index(init_scale_x)) 
     36            self.cbY.setCurrentIndex(y_values.index(init_scale_y)) 
    3137 
    3238        # Connect combobox index change to a custom method 
  • src/sas/qtgui/run_tests.bat

    r55d89f8 r3b7b218  
    1212python -m UnitTesting.PlotHelperTest 
    1313python -m UnitTesting.KiessigCalculatorTest 
     14python -m UnitTesting.PlotterBaseTest 
    1415python -m UnitTesting.PlotterTest 
    1516python -m UnitTesting.Plotter2DTest 
  • src/sas/qtgui/run_tests.sh

    r55d89f8 r3b7b218  
    99python -m UnitTesting.PlotHelperTest 
    1010python -m UnitTesting.SasviewLoggerTest 
     11python -m UnitTesting.PlotterBaseTest 
    1112python -m UnitTesting.PlotterTest 
    1213python -m UnitTesting.Plotter2DTest 
Note: See TracChangeset for help on using the changeset viewer.