Changeset 488c49d in sasview


Ignore:
Timestamp:
Jun 8, 2016 9:56:28 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:
5032ea68
Parents:
f721030
git-author:
Piotr Rozyczko <piotr.rozyczko@…> (06/08/16 09:53:59)
git-committer:
Piotr Rozyczko <piotr.rozyczko@…> (06/08/16 09:56:28)
Message:

Hold data objects in model. Added more Data Explorer functionality. Added unit tests.

Location:
src/sas/qtgui
Files:
2 added
12 deleted
10 edited

Legend:

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

    rf721030 r488c49d  
    1515 
    1616# UI 
    17 #from UI.DataExplorerUI import DataExplorerUI 
    1817from UI.TabbedFileLoadUI import DataLoadWidget 
    1918 
     
    3938        self.cmdDelete.clicked.connect(self.deleteFile) 
    4039        self.cmdSendTo.clicked.connect(self.sendData) 
     40 
     41        # Connect the comboboxes 
     42        self.cbSelect.currentIndexChanged.connect(self.selectData) 
    4143 
    4244        # Communicator for signal definitions 
     
    222224 
    223225        return wlist 
    224             
     226 
     227    def selectData(self, index): 
     228        """ 
     229        Callback method for modifying the TreeView on Selection Options change 
     230        """ 
     231        if not isinstance(index, int): 
     232            msg = "Incorrect type passed to DataExplorer.selectData()" 
     233            raise AttributeError, msg 
     234 
     235        # Respond appropriately 
     236        if index == 0: 
     237            # Select All 
     238            for index in range(self.model.rowCount()): 
     239                item = self.model.item(index) 
     240                if item.isCheckable() and item.checkState() == QtCore.Qt.Unchecked: 
     241                    item.setCheckState(QtCore.Qt.Checked) 
     242        elif index == 1: 
     243            # De-select All 
     244            for index in range(self.model.rowCount()): 
     245                item = self.model.item(index) 
     246                if item.isCheckable() and item.checkState() == QtCore.Qt.Checked: 
     247                    item.setCheckState(QtCore.Qt.Unchecked) 
     248 
     249        elif index == 2: 
     250            # Select All 1-D 
     251            for index in range(self.model.rowCount()): 
     252                item = self.model.item(index) 
     253                item.setCheckState(QtCore.Qt.Unchecked) 
     254 
     255                try: 
     256                    is1D = item.child(0).data().toPyObject().__class__.__name__ == 'Data1D' 
     257                except AttributeError: 
     258                    msg = "Bad structure of the data model." 
     259                    raise RuntimeError, msg 
     260 
     261                if is1D: 
     262                    item.setCheckState(QtCore.Qt.Checked) 
     263 
     264        elif index == 3: 
     265            # Unselect All 1-D 
     266            for index in range(self.model.rowCount()): 
     267                item = self.model.item(index) 
     268 
     269                try: 
     270                    is1D = item.child(0).data().toPyObject().__class__.__name__ == 'Data1D' 
     271                except AttributeError: 
     272                    msg = "Bad structure of the data model." 
     273                    raise RuntimeError, msg 
     274 
     275                if item.isCheckable() and item.checkState() == QtCore.Qt.Checked and is1D: 
     276                    item.setCheckState(QtCore.Qt.Unchecked) 
     277 
     278        elif index == 4: 
     279            # Select All 2-D 
     280            for index in range(self.model.rowCount()): 
     281                item = self.model.item(index) 
     282                item.setCheckState(QtCore.Qt.Unchecked) 
     283                try: 
     284                    is2D = item.child(0).data().toPyObject().__class__.__name__ == 'Data2D' 
     285                except AttributeError: 
     286                    msg = "Bad structure of the data model." 
     287                    raise RuntimeError, msg 
     288 
     289                if is2D: 
     290                    item.setCheckState(QtCore.Qt.Checked) 
     291 
     292        elif index == 5: 
     293            # Unselect All 2-D 
     294            for index in range(self.model.rowCount()): 
     295                item = self.model.item(index) 
     296 
     297                try: 
     298                    is2D = item.child(0).data().toPyObject().__class__.__name__ == 'Data2D' 
     299                except AttributeError: 
     300                    msg = "Bad structure of the data model." 
     301                    raise RuntimeError, msg 
     302 
     303                if item.isCheckable() and item.checkState() == QtCore.Qt.Checked and is2D: 
     304                    item.setCheckState(QtCore.Qt.Unchecked) 
     305 
     306        else: 
     307            msg = "Incorrect value in the Selection Option" 
     308            # Change this to a proper logging action 
     309            raise Exception, msg 
     310 
    225311 
    226312    def loadComplete(self, output, message=""): 
     
    262348        object_item.setData(QtCore.QVariant(data)) 
    263349 
     350        checkbox_item.setChild(0, object_item) 
     351 
    264352        # Add rows for display in the view 
    265353        self.addExtraRows(info_item, data) 
    266354 
    267355        # Set info_item as the only child 
    268         checkbox_item.setChild(0, info_item) 
     356        checkbox_item.setChild(1, info_item) 
    269357 
    270358        # New row in the model 
  • src/sas/qtgui/Perspectives/Invariant/UI/InvariantDetailsUI.py

    rf721030 r488c49d  
    11# -*- coding: utf-8 -*- 
    22 
    3 # Form implementation generated from reading ui file 'InvariantDetails.ui' 
     3# Form implementation generated from reading ui file 'InvariantDetailsUI.ui' 
    44# 
    55# Created by: PyQt4 UI code generator 4.11.4 
  • src/sas/qtgui/Perspectives/Invariant/UI/TabbedInvariantUI.py

    rf721030 r488c49d  
    2727        tabbedInvariantUI.setObjectName(_fromUtf8("tabbedInvariantUI")) 
    2828        tabbedInvariantUI.resize(465, 408) 
    29         icon = QtGui.QIcon() 
    30         icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/res/ball.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off) 
    31         tabbedInvariantUI.setWindowIcon(icon) 
    3229        self.gridLayout_11 = QtGui.QGridLayout(tabbedInvariantUI) 
    3330        self.gridLayout_11.setObjectName(_fromUtf8("gridLayout_11")) 
     
    315312 
    316313        self.retranslateUi(tabbedInvariantUI) 
    317         self.tabWidget.setCurrentIndex(1) 
     314        self.tabWidget.setCurrentIndex(0) 
    318315        QtCore.QMetaObject.connectSlotsByName(tabbedInvariantUI) 
    319316 
     
    374371        self.pushButton_3.setText(_translate("tabbedInvariantUI", "Help", None)) 
    375372 
    376 import main_resources_rc 
    377373 
    378374class tabbedInvariantUI(QtGui.QDialog, Ui_tabbedInvariantUI): 
  • src/sas/qtgui/Perspectives/Invariant/UI/TabbedInvariantUI.ui

    rf721030 r488c49d  
    1313  <property name="windowTitle"> 
    1414   <string>Dialog</string> 
    15   </property> 
    16   <property name="windowIcon"> 
    17    <iconset resource="main_resources.qrc"> 
    18     <normaloff>:/res/ball.ico</normaloff>:/res/ball.ico</iconset> 
    1915  </property> 
    2016  <layout class="QGridLayout" name="gridLayout_11"> 
     
    582578  </layout> 
    583579 </widget> 
    584  <resources> 
    585   <include location="main_resources.qrc"/> 
    586  </resources> 
    587580 <connections/> 
    588581</ui> 
  • src/sas/qtgui/UnitTesting/DataExplorerTest.py

    rf721030 r488c49d  
    4545 
    4646        self.assertEqual(self.form.cbSelect.count(), 6) 
     47        self.assertEqual(self.form.cbSelect.currentIndex(), 0) 
    4748 
    4849        # Class is in the default state even without pressing OK 
     
    100101        # Assure the model contains no items 
    101102 
     103    def testDataSelection(self): 
     104        """ 
     105        Tests the functionality of the Selection Option combobox 
     106        """ 
     107        # Populate the model with 1d and 2d data 
     108        filename = ["cyl_400_20.txt", "Dec07031.ASC"] 
     109        self.form.readData(filename) 
     110 
     111        # Unselect all data 
     112        self.form.cbSelect.setCurrentIndex(1) 
     113 
     114        # Test the current selection 
     115        item1D = self.form.model.item(0) 
     116        item2D = self.form.model.item(1) 
     117        self.assertTrue(item1D.checkState() == QtCore.Qt.Unchecked) 
     118        self.assertTrue(item2D.checkState() == QtCore.Qt.Unchecked)         
     119 
     120        # Select all data 
     121        self.form.cbSelect.setCurrentIndex(0) 
     122 
     123        # Test the current selection 
     124        self.assertTrue(item1D.checkState() == QtCore.Qt.Checked) 
     125        self.assertTrue(item2D.checkState() == QtCore.Qt.Checked)         
     126 
     127        # select 1d data 
     128        self.form.cbSelect.setCurrentIndex(2) 
     129 
     130        # Test the current selection 
     131        self.assertTrue(item1D.checkState() == QtCore.Qt.Checked) 
     132        self.assertTrue(item2D.checkState() == QtCore.Qt.Unchecked)         
     133 
     134        # unselect 1d data 
     135        self.form.cbSelect.setCurrentIndex(3) 
     136 
     137        # Test the current selection 
     138        self.assertTrue(item1D.checkState() == QtCore.Qt.Unchecked) 
     139        self.assertTrue(item2D.checkState() == QtCore.Qt.Unchecked)         
     140 
     141        # select 2d data 
     142        self.form.cbSelect.setCurrentIndex(4) 
     143 
     144        # Test the current selection 
     145        self.assertTrue(item1D.checkState() == QtCore.Qt.Unchecked) 
     146        self.assertTrue(item2D.checkState() == QtCore.Qt.Checked)         
     147 
     148        # unselect 2d data 
     149        self.form.cbSelect.setCurrentIndex(5) 
     150 
     151        # Test the current selection 
     152        self.assertTrue(item1D.checkState() == QtCore.Qt.Unchecked) 
     153        self.assertTrue(item2D.checkState() == QtCore.Qt.Unchecked)         
     154 
     155        # choose impossible index and assure the code raises 
     156        #with self.assertRaises(Exception): 
     157        #    self.form.cbSelect.setCurrentIndex(6) 
     158 
    102159    def testReadData(self): 
    103160        """ 
  • src/sas/qtgui/UnitTesting/GuiManagerTest.py

    rf721030 r488c49d  
     1import sys 
     2import unittest 
     3 
     4from PyQt4.QtGui import * 
     5from PyQt4.QtTest import QTest 
     6from PyQt4.QtCore import * 
     7from mock import MagicMock 
     8 
     9# Local 
     10from GuiManager import GuiManager 
     11 
     12#app = QApplication(sys.argv) 
     13 
     14class GuiManagerTest(unittest.TestCase): 
     15    '''Test the WelcomePanel''' 
     16    def setUp(self): 
     17        '''Create the tested object''' 
     18 
     19        self.manager = GuiManager(None) 
     20 
     21    def tearDown(self): 
     22        '''Destroy the GUI''' 
     23        self.manager = None 
     24 
     25    def testDefaults(self): 
     26        '''Test the object in its default state''' 
     27        pass 
     28         
     29    def testUpdatePerspective(self): 
     30        """ 
     31        """ 
     32        pass 
     33 
     34    def testUpdateStatusBar(self): 
     35        """ 
     36        """ 
     37        pass 
     38 
     39    def testSetData(self): 
     40        """ 
     41        """ 
     42        pass 
     43 
     44    def testSetData(self): 
     45        """ 
     46        """ 
     47        pass 
     48 
     49    def testActions(self): 
     50        """ 
     51        """ 
     52        pass 
     53 
     54    # test each action separately 
     55        
     56if __name__ == "__main__": 
     57    unittest.main() 
     58 
  • src/sas/qtgui/UnitTesting/TestUtils.py

    rf721030 r488c49d  
    1212        super(QtSignalSpy, self).__init__(parent) 
    1313 
    14         self._connector = {} 
     14        self._recorder = {} 
    1515        self._count = 0 
    16         self._signal = [None, None] 
     16        self._signal = [] 
    1717 
    1818        # Assign our own slot to the emitted signal 
    19         if isinstance(signal, pyqtBoundSignal): 
    20             signal.connect(self.slot) 
    21         elif hasattr(widget, signal): 
    22             getattr(widget, signal).connect(self.slot) 
    23         else: 
    24             widget.signal.connect(slot) 
     19        try: 
     20            if isinstance(signal, pyqtBoundSignal): 
     21                signal.connect(self.slot) 
     22            elif hasattr(widget, signal): 
     23                getattr(widget, signal).connect(self.slot) 
     24            else: 
     25                widget.signal.connect(slot) 
     26        except AttributeError: 
     27            msg = "Wrong construction of QtSignalSpy instance" 
     28            raise RuntimeError, msg 
    2529 
    2630    def slot(self, *args, **kwargs): 
     
    2832        Record emitted signal. 
    2933        """ 
    30         self._connector[self._count] = { 
     34        self._recorder[self._count] = { 
    3135            'args'   : args, 
    3236            'kwargs' : kwargs, 
     
    3741 
    3842    def signal(self, index=None): 
    39         """ 
    40         """ 
    4143        if index == None: 
    4244            return self._signal 
     
    4547 
    4648    def count(self): 
    47         """ 
    48         """ 
    4949        return self._count 
    5050 
    5151    def called(self): 
    52         """ 
    53         """ 
    54         return self._connector 
     52        return self._recorder 
  • src/sas/qtgui/UnitTesting/WelcomePanelTest.py

    rf721030 r488c49d  
     1import sys 
     2import unittest 
     3 
     4from PyQt4.QtGui import * 
     5from PyQt4.QtTest import QTest 
     6from PyQt4.QtCore import * 
     7 
     8# Local 
     9from WelcomePanel import WelcomePanel 
     10 
     11app = QApplication(sys.argv) 
     12 
     13class WelcomePanelTest(unittest.TestCase): 
     14    '''Test the WelcomePanel''' 
     15    def setUp(self): 
     16        '''Create the WelcomePanel''' 
     17 
     18        self.widget = WelcomePanel(None) 
     19 
     20    def tearDown(self): 
     21        '''Destroy the GUI''' 
     22        self.widget.close() 
     23        self.widget = None 
     24 
     25    def testDefaults(self): 
     26        '''Test the GUI in its default state''' 
     27        self.assertIsInstance(self.widget, QDialog) 
     28        self.assertEqual(self.widget.windowTitle(), "Welcome") 
     29         
     30    def testVersion(self): 
     31        """ 
     32        """ 
     33        version = self.widget.lblVersion 
     34        self.assertIsInstance(version, QLabel) 
     35        ver_text = "\nSasView 4.0.0-alpha\nBuild: 1\n(c) 2009 - 2013, UTK, UMD, NIST, ORNL, ISIS, ESS and IL" 
     36        #self.assertEqual(str(version.text()), ver_text) 
     37        self.assertIn("SasView", str(version.text())) 
     38        self.assertIn("Build:", str(version.text())) 
     39        
     40if __name__ == "__main__": 
     41    unittest.main() 
  • src/sas/qtgui/WelcomePanel.py

    rf721030 r488c49d  
    1818        build = sas.sasview.__build__ 
    1919 
    20         self.lblVersion = "\nSasView %s\nBuild: %s" % (version, build) 
    21         self.lblVersion += "\n(c) 2009 - 2013, UTK, UMD, NIST, ORNL, ISIS, ESS and IL" 
     20        ver = "\nSasView %s\nBuild: %s" % (version, build) 
     21        ver += "\n(c) 2009 - 2013, UTK, UMD, NIST, ORNL, ISIS, ESS and IL" 
     22 
     23        self.lblVersion.setText(ver) 
  • src/sas/qtgui/run_tests.sh

    rf721030 r488c49d  
     1python -m UnitTesting.TestUtilsTest 
     2python -m UnitTesting.WelcomePanelTest 
    13python -m UnitTesting.DataExplorerTest 
    24python -m UnitTesting.MainWindowTest 
Note: See TracChangeset for help on using the changeset viewer.