Changeset c4e5400 in sasview
- Timestamp:
- Dec 12, 2016 3:21:03 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:
- 27313b7
- Parents:
- 3b7b218
- Location:
- src/sas/qtgui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Plotter.py
r3b7b218 rc4e5400 73 73 self.canvas.draw() 74 74 75 def contextMenu(self): 76 """ 77 Define common context menu and associated actions for the MPL widget 78 """ 79 self.defaultContextMenu() 80 81 75 82 def contextMenuQuickPlot(self): 76 83 """ 77 84 Define context menu and associated actions for the quickplot MPL widget 78 85 """ 79 # Actions 80 self.contextMenu = QtGui.QMenu(self) 81 self.actionSaveImage = self.contextMenu.addAction("Save Image") 82 self.actionPrintImage = self.contextMenu.addAction("Print Image") 83 self.actionCopyToClipboard = self.contextMenu.addAction("Copy to Clipboard") 84 self.contextMenu.addSeparator() 86 # Default actions 87 self.defaultContextMenu() 88 89 # Additional actions 85 90 self.actionToggleGrid = self.contextMenu.addAction("Toggle Grid On/Off") 86 91 self.contextMenu.addSeparator() … … 88 93 89 94 # Define the callbacks 90 self.actionSaveImage.triggered.connect(self.onImageSave)91 self.actionPrintImage.triggered.connect(self.onImagePrint)92 self.actionCopyToClipboard.triggered.connect(self.onClipboardCopy)93 95 self.actionToggleGrid.triggered.connect(self.onGridToggle) 94 96 self.actionChangeScale.triggered.connect(self.onScaleChange) -
src/sas/qtgui/Plotter2D.py
rfecfe28 rc4e5400 78 78 zmax=zmax_2D_temp) 79 79 80 def contextMenu(self): 81 """ 82 Define common context menu and associated actions for the MPL widget 83 """ 84 self.defaultContextMenu() 85 80 86 def contextMenuQuickPlot(self): 81 87 """ 82 88 Define context menu and associated actions for the quickplot MPL widget 83 89 """ 84 # Actions 85 self.contextMenu = QtGui.QMenu(self) 86 self.actionSaveImage = self.contextMenu.addAction("Save Image") 87 self.actionPrintImage = self.contextMenu.addAction("Print Image") 88 self.actionCopyToClipboard = self.contextMenu.addAction("Copy to Clipboard") 89 self.contextMenu.addSeparator() 90 self.defaultContextMenu() 91 90 92 if self.dimension == 2: 91 93 self.actionToggleGrid = self.contextMenu.addAction("Toggle Grid On/Off") … … 94 96 95 97 # Define the callbacks 96 self.actionSaveImage.triggered.connect(self.onImageSave) 97 self.actionPrintImage.triggered.connect(self.onImagePrint) 98 self.actionCopyToClipboard.triggered.connect(self.onClipboardCopy) 98 self.actionChangeScale.triggered.connect(self.onToggleScale) 99 99 if self.dimension == 2: 100 100 self.actionToggleGrid.triggered.connect(self.onGridToggle) 101 self.actionChangeScale.triggered.connect(self.onToggleScale)102 101 103 102 def onToggleScale(self, event): -
src/sas/qtgui/PlotterBase.py
r3b7b218 rc4e5400 145 145 self.manager.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots()) 146 146 147 def contextMenu(self):148 """ 149 Define common context menu and associated actions for the MPL widget150 TODO: move to plotter1d/plotter2d147 def defaultContextMenu(self): 148 """ 149 Content of the dialog-universal context menu: 150 Save, Print and Copy 151 151 """ 152 152 # Actions … … 162 162 self.actionCopyToClipboard.triggered.connect(self.onClipboardCopy) 163 163 164 def contextMenu(self): 165 """ 166 Define common context menu and associated actions for the MPL widget 167 TODO: move to plotter1d/plotter2d 168 """ 169 raise NotImplementedError("Context menu method must be implemented in derived class.") 170 164 171 def contextMenuQuickPlot(self): 165 172 """ -
src/sas/qtgui/UnitTesting/PlotterBaseTest.py
r3b7b218 rc4e5400 1 1 import sys 2 2 import unittest 3 from mock import MagicMock3 from mock import patch, MagicMock 4 4 5 5 from PyQt4 import QtGui … … 15 15 #import sas.qtgui.GuiUtils as GuiUtils 16 16 from sas.qtgui.GuiUtils import * 17 import sas.qtgui.PlotHelper as PlotHelper 17 18 18 19 # Tested module … … 30 31 def perspective(self): 31 32 return MyPerspective() 32 33 #PlotterBase.PlotterBase.updatePlotHelper = MagicMock()34 #self.plotter = PlotterBase.PlotterBase(None, manager=dummy_manager())35 33 36 34 PlotterBase.PlotterBase.contextMenuQuickPlot = MagicMock() … … 64 62 def testContextMenu(self): 65 63 ''' Test the default context menu ''' 66 pass 67 68 def testContextMenuQuickPlot(self): 69 ''' Test the default quick context menu ''' 70 pass 64 with self.assertRaises(NotImplementedError): 65 self.plotter.contextMenu() 71 66 72 67 def testClean(self): 73 68 ''' test the graph cleanup ''' 74 pass 69 self.plotter.figure.delaxes = MagicMock() 70 self.plotter.clean() 71 self.assertTrue(self.plotter.figure.delaxes.called) 75 72 76 73 def testPlot(self): … … 79 76 self.plotter.plot() 80 77 81 def testOnCloseEvent(self):78 def notestOnCloseEvent(self): 82 79 ''' test the plotter close behaviour ''' 83 pass 80 PlotHelper.deletePlot = MagicMock() 81 self.plotter.closeEvent(None) 82 self.assertTrue(PlotHelper.deletePlot.called) 84 83 85 84 def testOnImageSave(self): 86 85 ''' test the workspace save ''' 87 pass 86 self.plotter.toolbar.save_figure = MagicMock() 87 self.plotter.onImageSave() 88 self.assertTrue(self.plotter.toolbar.save_figure.called) 88 89 89 90 def testOnImagePrint(self): 90 91 ''' test the workspace print ''' 91 pass 92 QtGui.QPainter.end = MagicMock() 93 QtGui.QLabel.render = MagicMock() 92 94 93 def tesOonClipboardCopy(self): 94 ''' test the workspace copy ''' 95 pass 95 # First, let's cancel printing 96 QtGui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected) 97 self.plotter.onImagePrint() 98 self.assertFalse(QtGui.QPainter.end.called) 99 self.assertFalse(QtGui.QLabel.render.called) 100 101 # Let's print now 102 QtGui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted) 103 self.plotter.onImagePrint() 104 self.assertTrue(QtGui.QPainter.end.called) 105 self.assertTrue(QtGui.QLabel.render.called) 106 107 def testOnClipboardCopy(self): 108 ''' test the workspace screen copy ''' 109 QtGui.QClipboard.setPixmap = MagicMock() 110 self.plotter.onClipboardCopy() 111 self.assertTrue(QtGui.QClipboard.setPixmap.called) 96 112 97 113 def testOnGridToggle(self): 98 114 ''' test toggling the grid lines ''' 99 pass 115 # Check the toggle 116 orig_toggle = self.plotter.grid_on 117 118 FigureCanvas.draw_idle = MagicMock() 119 self.plotter.onGridToggle() 120 121 self.assertTrue(FigureCanvas.draw_idle.called) 122 self.assertTrue(self.plotter.grid_on != orig_toggle) 123 124 def testDefaultContextMenu(self): 125 """ Test the right click default menu """ 126 127 self.plotter.defaultContextMenu() 128 129 actions = self.plotter.contextMenu.actions() 130 self.assertEqual(len(actions), 4) 131 132 # Trigger Save Image and make sure the method is called 133 self.assertEqual(actions[0].text(), "Save Image") 134 self.plotter.toolbar.save_figure = MagicMock() 135 actions[0].trigger() 136 self.assertTrue(self.plotter.toolbar.save_figure.called) 137 138 # Trigger Print Image and make sure the method is called 139 self.assertEqual(actions[1].text(), "Print Image") 140 QtGui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected) 141 actions[1].trigger() 142 self.assertTrue(QtGui.QPrintDialog.exec_.called) 143 144 # Trigger Copy to Clipboard and make sure the method is called 145 self.assertEqual(actions[2].text(), "Copy to Clipboard") 146 147 # Spy on cliboard's dataChanged() signal 148 self.clipboard_called = False 149 def done(): 150 self.clipboard_called = True 151 QtCore.QObject.connect(app.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 152 actions[2].trigger() 153 QtGui.qApp.processEvents() 154 # Make sure clipboard got updated. 155 self.assertTrue(self.clipboard_called) 100 156 101 157
Note: See TracChangeset
for help on using the changeset viewer.