Changeset a281ab8 in sasview for src


Ignore:
Timestamp:
Jun 15, 2016 5:57:34 AM (8 years ago)
Author:
Piotr Rozyczko <piotr.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:
1042dba
Parents:
5032ea68
Message:

Prototype DE↔perspective api based on QStandardItem.

Location:
src/sas/qtgui
Files:
6 edited

Legend:

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

    r5032ea68 ra281ab8  
    1616# UI 
    1717from UI.TabbedFileLoadUI import DataLoadWidget 
     18 
     19# This is how to get data1/2D from the model item 
     20# data = [selected_items[0].child(0).data().toPyObject()] 
    1821 
    1922class DataExplorerWindow(DataLoadWidget): 
     
    150153            retval = msgbox.exec_() 
    151154            return 
    152         # Dig up data from model 
    153         data = [selected_items[0].child(0).data().toPyObject()] 
     155 
     156        # Dig up the item 
     157        data = selected_items 
    154158 
    155159        # TODO 
     
    157161 
    158162        # Notify the GuiManager about the send request 
    159         self._perspective.setData(data_list=data) 
     163        self._perspective.setData(data_item=data) 
    160164 
    161165 
     
    272276            message = "Loading Data Complete! " 
    273277        message += log_msg 
    274         return (output, message) 
     278        return output, message 
    275279 
    276280    def getWlist(self): 
     
    375379 
    376380 
    377     def loadComplete(self, output, message=""): 
     381    def loadComplete(self, output): 
    378382        """ 
    379383        Post message to status bar and update the data manager 
    380384        """ 
    381385        self.model.reset() 
     386        assert(type(output), tuple) 
     387 
     388        output_data = output[0] 
     389        message = output[1] 
    382390        # Notify the manager of the new data available 
    383391        self.communicate.statusBarUpdateSignal.emit(message) 
    384         self.communicate.fileDataReceivedSignal.emit(output) 
    385         self.manager.add_data(data_list=output) 
     392        self.communicate.fileDataReceivedSignal.emit(output_data) 
     393        self.manager.add_data(data_list=output_data) 
    386394 
    387395    def updateModel(self, data, p_file): 
     
    429437    def updateModelFromPerspective(self, model_item): 
    430438        """ 
    431         """ 
    432         # Overwrite the index with what we got from the perspective 
     439        Receive an update model item from a perspective 
     440        Make sure it is valid and if so, replace it in the model 
     441        """ 
     442        # Assert the correct type 
    433443        if type(model_item) != QtGui.QStandardItem: 
    434444            msg = "Wrong data type returned from calculations." 
    435445            raise AttributeError, msg 
     446        # Assert other properties 
     447 
     448        # Remove the original item         
     449 
     450        # Add the current item 
    436451        # self.model.insertRow(model_item) 
     452 
    437453        # Reset the view 
    438454        self.model.reset() 
  • src/sas/qtgui/GuiUtils.py

    r5032ea68 ra281ab8  
    205205 
    206206    # New data in current perspective 
    207     updateModelFromPerspectiveSignal = QtCore.pyqtSignal(Data1D) 
     207    updateModelFromPerspectiveSignal = QtCore.pyqtSignal(QtGui.QStandardItem) 
     208 
     209def updateModelItem(item, update_data, name=""): 
     210    """ 
     211    Updates QStandardItem with a checkboxed row named 'name' 
     212    and containing QVariant 'update_data' 
     213    """ 
     214    assert type(item) == QtGui.QStandardItem 
     215    assert type(update_data) == QtCore.QVariant 
     216 
     217    checkbox_item = QtGui.QStandardItem(True) 
     218    checkbox_item.setCheckable(True) 
     219    checkbox_item.setCheckState(QtCore.Qt.Checked) 
     220    checkbox_item.setText(name) 
     221 
     222    # Add "Info" item 
     223    info_item = QtGui.QStandardItem("Info") 
     224 
     225    # Add the actual Data1D/Data2D object 
     226    object_item = QtGui.QStandardItem() 
     227    object_item.setData(update_data) 
     228 
     229    checkbox_item.setChild(0, object_item) 
     230 
     231    # Set info_item as the only child 
     232    checkbox_item.setChild(1, info_item) 
     233 
     234    # Append the new row to the main item 
     235    item.appendRow(checkbox_item) 
  • src/sas/qtgui/Perspectives/Invariant/InvariantPerspective.py

    r5032ea68 ra281ab8  
    1212from sas.sasgui.guiframe.dataFitting import Data1D 
    1313from sas.qtgui.GuiUtils import Communicate 
     14from sas.qtgui.GuiUtils import updateModelItem 
    1415 
    1516# local 
     
    3536        self._model.appendRow(item) 
    3637 
    37 # class InvariantWindow(InvariantUI): 
    3838class InvariantWindow(tabbedInvariantUI): 
    3939    # The controller which is responsible for managing signal slots connections 
     
    5353        self._manager = manager 
    5454        self._reactor = self._manager.reactor() 
     55        self._model_item = QtGui.QStandardItem() 
    5556 
    5657        self._helpView = QtWebKit.QWebView() 
     
    119120        self._high_power_value  = float(self.model.item(WIDGETS.W_HIGHQ_POWER_VALUE).text()) 
    120121 
    121     def calculate(self): 
     122    def calculateInvariant(self): 
    122123        """ 
    123124        Use twisted to thread the calculations away. 
     
    151152        """ 
    152153        """ 
    153         self._plotter.show() 
     154        if self._low_extrapolate or self._high_extrapolate: 
     155            self._plotter.show() 
    154156        self.model = model 
    155157        self.mapper.toFirst() 
     
    160162        self.pushButton.setStyleSheet(self.style) 
    161163 
    162         # Send the new data to DE for keeping in the model 
    163         self.communicate.updateModelFromPerspectiveSignal.emit(self._data) 
     164        # Send the modified model item to DE for keeping in the model 
     165        self.communicate.updateModelFromPerspectiveSignal.emit(self._model_item) 
    164166 
    165167 
     
    255257 
    256258            # Plot the chart 
     259            title = "Low-Q extrapolation" 
    257260            self._plotter.data(extrapolated_data) 
    258             self._plotter.title("Low-Q extrapolation") 
     261            self._plotter.title(title) 
    259262            self._plotter.plot() 
    260263 
     264            # Add the plot to the model item 
     265            variant_item = QtCore.QVariant(self._plotter) 
     266            updateModelItem(self._model_item, variant_item, title) 
    261267 
    262268        if self._high_extrapolate: 
     
    271277            # find how to add this plot to the existing plot for low_extrapolate 
    272278            # Plot the chart 
     279            title = "High-Q extrapolation" 
    273280            self._plotter.data(high_out_data) 
    274             self._plotter.title("High-Q extrapolation") 
     281            self._plotter.title(title) 
    275282            self._plotter.plot() 
     283 
     284            # Add the plot to the model item 
     285            variant_item = QtCore.QVariant(self._plotter) 
     286            updateModelItem(self._model_item, variant_item, title) 
    276287 
    277288 
     
    326337 
    327338    def setupSlots(self): 
    328         self.pushButton.clicked.connect(self.calculate) 
     339        self.pushButton.clicked.connect(self.calculateInvariant) 
    329340        self.pushButton_2.clicked.connect(self.status) 
    330341        self.pushButton_3.clicked.connect(self.help) 
     
    489500        self.mapper.toFirst() 
    490501 
    491     def setData(self, data_list=None): 
     502    def setData(self, data_item): 
     503        """ 
     504        Obtain a QStandardItem object and dissect it to get Data1D/2D 
     505        Pass it over to the calculator 
     506        """ 
     507        if not isinstance(data_item, list): 
     508            msg = "Incorrect type passed to the Invariant Perspective" 
     509            raise AttributeError, msg 
     510 
     511        if not isinstance(data_item[0], QtGui.QStandardItem): 
     512            msg = "Incorrect type passed to the Invariant Perspective" 
     513            raise AttributeError, msg 
     514 
     515        self._model_item = data_item[0] 
     516 
     517        # Extract data on 1st child - this is the Data1D/2D component 
     518        data = self._model_item.child(0).data().toPyObject() 
     519 
     520        self.calculate(data_list=[data]) 
     521         
     522    def calculate(self, data_list=None): 
    492523        """ 
    493524        receive a list of data and compute invariant 
     525 
     526        TODO: pass warnings/messages to log 
    494527        """ 
    495528        msg = "" 
     
    520553                    #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error')) 
    521554                    return 
    522                 msg += "Invariant panel does not allow multiple data!\n" 
    523                 msg += "Please select one.\n" 
     555 
     556                # TODO: add msgbox for data choice 
     557                #msg += "Invariant panel does not allow multiple data!\n" 
     558                #msg += "Please select one.\n" 
    524559                #if len(data_list) > 1: 
    525560                    #from invariant_widgets import DataDialog 
     
    545580                    self._data = data 
    546581                    self._path = "unique path" 
    547                     self.calculate() 
     582                    self.calculateInvariant() 
    548583                except: 
    549584                    msg = "Invariant Set_data: " + str(sys.exc_value) 
  • src/sas/qtgui/UnitTesting/DataExplorerTest.py

    r5032ea68 ra281ab8  
    11import sys 
    22import unittest 
    3 #from twisted.trial import unittest 
    4 #from twisted.internet import reactor, defer, interfaces, threads, protocol, error 
    53 
    64from PyQt4.QtGui import * 
     
    2725            def allowBatch(self): 
    2826                return False 
    29             def setData(self, data_list=None): 
     27            def setData(self, data_item=None): 
    3028                return None 
    3129            def title(self): 
     
    271269        """ 
    272270 
     271        message="Loading Data Complete" 
    273272        data_dict = {"a1":Data1D()} 
     273        output_data = (data_dict, message) 
    274274 
    275275        self.form.manager.add_data = MagicMock() 
     
    280280 
    281281        # Read in the file 
    282         self.form.loadComplete(data_dict, message="Loading Data Complete") 
     282        self.form.loadComplete(output_data) 
    283283 
    284284        # "Loading data complete" no longer sent in LoadFile but in callback 
  • src/sas/qtgui/UnitTesting/GuiUtilsTest.py

    rf721030 ra281ab8  
     1import sys 
     2import unittest 
     3 
     4# Tested module 
     5from GuiUtils import * 
     6 
     7class GuiUtilsTest(unittest.TestCase): 
     8    '''Test the GUI Utilities methods''' 
     9    def setUp(self): 
     10        '''Empty''' 
     11        pass 
     12 
     13    def tearDown(self): 
     14        '''empty''' 
     15        pass 
     16 
     17    def testDefaults(self): 
     18        """ 
     19        Test all the global constants defined in the file. 
     20        """ 
     21        # Should probably test the constants in the file, 
     22        # but this will done after trimming down GuiUtils 
     23        # and retaining only necessary variables. 
     24        pass 
     25 
     26    def testGetAppDir(self): 
     27        """ 
     28        """ 
     29        pass 
     30 
     31    def testGetUserDirectory(self): 
     32        """ 
     33        Simple test of user directory getter 
     34        """ 
     35        home_dir = os.path.expanduser("~") 
     36        self.assertIn(home_dir, get_user_directory()) 
     37 
     38    def testCommunicate(self): 
     39        """ 
     40        Test the container class with signal definitions 
     41        """ 
     42        com = Communicate() 
     43 
     44        # All defined signals 
     45        list_of_signals = [ 
     46            'fileReadSignal', 
     47            'fileDataReceivedSignal', 
     48            'statusBarUpdateSignal', 
     49            'updatePerspectiveWithDataSignal', 
     50            'updateModelFromPerspectiveSignal' 
     51        ] 
     52 
     53        # Assure all signals are defined. 
     54        for signal in list_of_signals: 
     55            self.assertIn(signal, dir(com)) 
     56 
     57 
     58    def testUpdateModelItem(self): 
     59        """ 
     60        Test the QModelItem update method 
     61        """ 
     62        test_item = QtGui.QStandardItem() 
     63        test_list = ['aa','11'] 
     64        update_data = QtCore.QVariant(test_list) 
     65        name = "Black Sabbath" 
     66 
     67        # update the item 
     68        updateModelItem(test_item, update_data, name) 
     69         
     70        # Make sure test_item got all data added 
     71        self.assertEqual(test_item.child(0).text(), name) 
     72        self.assertTrue(test_item.child(0).isCheckable()) 
     73        list_from_item = test_item.child(0).child(0).data().toPyObject() 
     74        self.assertIsInstance(list_from_item, list) 
     75        self.assertEqual(str(list_from_item[0]), test_list[0]) 
     76        self.assertEqual(str(list_from_item[1]), test_list[1]) 
     77 
     78if __name__ == "__main__": 
     79    unittest.main() 
     80 
  • src/sas/qtgui/run_tests.sh

    r5032ea68 ra281ab8  
    1 # python -m UnitTesting.TestUtilsTest 
    2 # python -m UnitTesting.WelcomePanelTest 
     1python -m UnitTesting.TestUtilsTest 
     2python -m UnitTesting.WelcomePanelTest 
    33python -m UnitTesting.DataExplorerTest 
    4 # python -m UnitTesting.GuiManagerTest 
    5 # python -m UnitTesting.MainWindowTest 
     4python -m UnitTesting.GuiManagerTest 
     5python -m UnitTesting.MainWindowTest 
     6python -m UnitTesting.GuiUtilsTest 
    67 
Note: See TracChangeset for help on using the changeset viewer.