def test_PolyLineROI(): rois = [ (pg.PolyLineROI([[0, 0], [10, 0], [0, 15]], closed=True, pen=0.3), 'closed'), (pg.PolyLineROI([[0, 0], [10, 0], [0, 15]], closed=False, pen=0.3), 'open') ] #plt = pg.plot() plt = pg.GraphicsView() plt.show() resizeWindow(plt, 200, 200) vb = pg.ViewBox() plt.scene().addItem(vb) vb.resize(200, 200) #plt.plotItem = pg.PlotItem() #plt.scene().addItem(plt.plotItem) #plt.plotItem.resize(200, 200) plt.scene().minDragTime = 0 # let us simulate mouse drags very quickly. # seemingly arbitrary requirements; might need longer wait time for some platforms.. QtTest.QTest.qWaitForWindowShown(plt) QtTest.QTest.qWait(100) for r, name in rois: vb.clear() vb.addItem(r) vb.autoRange() app.processEvents() assertImageApproved(plt, 'roi/polylineroi/'+name+'_init', 'Init %s polyline.' % name) initState = r.getState() assert len(r.getState()['points']) == 3 # hover over center center = r.mapToScene(pg.Point(3, 3)) mouseMove(plt, center) assertImageApproved(plt, 'roi/polylineroi/'+name+'_hover_roi', 'Hover mouse over center of ROI.') # drag ROI mouseDrag(plt, center, center + pg.Point(10, -10), QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/'+name+'_drag_roi', 'Drag mouse over center of ROI.') # hover over handle pt = r.mapToScene(pg.Point(r.getState()['points'][2])) mouseMove(plt, pt) assertImageApproved(plt, 'roi/polylineroi/'+name+'_hover_handle', 'Hover mouse over handle.') # drag handle mouseDrag(plt, pt, pt + pg.Point(5, 20), QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/'+name+'_drag_handle', 'Drag mouse over handle.') # hover over segment pt = r.mapToScene((pg.Point(r.getState()['points'][2]) + pg.Point(r.getState()['points'][1])) * 0.5) mouseMove(plt, pt+pg.Point(0, 2)) assertImageApproved(plt, 'roi/polylineroi/'+name+'_hover_segment', 'Hover mouse over diagonal segment.') # click segment mouseClick(plt, pt, QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/'+name+'_click_segment', 'Click mouse over segment.') # drag new handle mouseMove(plt, pt+pg.Point(10, -10)) # pg bug: have to move the mouse off/on again to register hover mouseDrag(plt, pt, pt + pg.Point(10, -10), QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/'+name+'_drag_new_handle', 'Drag mouse over created handle.') # clear all points r.clearPoints() assertImageApproved(plt, 'roi/polylineroi/'+name+'_clear', 'All points cleared.') assert len(r.getState()['points']) == 0 # call setPoints r.setPoints(initState['points']) assertImageApproved(plt, 'roi/polylineroi/'+name+'_setpoints', 'Reset points to initial state.') assert len(r.getState()['points']) == 3 # call setState r.setState(initState) assertImageApproved(plt, 'roi/polylineroi/'+name+'_setstate', 'Reset ROI to initial state.') assert len(r.getState()['points']) == 3
def test_PolyLineROI(): rois = [(pg.PolyLineROI([[0, 0], [10, 0], [0, 15]], closed=True, pen=0.3), 'closed'), (pg.PolyLineROI([[0, 0], [10, 0], [0, 15]], closed=False, pen=0.3), 'open')] #plt = pg.plot() plt = pg.GraphicsView() plt.show() resizeWindow(plt, 200, 200) vb = pg.ViewBox() plt.scene().addItem(vb) vb.resize(200, 200) #plt.plotItem = pg.PlotItem() #plt.scene().addItem(plt.plotItem) #plt.plotItem.resize(200, 200) plt.scene().minDragTime = 0 # let us simulate mouse drags very quickly. # seemingly arbitrary requirements; might need longer wait time for some platforms.. QtTest.QTest.qWaitForWindowExposed(plt) QtTest.QTest.qWait(100) for r, name in rois: vb.clear() vb.addItem(r) vb.autoRange() app.processEvents() assertImageApproved(plt, 'roi/polylineroi/' + name + '_init', 'Init %s polyline.' % name) initState = r.getState() assert len(r.getState()['points']) == 3 # hover over center center = r.mapToScene(pg.Point(3, 3)) mouseMove(plt, center) assertImageApproved(plt, 'roi/polylineroi/' + name + '_hover_roi', 'Hover mouse over center of ROI.') # drag ROI mouseDrag(plt, center, center + pg.Point(10, -10), QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/' + name + '_drag_roi', 'Drag mouse over center of ROI.') # hover over handle pt = r.mapToScene(pg.Point(r.getState()['points'][2])) mouseMove(plt, pt) assertImageApproved(plt, 'roi/polylineroi/' + name + '_hover_handle', 'Hover mouse over handle.') # drag handle mouseDrag(plt, pt, pt + pg.Point(5, 20), QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/' + name + '_drag_handle', 'Drag mouse over handle.') # hover over segment pt = r.mapToScene((pg.Point(r.getState()['points'][2]) + pg.Point(r.getState()['points'][1])) * 0.5) mouseMove(plt, pt + pg.Point(0, 2)) assertImageApproved(plt, 'roi/polylineroi/' + name + '_hover_segment', 'Hover mouse over diagonal segment.') # click segment mouseClick(plt, pt, QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/' + name + '_click_segment', 'Click mouse over segment.') # drag new handle mouseMove( plt, pt + pg.Point(10, -10) ) # pg bug: have to move the mouse off/on again to register hover mouseDrag(plt, pt, pt + pg.Point(10, -10), QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/' + name + '_drag_new_handle', 'Drag mouse over created handle.') # clear all points r.clearPoints() assertImageApproved(plt, 'roi/polylineroi/' + name + '_clear', 'All points cleared.') assert len(r.getState()['points']) == 0 # call setPoints r.setPoints(initState['points']) assertImageApproved(plt, 'roi/polylineroi/' + name + '_setpoints', 'Reset points to initial state.') assert len(r.getState()['points']) == 3 # call setState r.setState(initState) assertImageApproved(plt, 'roi/polylineroi/' + name + '_setstate', 'Reset ROI to initial state.') assert len(r.getState()['points']) == 3 plt.hide()
def test_selection(self): selected_data = self.get_output(self.widget.Outputs.selected_data) self.assertIsNone(selected_data) self.simulate_mouse_drag((0.1, 1), (6, 1)) # check if correct curve is selected self.assertEqual(1, len(self.widget.graph.selection)) self.assertIn(0, self.widget.graph.selection.keys()) # check if correct intervals are selected selection_interval = self.widget.graph.selection[0] self.assertEqual(0.1, round(selection_interval.x[0], 1)) self.assertEqual(5.0, round(selection_interval.x[-1])) self.assertEqual(1.0, round(selection_interval.y[0])) self.assertEqual(0.1, round(selection_interval.y[-1], 1)) # check output data selected_data = self.get_output(self.widget.Outputs.selected_data) selected_groups = selected_data.get_column_view('Group')[0] self.assertEqual(12, selected_groups.size) selected_groups = set(selected_data.get_column_view('Group')[0]) self.assertEqual(2, len(selected_groups)) self.assertIn(0, selected_groups) self.assertIn(1, selected_groups) self.widget.group_var = self.widget.data.domain['Group'] self.widget.on_controls_changed() self.simulate_mouse_drag((0.1, 1), (6, 1)) # check if correct curve is selected self.assertTrue(1, len(self.widget.graph.selection)) self.assertIn(0, self.widget.graph.selection.keys()) # check if correct intervals are selected selection_interval = self.widget.graph.selection[0] self.assertEqual(0.1, round(selection_interval.x[0], 1)) self.assertEqual(5.0, round(selection_interval.x[-1])) self.assertEqual(1.0, round(selection_interval.y[0])) self.assertEqual(0.2, round(selection_interval.y[-1], 1)) # check output data selected_data = self.get_output(self.widget.Outputs.selected_data) selected_groups = selected_data.get_column_view('Group')[0] self.assertEqual(6, selected_groups.size) selected_groups = set(selected_data.get_column_view('Group')[0]) self.assertEqual(1, len(selected_groups)) self.assertIn(0, selected_groups) self.assertNotIn(1, selected_groups) # reset selection pos = self.widget.graph.view_box.mapViewToScene(pg.Point(0, 0)).toPoint() mouseClick(self.widget.graph, pos, Qt.LeftButton) QtTest.QTest.qWait(100) selected_data = self.get_output(self.widget.Outputs.selected_data) self.assertIsNone(selected_data) self.assertEqual(0, len(self.widget.graph.selection)) # test selection of a second group self.simulate_mouse_drag((0.4, 0.8), (6, 0.8)) # check if correct curve is selected self.assertTrue(1, len(self.widget.graph.selection)) self.assertIn(1, self.widget.graph.selection.keys()) # check output data selected_data = self.get_output(self.widget.Outputs.selected_data) selected_groups = selected_data.get_column_view('Group')[0] self.assertEqual(6, selected_groups.size) selected_groups = set(selected_data.get_column_view('Group')[0]) self.assertEqual(1, len(selected_groups)) self.assertIn(1, selected_groups) self.assertNotIn(0, selected_groups)