Loading pyqtgraph_sublasses.py +46 Changes for pyqtgraph_sublasses.py: 46 added lines, 0 removed lines. Original line number Original line Diff line number Diff line from pyqtgraph import ROI class CustomRectangularROI(ROI): """ Rectangular ROI subclass with a single scale handle at the top-right corner. ============== ============================================================= **Arguments** pos (length-2 sequence) The position of the ROI origin. See ROI(). size (length-2 sequence) The size of the ROI. See ROI(). centered (bool) If True, scale handles affect the ROI relative to its center, rather than its origin. sideScalers (bool) If True, extra scale handles are added at the top and right edges. \**args All extra keyword arguments are passed to ROI() ============== ============================================================= """ def __init__(self, pos, size = [8, 8], centered=False, sideScalers=False): #ROI.__init__(self, pos, size, **args) super().__init__(pos, size, centered, sideScalers) ## handles scaling horizontally around center self.addScaleHandle([1, 0.5], [0.5, 0.5]) self.addScaleHandle([0, 0.5], [0.5, 0.5]) ## handles scaling vertically from opposite edge self.addScaleHandle([0.5, 0], [0.5, 1]) self.addScaleHandle([0.5, 1], [0.5, 0]) ## handles scaling both vertically and horizontally self.addScaleHandle([1, 1], [0, 0]) self.addScaleHandle([0, 0], [1, 1]) self.sigRegionChangeFinished.connect(self.correct_scaling) def correct_scaling(self): x, y = self.pos()[0], self.pos()[1] print(x, y) if x%8 != 0 or y%8 != 0: self.setPos((x//8)*8, (y//8)*8) No newline at end of file Loading
pyqtgraph_sublasses.py +46 Changes for pyqtgraph_sublasses.py: 46 added lines, 0 removed lines. Original line number Original line Diff line number Diff line from pyqtgraph import ROI class CustomRectangularROI(ROI): """ Rectangular ROI subclass with a single scale handle at the top-right corner. ============== ============================================================= **Arguments** pos (length-2 sequence) The position of the ROI origin. See ROI(). size (length-2 sequence) The size of the ROI. See ROI(). centered (bool) If True, scale handles affect the ROI relative to its center, rather than its origin. sideScalers (bool) If True, extra scale handles are added at the top and right edges. \**args All extra keyword arguments are passed to ROI() ============== ============================================================= """ def __init__(self, pos, size = [8, 8], centered=False, sideScalers=False): #ROI.__init__(self, pos, size, **args) super().__init__(pos, size, centered, sideScalers) ## handles scaling horizontally around center self.addScaleHandle([1, 0.5], [0.5, 0.5]) self.addScaleHandle([0, 0.5], [0.5, 0.5]) ## handles scaling vertically from opposite edge self.addScaleHandle([0.5, 0], [0.5, 1]) self.addScaleHandle([0.5, 1], [0.5, 0]) ## handles scaling both vertically and horizontally self.addScaleHandle([1, 1], [0, 0]) self.addScaleHandle([0, 0], [1, 1]) self.sigRegionChangeFinished.connect(self.correct_scaling) def correct_scaling(self): x, y = self.pos()[0], self.pos()[1] print(x, y) if x%8 != 0 or y%8 != 0: self.setPos((x//8)*8, (y//8)*8) No newline at end of file