Changeset 53c771e in sasview for src/sas/qtgui/MainWindow
- Timestamp:
- Nov 9, 2017 8:45:20 AM (7 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:
- dd150ef
- Parents:
- d6b8a1d
- git-author:
- Piotr Rozyczko <rozyczko@…> (11/08/17 09:22:45)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (11/09/17 08:45:20)
- Location:
- src/sas/qtgui/MainWindow
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/MainWindow/DataExplorer.py
rd6b8a1d r53c771e 287 287 delete_msg = "This operation will delete the checked data sets and all the dependents." +\ 288 288 "\nDo you want to continue?" 289 reply = Qt Gui.QMessageBox.question(self,289 reply = QtWidgets.QMessageBox.question(self, 290 290 'Warning', 291 291 delete_msg, 292 Qt Gui.QMessageBox.Yes,293 Qt Gui.QMessageBox.No)294 295 if reply == Qt Gui.QMessageBox.No:292 QtWidgets.QMessageBox.Yes, 293 QtWidgets.QMessageBox.No) 294 295 if reply == QtWidgets.QMessageBox.No: 296 296 return 297 297 … … 327 327 delete_msg = "This operation will delete the checked data sets and all the dependents." +\ 328 328 "\nDo you want to continue?" 329 reply = Qt Gui.QMessageBox.question(self,329 reply = QtWidgets.QMessageBox.question(self, 330 330 'Warning', 331 331 delete_msg, 332 Qt Gui.QMessageBox.Yes,333 Qt Gui.QMessageBox.No)334 335 if reply == Qt Gui.QMessageBox.No:332 QtWidgets.QMessageBox.Yes, 333 QtWidgets.QMessageBox.No) 334 335 if reply == QtWidgets.QMessageBox.No: 336 336 return 337 337 … … 373 373 if len(selected_items) > 1 and not self._perspective().allowBatch(): 374 374 msg = self._perspective().title() + " does not allow multiple data." 375 msgbox = Qt Gui.QMessageBox()376 msgbox.setIcon(Qt Gui.QMessageBox.Critical)375 msgbox = QtWidgets.QMessageBox() 376 msgbox.setIcon(QtWidgets.QMessageBox.Critical) 377 377 msgbox.setText(msg) 378 msgbox.setStandardButtons(Qt Gui.QMessageBox.Ok)378 msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok) 379 379 retval = msgbox.exec_() 380 380 return -
src/sas/qtgui/MainWindow/DroppableDataLoadWidget.py
r4992ff2 r53c771e 58 58 filenames=[] 59 59 for url in event.mimeData().urls(): 60 filenames.append( str(url.toLocalFile()))60 filenames.append(url.toLocalFile()) 61 61 self.communicator.fileReadSignal.emit(filenames) 62 62 event.accept() -
src/sas/qtgui/MainWindow/MainWindow.py
rd6b8a1d r53c771e 27 27 self.guiManager = GuiManager(self) 28 28 except Exception as ex: 29 print("EXCEPTION: ", ex) 29 import logging 30 logging.error("Application failed with: ", ex) 31 print("Application failed with: ", ex) 30 32 31 33 def closeEvent(self, event): -
src/sas/qtgui/MainWindow/UnitTesting/AboutBoxTest.py
r7fb471d r53c771e 3 3 import webbrowser 4 4 5 from PyQt 4 import QtGui6 from PyQt 4.QtTest import QTest7 from PyQt 4import QtCore5 from PyQt5 import QtGui, QtWidgets 6 from PyQt5.QtTest import QTest 7 from PyQt5 import QtCore 8 8 from unittest.mock import MagicMock 9 9 … … 15 15 import sas.qtgui.Utilities.LocalConfig as LocalConfig 16 16 17 if not Qt Gui.QApplication.instance():18 app = Qt Gui.QApplication(sys.argv)17 if not QtWidgets.QApplication.instance(): 18 app = QtWidgets.QApplication(sys.argv) 19 19 20 20 class AboutBoxTest(unittest.TestCase): … … 31 31 def testDefaults(self): 32 32 '''Test the GUI in its default state''' 33 self.assertIsInstance(self.widget, Qt Gui.QWidget)33 self.assertIsInstance(self.widget, QtWidgets.QWidget) 34 34 self.assertEqual(self.widget.windowTitle(), "About") 35 35 self.assertEqual(self.widget.cmdOK.text(), "OK") … … 45 45 """ 46 46 version = self.widget.lblVersion 47 self.assertIsInstance(version, Qt Gui.QLabel)47 self.assertIsInstance(version, QtWidgets.QLabel) 48 48 self.assertEqual(str(version.text()), str(LocalConfig.__version__)) 49 49 … … 53 53 """ 54 54 about = self.widget.lblAbout 55 self.assertIsInstance(about, Qt Gui.QLabel)55 self.assertIsInstance(about, QtWidgets.QLabel) 56 56 # build version 57 57 self.assertIn(str(LocalConfig.__build__), about.text()) … … 83 83 84 84 # Press the buttons 85 buttonList = self.widget.findChildren(Qt Gui.QPushButton)85 buttonList = self.widget.findChildren(QtWidgets.QPushButton) 86 86 for button in buttonList: 87 87 QTest.mouseClick(button, QtCore.Qt.LeftButton) -
src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py
r7fb471d r53c771e 2 2 import unittest 3 3 4 from PyQt4.QtGui import * 5 from PyQt4.QtTest import QTest 6 from PyQt4.QtCore import * 4 from PyQt5.QtGui import * 5 from PyQt5.QtWidgets import * 6 from PyQt5.QtTest import QTest 7 from PyQt5.QtCore import * 7 8 from unittest.mock import MagicMock 8 9 from unittest.mock import patch … … 36 37 return Communicate() 37 38 def allowBatch(self): 38 return False39 return True 39 40 def setData(self, data_item=None, is_batch=False): 40 41 return None … … 114 115 115 116 # Return no files. 116 Q tGui.QFileDialog.getOpenFileNames = MagicMock(return_value=None)117 QFileDialog.getOpenFileNames = MagicMock(return_value=('','')) 117 118 118 119 # Click on the Load button … … 120 121 121 122 # Test the getOpenFileName() dialog called once 122 self.assertTrue(Q tGui.QFileDialog.getOpenFileNames.called)123 Q tGui.QFileDialog.getOpenFileNames.assert_called_once()123 self.assertTrue(QFileDialog.getOpenFileNames.called) 124 QFileDialog.getOpenFileNames.assert_called_once() 124 125 125 126 # Make sure the signal has not been emitted … … 127 128 128 129 # Now, return a single file 129 Q tGui.QFileDialog.getOpenFileNames = MagicMock(return_value=filename)130 QFileDialog.getOpenFileNames = MagicMock(return_value=(filename,'')) 130 131 131 132 # Click on the Load button 132 133 QTest.mouseClick(loadButton, Qt.LeftButton) 133 QtGui.qApp.processEvents()134 qApp.processEvents() 134 135 135 136 # Test the getOpenFileName() dialog called once 136 self.assertTrue(Q tGui.QFileDialog.getOpenFileNames.called)137 Q tGui.QFileDialog.getOpenFileNames.assert_called_once()137 self.assertTrue(QFileDialog.getOpenFileNames.called) 138 QFileDialog.getOpenFileNames.assert_called_once() 138 139 139 140 # Expected one spy instance … … 167 168 168 169 # Mock the confirmation dialog with return=No 169 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.No)170 QMessageBox.question = MagicMock(return_value=QMessageBox.No) 170 171 171 172 # Populate the model … … 180 181 item2 = self.form.model.item(1) 181 182 item3 = self.form.model.item(2) 182 self.assertTrue(item1.checkState() == Qt Core.Qt.Checked)183 self.assertTrue(item2.checkState() == Qt Core.Qt.Checked)184 self.assertTrue(item3.checkState() == Qt Core.Qt.Checked)183 self.assertTrue(item1.checkState() == Qt.Checked) 184 self.assertTrue(item2.checkState() == Qt.Checked) 185 self.assertTrue(item3.checkState() == Qt.Checked) 185 186 186 187 # Click on the delete button … … 188 189 189 190 # Test the warning dialog called once 190 self.assertTrue(Q tGui.QMessageBox.question.called)191 self.assertTrue(QMessageBox.question.called) 191 192 192 193 # Assure the model still contains the items … … 194 195 195 196 # Now, mock the confirmation dialog with return=Yes 196 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)197 QMessageBox.question = MagicMock(return_value=QMessageBox.Yes) 197 198 198 199 # Click on the delete button … … 200 201 201 202 # Test the warning dialog called once 202 self.assertTrue(Q tGui.QMessageBox.question.called)203 self.assertTrue(QMessageBox.question.called) 203 204 204 205 # Assure the model contains no items … … 215 216 216 217 # Mock the confirmation dialog with return=No 217 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.No)218 QMessageBox.question = MagicMock(return_value=QMessageBox.No) 218 219 219 220 # Populate the model 220 item1 = Q tGui.QStandardItem(True)221 item1 = QStandardItem(True) 221 222 item1.setCheckable(True) 222 item1.setCheckState(Qt Core.Qt.Checked)223 item1.setCheckState(Qt.Checked) 223 224 item1.setText("item 1") 224 225 self.form.theory_model.appendRow(item1) 225 item2 = Q tGui.QStandardItem(True)226 item2 = QStandardItem(True) 226 227 item2.setCheckable(True) 227 item2.setCheckState(Qt Core.Qt.Unchecked)228 item2.setCheckState(Qt.Unchecked) 228 229 item2.setText("item 2") 229 230 self.form.theory_model.appendRow(item2) … … 233 234 234 235 # Assure the checkboxes are on 235 self.assertTrue(item1.checkState() == Qt Core.Qt.Checked)236 self.assertTrue(item2.checkState() == Qt Core.Qt.Unchecked)236 self.assertTrue(item1.checkState() == Qt.Checked) 237 self.assertTrue(item2.checkState() == Qt.Unchecked) 237 238 238 239 # Click on the delete button … … 240 241 241 242 # Test the warning dialog called once 242 self.assertTrue(Q tGui.QMessageBox.question.called)243 self.assertTrue(QMessageBox.question.called) 243 244 244 245 # Assure the model still contains the items … … 246 247 247 248 # Now, mock the confirmation dialog with return=Yes 248 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)249 QMessageBox.question = MagicMock(return_value=QMessageBox.Yes) 249 250 250 251 # Click on the delete button … … 252 253 253 254 # Test the warning dialog called once 254 self.assertTrue(Q tGui.QMessageBox.question.called)255 self.assertTrue(QMessageBox.question.called) 255 256 256 257 # Assure the model contains 1 item … … 258 259 259 260 # Set the remaining item to checked 260 self.form.theory_model.item(0).setCheckState(Qt Core.Qt.Checked)261 self.form.theory_model.item(0).setCheckState(Qt.Checked) 261 262 262 263 # Click on the delete button again … … 306 307 307 308 # Mock the warning message 308 Q tGui.QMessageBox = MagicMock()309 QMessageBox = MagicMock() 309 310 310 311 # Click on the button … … 312 313 313 314 # Assure the message box popped up 314 Q tGui.QMessageBox.assert_called_once()315 QMessageBox.assert_called_once() 315 316 316 317 def testDataSelection(self): … … 325 326 self.form.cbSelect.setCurrentIndex(1) 326 327 327 self.form.show()328 app.exec_()329 330 328 # Test the current selection 331 329 item1D = self.form.model.item(0) 332 330 item2D = self.form.model.item(1) 333 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)334 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)331 self.assertTrue(item1D.checkState() == Qt.Unchecked) 332 self.assertTrue(item2D.checkState() == Qt.Unchecked) 335 333 336 334 # Select all data … … 338 336 339 337 # Test the current selection 340 self.assertTrue(item1D.checkState() == Qt Core.Qt.Checked)341 self.assertTrue(item2D.checkState() == Qt Core.Qt.Checked)338 self.assertTrue(item1D.checkState() == Qt.Checked) 339 self.assertTrue(item2D.checkState() == Qt.Checked) 342 340 343 341 # select 1d data … … 345 343 346 344 # Test the current selection 347 self.assertTrue(item1D.checkState() == Qt Core.Qt.Checked)348 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)345 self.assertTrue(item1D.checkState() == Qt.Checked) 346 self.assertTrue(item2D.checkState() == Qt.Unchecked) 349 347 350 348 # unselect 1d data … … 352 350 353 351 # Test the current selection 354 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)355 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)352 self.assertTrue(item1D.checkState() == Qt.Unchecked) 353 self.assertTrue(item2D.checkState() == Qt.Unchecked) 356 354 357 355 # select 2d data … … 359 357 360 358 # Test the current selection 361 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)362 self.assertTrue(item2D.checkState() == Qt Core.Qt.Checked)359 self.assertTrue(item1D.checkState() == Qt.Unchecked) 360 self.assertTrue(item2D.checkState() == Qt.Checked) 363 361 364 362 # unselect 2d data … … 366 364 367 365 # Test the current selection 368 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)369 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)366 self.assertTrue(item1D.checkState() == Qt.Unchecked) 367 self.assertTrue(item2D.checkState() == Qt.Unchecked) 370 368 371 369 # choose impossible index and assure the code raises … … 385 383 """ 386 384 # Create an item with several branches 387 item1 = Q tGui.QStandardItem()388 item2 = Q tGui.QStandardItem()389 item3 = Q tGui.QStandardItem()390 item4 = Q tGui.QStandardItem()391 item5 = Q tGui.QStandardItem()392 item6 = Q tGui.QStandardItem()385 item1 = QStandardItem() 386 item2 = QStandardItem() 387 item3 = QStandardItem() 388 item4 = QStandardItem() 389 item5 = QStandardItem() 390 item6 = QStandardItem() 393 391 394 392 item4.appendRow(item5) … … 432 430 # The 0th item header should be the name of the file 433 431 model_item = self.form.model.index(0,0) 434 model_name = s tr(self.form.model.data(model_item).toString())432 model_name = self.form.model.data(model_item) 435 433 self.assertEqual(model_name, filename[0]) 436 434 … … 445 443 # Click on the Help button 446 444 QTest.mouseClick(button1, Qt.LeftButton) 447 QtGui.qApp.processEvents()445 qApp.processEvents() 448 446 449 447 # Check the browser … … 454 452 # Click on the Help_2 button 455 453 QTest.mouseClick(button2, Qt.LeftButton) 456 QtGui.qApp.processEvents()454 qApp.processEvents() 457 455 # Check the browser 458 456 self.assertIn(partial_url, str(self.form._helpView.url())) … … 596 594 p_file="cyl_400_20.txt" 597 595 output_object = loader.load(p_file) 598 output_item = Q tGui.QStandardItem()596 output_item = QStandardItem() 599 597 new_data = [(output_item, manager.create_gui_data(output_object[0], p_file))] 600 598 … … 644 642 Assure the model update is correct 645 643 """ 646 good_item = Q tGui.QStandardItem()644 good_item = QStandardItem() 647 645 bad_item = "I'm so bad" 648 646 … … 669 667 670 668 # Pick up the treeview index corresponding to that file 671 index = self.form.treeView.indexAt(Q tCore.QPoint(5,5))669 index = self.form.treeView.indexAt(QPoint(5,5)) 672 670 self.form.show() 673 671 -
src/sas/qtgui/MainWindow/UnitTesting/DroppableDataLoadWidgetTest.py
r464cd07 r53c771e 2 2 import unittest 3 3 4 from PyQt 4.QtGuiimport QApplication5 from PyQt 4.QtTest import QTest6 from PyQt 4import QtCore4 from PyQt5.QtWidgets import QApplication 5 from PyQt5.QtTest import QTest 6 from PyQt5 import QtCore 7 7 8 8 # set up import paths … … 62 62 63 63 drop_event = QtGui.QDropEvent(QtCore.QPoint(0,0), 64 65 66 67 64 QtCore.Qt.CopyAction, 65 self.mime_data, 66 QtCore.Qt.LeftButton, 67 QtCore.Qt.NoModifier) 68 68 69 69 self.form.dropEvent(drop_event) 70 Q tGui.qApp.processEvents()70 QApplication.processEvents() 71 71 self.assertEqual(spy_file_read.count(), 1) 72 72 self.assertIn(self.testfile, str(spy_file_read.signal(index=0))) -
src/sas/qtgui/MainWindow/UnitTesting/GuiManagerTest.py
r7fb471d r53c771e 5 5 import logging 6 6 7 from PyQt4.QtGui import * 8 from PyQt4.QtTest import QTest 9 from PyQt4.QtCore import * 10 from PyQt4.QtWebKit import * 7 from PyQt5.QtGui import * 8 from PyQt5.QtWidgets import * 9 from PyQt5.QtTest import QTest 10 from PyQt5.QtCore import * 11 from PyQt5.QtWebKit import * 11 12 from unittest.mock import MagicMock 12 13 … … 18 19 from sas.qtgui.MainWindow.AboutBox import AboutBox 19 20 from sas.qtgui.MainWindow.WelcomePanel import WelcomePanel 20 from sas.qtgui.Utilities.IPythonWidget import IPythonWidget21 #from sas.qtgui.Utilities.IPythonWidget import IPythonWidget 21 22 22 23 from sas.qtgui.MainWindow.GuiManager import Acknowledgements, GuiManager … … 37 38 38 39 # define workspace for dialogs. 39 self.workspace = Q Workspace(self)40 self.workspace = QMdiArea(self) 40 41 self.setCentralWidget(self.workspace) 41 42 … … 221 222 """ 222 223 # Mock the system file open method 223 QFileDialog.getOpenFileNames = MagicMock(return_value= None)224 QFileDialog.getOpenFileNames = MagicMock(return_value=('','')) 224 225 225 226 # invoke the action … … 234 235 """ 235 236 # Mock the system file open method 236 QFileDialog.getExistingDirectory = MagicMock(return_value= None)237 QFileDialog.getExistingDirectory = MagicMock(return_value=('','')) 237 238 238 239 # invoke the action … … 270 271 271 272 #### HELP #### 272 def testActionDocumentation(self): 273 # test when PyQt5 works with html 274 def notestActionDocumentation(self): 273 275 """ 274 276 Menu Help/Documentation -
src/sas/qtgui/MainWindow/UnitTesting/MainWindowTest.py
r7fb471d r53c771e 1 1 import sys 2 2 import unittest 3 import logging 3 4 4 from PyQt 4 import QtGui5 from PyQt 4import QtTest6 from PyQt 4import QtCore5 from PyQt5 import QtGui, QtWidgets 6 from PyQt5 import QtTest 7 from PyQt5 import QtCore 7 8 from unittest.mock import MagicMock 8 9 … … 13 14 from sas.qtgui.MainWindow.MainWindow import MainSasViewWindow 14 15 from sas.qtgui.MainWindow.MainWindow import SplashScreen 16 from sas.qtgui.MainWindow.GuiManager import GuiManager 15 17 16 if not Qt Gui.QApplication.instance():17 app = Qt Gui.QApplication(sys.argv)18 if not QtWidgets.QApplication.instance(): 19 app = QtWidgets.QApplication(sys.argv) 18 20 19 21 class MainWindowTest(unittest.TestCase): … … 30 32 def testDefaults(self): 31 33 """Test the GUI in its default state""" 32 self.assertIsInstance(self.widget, Qt Gui.QMainWindow)33 self.assertIsInstance(self.widget.centralWidget(), Qt Gui.QWorkspace)34 self.assertIsInstance(self.widget, QtWidgets.QMainWindow) 35 self.assertIsInstance(self.widget.centralWidget(), QtWidgets.QMdiArea) 34 36 35 37 def testSplashScreen(self): 36 38 """ Test the splash screen """ 37 39 splash = SplashScreen() 38 self.assertIsInstance(splash, Qt Gui.QSplashScreen)40 self.assertIsInstance(splash, QtWidgets.QSplashScreen) 39 41 40 42 def testExit(self): … … 44 46 # Must mask sys.exit, otherwise the whole testing process stops. 45 47 sys.exit = MagicMock() 46 Qt Gui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)48 QtWidgets.QMessageBox.question = MagicMock(return_value=QtWidgets.QMessageBox.Yes) 47 49 48 50 # Open, then close the main window … … 51 53 52 54 # See that the MessageBox method got called 53 self.assertTrue(Qt Gui.QMessageBox.question.called)55 self.assertTrue(QtWidgets.QMessageBox.question.called) 54 56 55 57 if __name__ == "__main__": -
src/sas/qtgui/MainWindow/UnitTesting/WelcomePanelTest.py
r464cd07 r53c771e 2 2 import unittest 3 3 4 from PyQt 4 import QtGui4 from PyQt5 import QtGui, QtWidgets 5 5 6 6 # set up import paths … … 10 10 from sas.qtgui.MainWindow.WelcomePanel import WelcomePanel 11 11 12 if not Qt Gui.QApplication.instance():13 app = Qt Gui.QApplication(sys.argv)12 if not QtWidgets.QApplication.instance(): 13 app = QtWidgets.QApplication(sys.argv) 14 14 15 15 class WelcomePanelTest(unittest.TestCase): … … 27 27 def testDefaults(self): 28 28 '''Test the GUI in its default state''' 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertEqual(self.widget.windowTitle(), "Welcome") 31 31 … … 33 33 '''Test the version string''' 34 34 version = self.widget.lblVersion 35 self.assertIsInstance(version, Qt Gui.QLabel)35 self.assertIsInstance(version, QtWidgets.QLabel) 36 36 37 37 self.assertIn("SasView", version.text())
Note: See TracChangeset
for help on using the changeset viewer.