Changeset a281ab8 in sasview
- Timestamp:
- Jun 15, 2016 5:57:34 AM (9 years ago)
- 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
- Location:
- src/sas/qtgui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/DataExplorer.py
r5032ea68 ra281ab8 16 16 # UI 17 17 from 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()] 18 21 19 22 class DataExplorerWindow(DataLoadWidget): … … 150 153 retval = msgbox.exec_() 151 154 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 154 158 155 159 # TODO … … 157 161 158 162 # Notify the GuiManager about the send request 159 self._perspective.setData(data_ list=data)163 self._perspective.setData(data_item=data) 160 164 161 165 … … 272 276 message = "Loading Data Complete! " 273 277 message += log_msg 274 return (output, message)278 return output, message 275 279 276 280 def getWlist(self): … … 375 379 376 380 377 def loadComplete(self, output , message=""):381 def loadComplete(self, output): 378 382 """ 379 383 Post message to status bar and update the data manager 380 384 """ 381 385 self.model.reset() 386 assert(type(output), tuple) 387 388 output_data = output[0] 389 message = output[1] 382 390 # Notify the manager of the new data available 383 391 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) 386 394 387 395 def updateModel(self, data, p_file): … … 429 437 def updateModelFromPerspective(self, model_item): 430 438 """ 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 433 443 if type(model_item) != QtGui.QStandardItem: 434 444 msg = "Wrong data type returned from calculations." 435 445 raise AttributeError, msg 446 # Assert other properties 447 448 # Remove the original item 449 450 # Add the current item 436 451 # self.model.insertRow(model_item) 452 437 453 # Reset the view 438 454 self.model.reset() -
src/sas/qtgui/GuiUtils.py
r5032ea68 ra281ab8 205 205 206 206 # New data in current perspective 207 updateModelFromPerspectiveSignal = QtCore.pyqtSignal(Data1D) 207 updateModelFromPerspectiveSignal = QtCore.pyqtSignal(QtGui.QStandardItem) 208 209 def 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 12 12 from sas.sasgui.guiframe.dataFitting import Data1D 13 13 from sas.qtgui.GuiUtils import Communicate 14 from sas.qtgui.GuiUtils import updateModelItem 14 15 15 16 # local … … 35 36 self._model.appendRow(item) 36 37 37 # class InvariantWindow(InvariantUI):38 38 class InvariantWindow(tabbedInvariantUI): 39 39 # The controller which is responsible for managing signal slots connections … … 53 53 self._manager = manager 54 54 self._reactor = self._manager.reactor() 55 self._model_item = QtGui.QStandardItem() 55 56 56 57 self._helpView = QtWebKit.QWebView() … … 119 120 self._high_power_value = float(self.model.item(WIDGETS.W_HIGHQ_POWER_VALUE).text()) 120 121 121 def calculate (self):122 def calculateInvariant(self): 122 123 """ 123 124 Use twisted to thread the calculations away. … … 151 152 """ 152 153 """ 153 self._plotter.show() 154 if self._low_extrapolate or self._high_extrapolate: 155 self._plotter.show() 154 156 self.model = model 155 157 self.mapper.toFirst() … … 160 162 self.pushButton.setStyleSheet(self.style) 161 163 162 # Send the new datato DE for keeping in the model163 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) 164 166 165 167 … … 255 257 256 258 # Plot the chart 259 title = "Low-Q extrapolation" 257 260 self._plotter.data(extrapolated_data) 258 self._plotter.title( "Low-Q extrapolation")261 self._plotter.title(title) 259 262 self._plotter.plot() 260 263 264 # Add the plot to the model item 265 variant_item = QtCore.QVariant(self._plotter) 266 updateModelItem(self._model_item, variant_item, title) 261 267 262 268 if self._high_extrapolate: … … 271 277 # find how to add this plot to the existing plot for low_extrapolate 272 278 # Plot the chart 279 title = "High-Q extrapolation" 273 280 self._plotter.data(high_out_data) 274 self._plotter.title( "High-Q extrapolation")281 self._plotter.title(title) 275 282 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) 276 287 277 288 … … 326 337 327 338 def setupSlots(self): 328 self.pushButton.clicked.connect(self.calculate )339 self.pushButton.clicked.connect(self.calculateInvariant) 329 340 self.pushButton_2.clicked.connect(self.status) 330 341 self.pushButton_3.clicked.connect(self.help) … … 489 500 self.mapper.toFirst() 490 501 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): 492 523 """ 493 524 receive a list of data and compute invariant 525 526 TODO: pass warnings/messages to log 494 527 """ 495 528 msg = "" … … 520 553 #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error')) 521 554 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" 524 559 #if len(data_list) > 1: 525 560 #from invariant_widgets import DataDialog … … 545 580 self._data = data 546 581 self._path = "unique path" 547 self.calculate ()582 self.calculateInvariant() 548 583 except: 549 584 msg = "Invariant Set_data: " + str(sys.exc_value) -
src/sas/qtgui/UnitTesting/DataExplorerTest.py
r5032ea68 ra281ab8 1 1 import sys 2 2 import unittest 3 #from twisted.trial import unittest4 #from twisted.internet import reactor, defer, interfaces, threads, protocol, error5 3 6 4 from PyQt4.QtGui import * … … 27 25 def allowBatch(self): 28 26 return False 29 def setData(self, data_ list=None):27 def setData(self, data_item=None): 30 28 return None 31 29 def title(self): … … 271 269 """ 272 270 271 message="Loading Data Complete" 273 272 data_dict = {"a1":Data1D()} 273 output_data = (data_dict, message) 274 274 275 275 self.form.manager.add_data = MagicMock() … … 280 280 281 281 # Read in the file 282 self.form.loadComplete( data_dict, message="Loading Data Complete")282 self.form.loadComplete(output_data) 283 283 284 284 # "Loading data complete" no longer sent in LoadFile but in callback -
src/sas/qtgui/UnitTesting/GuiUtilsTest.py
rf721030 ra281ab8 1 import sys 2 import unittest 3 4 # Tested module 5 from GuiUtils import * 6 7 class 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 78 if __name__ == "__main__": 79 unittest.main() 80 -
src/sas/qtgui/run_tests.sh
r5032ea68 ra281ab8 1 #python -m UnitTesting.TestUtilsTest2 #python -m UnitTesting.WelcomePanelTest1 python -m UnitTesting.TestUtilsTest 2 python -m UnitTesting.WelcomePanelTest 3 3 python -m UnitTesting.DataExplorerTest 4 # python -m UnitTesting.GuiManagerTest 5 # python -m UnitTesting.MainWindowTest 4 python -m UnitTesting.GuiManagerTest 5 python -m UnitTesting.MainWindowTest 6 python -m UnitTesting.GuiUtilsTest 6 7
Note: See TracChangeset
for help on using the changeset viewer.