Changeset d9150d8 in sasview for src/sas/qtgui/MainWindow
- Timestamp:
- Jul 10, 2018 6:03:11 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 4dd5766
- Parents:
- 515c23df
- git-author:
- Piotr Rozyczko <rozyczko@…> (07/10/18 05:57:36)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (07/10/18 06:03:11)
- Location:
- src/sas/qtgui/MainWindow
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/MainWindow/DataExplorer.py
r515c23df rd9150d8 56 56 self.mutex = QtCore.QMutex() 57 57 58 # Active plots 58 # Plot widgets {name:widget}, required to keep track of plots shown as MDI subwindows 59 self.plot_widgets = {} 60 61 # Active plots {id:Plotter1D/2D}, required to keep track of currently displayed plots 59 62 self.active_plots = {} 60 63 … … 554 557 if not 'new_plot' in locals(): 555 558 new_plot = Plotter(self) 559 new_plot.item = item 556 560 new_plot.plot(plot_set) 557 561 # active_plots may contain multiple charts … … 592 596 593 597 # Add the plot to the workspace 594 self.parent.workspace().addSubWindow(new_plot)598 plot_widget = self.parent.workspace().addSubWindow(new_plot) 595 599 596 600 # Show the plot 597 601 new_plot.show() 598 602 new_plot.canvas.draw() 603 604 # Update the plot widgets dict 605 self.plot_widgets[title]=plot_widget 599 606 600 607 # Update the active chart list … … 1026 1033 return 1027 1034 1028 proxy = self.current_view.model()1029 model = proxy.sourceModel()1030 1031 deleted_items = []1032 deleted_names = []1033 1034 1035 # Every time a row is removed, the indices change, so we'll just remove 1035 1036 # rows and keep calling selectedIndexes until it returns an empty list. 1036 1037 indices = self.current_view.selectedIndexes() 1038 1039 proxy = self.current_view.model() 1040 model = proxy.sourceModel() 1041 1042 deleted_items = [] 1043 deleted_names = [] 1037 1044 1038 1045 while len(indices) > 0: … … 1046 1053 deleted_names.append(item_to_delete.text()) 1047 1054 deleted_items.append(item_to_delete) 1055 1056 # Delete corresponding open plots 1057 self.closePlotsForItem(item_to_delete) 1048 1058 1049 1059 if item_to_delete.parent(): … … 1060 1070 # update stored_data 1061 1071 self.manager.update_stored_data(deleted_names) 1072 1073 def closePlotsForItem(self, item): 1074 """ 1075 Given standard item, close all its currently displayed plots 1076 """ 1077 # item - HashableStandardItems of active plots 1078 1079 # {} -> 'Graph1' : HashableStandardItem() 1080 current_plot_items = {} 1081 for plot_name in PlotHelper.currentPlots(): 1082 current_plot_items[plot_name] = PlotHelper.plotById(plot_name).item 1083 1084 # item and its hashable children 1085 items_being_deleted = [] 1086 if item.rowCount() > 0: 1087 items_being_deleted = [item.child(n) for n in range(item.rowCount()) 1088 if isinstance(item.child(n), GuiUtils.HashableStandardItem)] 1089 items_being_deleted.append(item) 1090 # Add the parent in case a child is selected 1091 if isinstance(item.parent(), GuiUtils.HashableStandardItem): 1092 items_being_deleted.append(item.parent()) 1093 1094 # Compare plot items and items to delete 1095 plots_to_close = set(current_plot_items.values()) & set(items_being_deleted) 1096 1097 for plot_item in plots_to_close: 1098 for plot_name in current_plot_items.keys(): 1099 if plot_item == current_plot_items[plot_name]: 1100 plotter = PlotHelper.plotById(plot_name) 1101 # try to delete the plot 1102 try: 1103 plotter.close() 1104 #self.parent.workspace().removeSubWindow(plotter) 1105 self.plot_widgets[plot_name].close() 1106 self.plot_widgets.pop(plot_name, None) 1107 except AttributeError as ex: 1108 logging.error("Closing of %s failed:\n %s" % (plot_name, str(ex))) 1109 1110 pass # debugger anchor 1062 1111 1063 1112 def onAnalysisUpdate(self, new_perspective=""): … … 1174 1223 self.theory_model.appendRow(model_item) 1175 1224 1176 1177 if __name__ == "__main__":1178 app = QtWidgets.QApplication([])1179 dlg = DataExplorerWindow()1180 dlg.show()1181 sys.exit(app.exec_()) -
src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py
r80468f6 rd9150d8 67 67 # Buttons - data tab 68 68 self.assertEqual(self.form.cmdLoad.text(), "Load data") 69 self.assertEqual(self.form.cmdDeleteData.text(), "Delete ")69 self.assertEqual(self.form.cmdDeleteData.text(), "Delete Data") 70 70 self.assertEqual(self.form.cmdDeleteTheory.text(), "Delete") 71 71 self.assertEqual(self.form.cmdFreeze.text(), "Freeze Theory") … … 819 819 pass 820 820 821 def notestDeleteItem(self):821 def testDeleteItem(self): 822 822 """ 823 823 Delete selected item from data explorer … … 876 876 self.assertEqual(self.form.model.rowCount(), 3) 877 877 878 def testClosePlotsForItem(self): 879 """ 880 Delete selected item from data explorer should also delete corresponding plots 881 """ 882 # Mock the confirmation dialog with return=No 883 QMessageBox.question = MagicMock(return_value=QMessageBox.No) 884 885 loader = Loader() 886 manager = DataManager() 887 PlotHelper.clear() 888 self.form.enableGraphCombo(None) 889 890 # Make sure the controls are disabled 891 self.assertFalse(self.form.cbgraph.isEnabled()) 892 self.assertFalse(self.form.cmdAppend.isEnabled()) 893 894 # Populate the model 895 filename = ["cyl_400_20.txt"] 896 self.form.readData(filename) 897 898 # Mask plotting 899 self.form.parent.workspace = MagicMock() 900 901 # Call the plotting method 902 self.form.newPlot() 903 904 time.sleep(1) 905 QApplication.processEvents() 906 907 # The plot was registered 908 self.assertEqual(len(PlotHelper.currentPlots()), 1) 909 self.assertEqual(len(self.form.plot_widgets), 1) 910 self.assertEqual(list(self.form.plot_widgets.keys()), ['Graph3']) 911 912 # data index 913 model_item = self.form.model.item(0,0) 914 915 # Call the method 916 self.form.closePlotsForItem(model_item) 917 918 # See that no plot remained 919 self.assertEqual(len(PlotHelper.currentPlots()), 0) 920 self.assertEqual(len(self.form.plot_widgets), 0) 921 878 922 879 923 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.