- Timestamp:
- Jul 12, 2016 8:44:53 AM (8 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:
- e3ae090
- Parents:
- a95260d
- Location:
- src/sas/qtgui
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/DataExplorer.py
r0cd8612 r8cb6cd6 13 13 14 14 # SAS 15 import GuiUtils16 from Plotter import Plotter17 15 from sas.sascalc.dataloader.loader import Loader 18 16 from sas.sasgui.guiframe.data_manager import DataManager … … 20 18 from sas.sasgui.guiframe.dataFitting import Data2D 21 19 20 import GuiUtils 21 import PlotHelper 22 from Plotter import Plotter 22 23 from DroppableDataLoadWidget import DroppableDataLoadWidget 23 24 … … 46 47 # Be careful with twisted threads. 47 48 self.mutex = QMutex() 49 50 # Active plots 51 self.active_plots = [] 48 52 49 53 # Connect the buttons … … 54 58 self.cmdSendTo.clicked.connect(self.sendData) 55 59 self.cmdNew.clicked.connect(self.newPlot) 60 self.cmdAppend.clicked.connect(self.appendPlot) 56 61 self.cmdHelp.clicked.connect(self.displayHelp) 57 62 self.cmdHelp_2.clicked.connect(self.displayHelp) … … 76 81 self.communicator = self.parent.communicator() 77 82 self.communicator.fileReadSignal.connect(self.loadFromURL) 83 self.communicator.activeGraphsSignal.connect(self.updateGraphCombo) 84 self.cbgraph.editTextChanged.connect(self.enableGraphCombo) 85 self.cbgraph.currentIndexChanged.connect(self.enableGraphCombo) 78 86 79 87 # Proxy model for showing a subset of Data1D/Data2D content … … 97 105 self.freezeView.setModel(self.theory_proxy) 98 106 107 self.enableGraphCombo(None) 108 99 109 def closeEvent(self, event): 100 110 """ … … 110 120 self._helpView.load(QtCore.QUrl(_TreeLocation)) 111 121 self._helpView.show() 122 123 def enableGraphCombo(self, combo_text): 124 """ 125 Enables/disables "Assign Plot" elements 126 """ 127 self.cbgraph.setEnabled(len(PlotHelper.currentPlots()) > 0) 128 self.cmdAppend.setEnabled(len(PlotHelper.currentPlots()) > 0) 112 129 113 130 def loadFromURL(self, url): … … 187 204 delete_msg = "This operation will delete the checked data sets and all the dependents." +\ 188 205 "\nDo you want to continue?" 189 reply = QtGui.QMessageBox.question(self, 'Warning', delete_msg, 190 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) 206 reply = QtGui.QMessageBox.question(self, 207 'Warning', 208 delete_msg, 209 QtGui.QMessageBox.Yes, 210 QtGui.QMessageBox.No) 191 211 192 212 if reply == QtGui.QMessageBox.No: … … 263 283 if not outer_item: 264 284 continue 265 for inner_index in xrange(outer_item.rowCount()): # Should be just two rows: data and Info 285 # Should be just two rows: data and Info 286 for inner_index in xrange(outer_item.rowCount()): 266 287 subitem = outer_item.child(inner_index) 267 if subitem and subitem.isCheckable() and subitem.checkState() == QtCore.Qt.Checked: 288 if subitem and \ 289 subitem.isCheckable() and \ 290 subitem.checkState() == QtCore.Qt.Checked: 268 291 theories_copied += 1 269 292 new_item = self.recursivelyCloneItem(subitem) 270 293 # Append a "unique" descriptor to the name 271 time_bit = str(time.time())[7:-1].replace('.', '')294 time_bit = str(time.time())[7:-1].replace('.', '') 272 295 new_name = new_item.text() + '_@' + time_bit 273 296 new_item.setText(new_name) … … 300 323 return new_item 301 324 325 def updateGraphCombo(self, graph_list): 326 """ 327 Modify Graph combo box on graph add/delete 328 """ 329 orig_text = self.cbgraph.currentText() 330 self.cbgraph.clear() 331 graph_titles = [] 332 for graph in graph_list: 333 graph_titles.append("Graph"+str(graph)) 334 self.cbgraph.insertItems(0, graph_titles) 335 ind = self.cbgraph.findText(orig_text) 336 if ind > 0: 337 self.cbgraph.setCurrentIndex(ind) 338 pass 339 302 340 def newPlot(self): 303 341 """ … … 306 344 TODO: Add 2D-functionality 307 345 """ 308 309 346 plots = GuiUtils.plotsFromCheckedItems(self.model) 310 347 311 348 # Call show on requested plots 312 new_plot = Plotter( )349 new_plot = Plotter(self) 313 350 for plot_set in plots: 314 351 new_plot.data(plot_set) 315 352 new_plot.plot() 316 353 354 # Update the global plot counter 355 title = "Graph"+str(PlotHelper.idOfPlot(new_plot)) 356 new_plot.setWindowTitle(title) 357 358 # Add the plot to the workspace 359 self.parent.workspace().addWindow(new_plot) 360 361 # Show the plot 317 362 new_plot.show() 363 364 # Update the active chart list 365 self.active_plots.append(title) 366 367 def appendPlot(self): 368 """ 369 Add data set(s) to the existing matplotlib chart 370 371 TODO: Add 2D-functionality 372 """ 373 # new plot data 374 new_plots = GuiUtils.plotsFromCheckedItems(self.model) 375 376 # old plot data 377 plot_id = self.cbgraph.currentText() 378 plot_id = int(plot_id[5:]) 379 380 assert plot_id in PlotHelper.currentPlots(), "No such plot: Graph%s"%str(plot_id) 381 382 old_plot = PlotHelper.plotById(plot_id) 383 384 # Add new data to the old plot 385 for plot_set in new_plots: 386 old_plot.data(plot_set) 387 old_plot.plot() 318 388 319 389 def chooseFiles(self): … … 424 494 else: 425 495 error_message += "%s\n" % str(p_file) 426 info = "error"427 496 428 497 current_percentage = int(100.0* index/number_of_files) … … 563 632 Post message to status bar and update the data manager 564 633 """ 565 assert type(output) == tuple634 assert isinstance(output, tuple) 566 635 567 636 # Reset the model so the view gets updated. -
src/sas/qtgui/GuiManager.py
r0cd8612 r8cb6cd6 63 63 64 64 # Fork off logging messages to the Log Window 65 XStream.stdout().messageWritten.connect( self.listWidget.insertPlainText)66 XStream.stderr().messageWritten.connect( self.listWidget.insertPlainText)65 XStream.stdout().messageWritten.connect(self.listWidget.insertPlainText) 66 XStream.stderr().messageWritten.connect(self.listWidget.insertPlainText) 67 67 68 68 # Log the start of the session … … 138 138 self.statusLabel = QtGui.QLabel() 139 139 self.statusLabel.setText("Welcome to SasView") 140 self._workspace.statusbar.addPermanentWidget(self.statusLabel, 1)140 self._workspace.statusbar.addPermanentWidget(self.statusLabel, 1) 141 141 self._workspace.statusbar.addPermanentWidget(self.progress, stretch=0) 142 self.progress.setRange(0, 100)142 self.progress.setRange(0, 100) 143 143 self.progress.setValue(0) 144 144 self.progress.setTextVisible(True) … … 150 150 """ 151 151 pass 152 153 def workspace(self): 154 """ 155 Accessor for the main window workspace 156 """ 157 return self._workspace.workspace 152 158 153 159 def updatePerspective(self, data): … … 186 192 Update progress bar with the required value (0-100) 187 193 """ 188 assert (-1 <= value <= 100)194 assert -1 <= value <= 100 189 195 if value == -1: 190 196 self.progress.setVisible(False) … … 253 259 % (content)) 254 260 version_info = json.loads(content) 255 except :256 logging.info("Failed to connect to www.sasview.org ")261 except ValueError, ex: 262 logging.info("Failed to connect to www.sasview.org:", ex) 257 263 self.processVersion(version_info) 258 264 -
src/sas/qtgui/GuiUtils.py
re540cd2 r8cb6cd6 217 217 progressBarUpdateSignal = QtCore.pyqtSignal(int) 218 218 219 # Workspace charts added/removed 220 activeGraphsSignal = QtCore.pyqtSignal(list) 221 219 222 220 223 def updateModelItem(item, update_data, name=""): -
src/sas/qtgui/Perspectives/Invariant/InvariantPerspective.py
ra95260d r8cb6cd6 58 58 self._helpView = QtWebKit.QWebView() 59 59 self.detailsDialog = DetailsDialog(self) 60 self._plotter = Plotter(self)60 # self._plotter = Plotter(self) 61 61 62 62 self._low_extrapolate = False … … 159 159 """ 160 160 """ 161 self._plotter = Plotter(self) 161 162 if self._low_extrapolate or self._high_extrapolate: 162 163 self._plotter.show() -
src/sas/qtgui/Plotter.py
ra95260d r8cb6cd6 1 import logging 2 1 3 from PyQt4 import QtGui 2 4 … … 9 11 import matplotlib.pyplot as plt 10 12 13 import PlotHelper 14 11 15 class Plotter(QtGui.QDialog): 12 16 def __init__(self, parent=None): 13 17 super(Plotter, self).__init__(parent) 18 19 # Required for the communicator 20 self.parent = parent 14 21 15 22 # a figure instance to plot on … … 39 46 self._ax = self.figure.add_subplot(self._current_plot) 40 47 48 # Notify the helper 49 PlotHelper.addPlot(self) 50 # Notify the listeners 51 self.parent.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots()) 41 52 42 53 def data(self, data=None): 43 """ 44 """ 54 """ data setter """ 45 55 self._data = data 46 56 47 57 def title(self, title=""): 48 """ 49 """ 58 """ title setter """ 50 59 self._title = title 51 60 52 61 def id(self, id=""): 53 """ 54 """ 62 """ id setter """ 55 63 self._id = id 56 64 57 65 def x_label(self, xlabel=""): 58 """ 59 """ 66 """ x-label setter """ 60 67 self._xlabel = xlabel 61 68 62 69 def y_label(self, ylabel=""): 63 """ 64 """ 70 """ y-label setter """ 65 71 self._ylabel = ylabel 66 72 67 73 def clean(self): 68 74 """ 75 Redraw the graph 69 76 """ 70 77 self.figure.delaxes(self._ax) … … 73 80 def plot(self): 74 81 """ 75 plot self._data82 Plot self._data 76 83 """ 77 84 # create an axis … … 92 99 # refresh canvas 93 100 self.canvas.draw() 101 102 def closeEvent(self, event): 103 """ 104 Overwrite the close event adding helper notification 105 """ 106 # Please remove me from your database. 107 PlotHelper.deletePlot(PlotHelper.idOfPlot(self)) 108 # Notify the listeners 109 self.parent.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots()) 110 event.accept() 111 -
src/sas/qtgui/UI/DataExplorerUI.py
re540cd2 r8cb6cd6 131 131 self.cbgraph.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) 132 132 self.cbgraph.setObjectName(_fromUtf8("cbgraph")) 133 self.cbgraph.addItem(_fromUtf8(""))134 133 self.gridLayout_3.addWidget(self.cbgraph, 1, 1, 1, 1) 135 134 self.gridLayout_2.addWidget(self.groupBox_3, 0, 0, 1, 1) … … 227 226 self.cmdNew.setText(_translate("DataLoadWidget", "Create New", None)) 228 227 self.cmdAppend.setText(_translate("DataLoadWidget", "Append to", None)) 229 self.cbgraph.setItemText(0, _translate("DataLoadWidget", "Graph1", None))230 228 self.cmdHelp.setText(_translate("DataLoadWidget", "Help", None)) 231 229 DataLoadWidget.setTabText(DataLoadWidget.indexOf(self.dataTab), _translate("DataLoadWidget", "Data", None)) -
src/sas/qtgui/UI/DataExplorerUI.ui
re540cd2 r8cb6cd6 252 252 <enum>QComboBox::AdjustToContents</enum> 253 253 </property> 254 <item>255 <property name="text">256 <string>Graph1</string>257 </property>258 </item>259 254 </widget> 260 255 </item> -
src/sas/qtgui/UnitTesting/DataExplorerTest.py
r0cd8612 r8cb6cd6 17 17 from UnitTesting.TestUtils import QtSignalSpy 18 18 from Plotter import Plotter 19 import PlotHelper 19 20 20 21 app = QApplication(sys.argv) … … 39 40 def perspective(self): 40 41 return MyPerspective() 42 def workspace(self): 43 return None 41 44 42 45 self.form = DataExplorerWindow(None, dummy_manager()) … … 505 508 loader = Loader() 506 509 manager = DataManager() 510 PlotHelper.clear() 511 self.form.enableGraphCombo(None) 512 513 # Make sure the controls are disabled 514 self.assertFalse(self.form.cbgraph.isEnabled()) 515 self.assertFalse(self.form.cmdAppend.isEnabled()) 507 516 508 517 # get Data1D … … 517 526 self.form.plotsFromCheckedItems = MagicMock(return_value=new_data) 518 527 528 # Mask plotting 529 self.form.parent.workspace = MagicMock() 530 519 531 # Call the plotting method 520 532 self.form.newPlot() … … 522 534 # The plot was displayed 523 535 self.assertTrue(Plotter.show.called) 536 537 # The plot was registered 538 self.assertEqual(len(PlotHelper.currentPlots()), 1) 539 540 self.assertTrue(self.form.cbgraph.isEnabled()) 541 self.assertTrue(self.form.cmdAppend.isEnabled()) 542 543 def testAppendPlot(self): 544 """ 545 Creating new plots from Data1D/2D 546 """ 547 loader = Loader() 548 manager = DataManager() 549 550 PlotHelper.clear() 551 self.form.enableGraphCombo(None) 552 553 # Make sure the controls are disabled 554 self.assertFalse(self.form.cbgraph.isEnabled()) 555 self.assertFalse(self.form.cmdAppend.isEnabled()) 556 557 # get Data1D 558 p_file="cyl_400_20.txt" 559 output_object = loader.load(p_file) 560 new_data = [manager.create_gui_data(output_object, p_file)] 561 562 # Mask plotting 563 self.form.parent.workspace = MagicMock() 564 565 # Mask the plot show call 566 Plotter.show = MagicMock() 567 568 # Mask retrieval of the data 569 self.form.plotsFromCheckedItems = MagicMock(return_value=new_data) 570 571 # Call the plotting method 572 self.form.newPlot() 573 574 # Call the plotting method again, so we have 2 graphs 575 self.form.newPlot() 576 577 # See that we have two plots 578 self.assertEqual(len(PlotHelper.currentPlots()), 2) 579 580 # Add data to plot #1 581 self.form.cbgraph.setCurrentIndex(1) 582 self.form.appendPlot() 583 584 # See that we still have two plots 585 self.assertEqual(len(PlotHelper.currentPlots()), 2) 586 587 def testUpdateGraphCombo(self): 588 """ 589 Test the combo box update 590 """ 591 PlotHelper.clear() 592 593 graph_list=[1,2,3] 594 self.form.updateGraphCombo(graph_list) 595 596 self.assertEqual(self.form.cbgraph.count(), 3) 597 self.assertEqual(self.form.cbgraph.currentText(), 'Graph1') 598 599 graph_list=[] 600 self.form.updateGraphCombo(graph_list) 601 self.assertEqual(self.form.cbgraph.count(), 0) 524 602 525 603 def testUpdateModelFromPerspective(self): -
src/sas/qtgui/run_tests.sh
r0cd8612 r8cb6cd6 8 8 python -m UnitTesting.DroppableDataLoadWidgetTest 9 9 python -m UnitTesting.SasviewLoggerTest 10 python -m UnitTesting.PlotHelperTest
Note: See TracChangeset
for help on using the changeset viewer.