4444_logger = logging .getLogger (__name__ )
4545
4646
47+ class _RulerROI (LineROI ):
48+ def __init__ (self , parent = None ):
49+ super ().__init__ (parent )
50+ self ._formatFunction = None
51+
52+ def registerFormatFunction (self , fct ):
53+ """fct is expected to be a function taking (startPoint, endPoint) as parameter"""
54+ self ._formatFunction = fct
55+
56+ def setEndPoints (self , startPoint , endPoint ):
57+ super ().setEndPoints (startPoint = startPoint , endPoint = endPoint )
58+ if self ._formatFunction is not None :
59+ ruler_text = self ._formatFunction (
60+ startPoint = startPoint , endPoint = endPoint
61+ )
62+ self ._updateText (ruler_text )
63+
64+
4765class RulerToolButton (PlotToolButton ):
4866 """
4967 Button to active measurement between two point of the plot
@@ -57,23 +75,6 @@ class RulerToolButton(PlotToolButton):
5775 plot.toolBar().addWidget(rulerButton)
5876 """
5977
60- class RulerROI (LineROI ):
61- def __init__ (self , parent = None ):
62- super ().__init__ (parent )
63- self ._formatFunction = None
64-
65- def registerFormatFunction (self , fct ):
66- """fct is expected to be a function taking (startPoint, endPoint) as parameter"""
67- self ._formatFunction = fct
68-
69- def setEndPoints (self , startPoint , endPoint ):
70- super ().setEndPoints (startPoint = startPoint , endPoint = endPoint )
71- if self ._formatFunction is not None :
72- ruler_text = self ._formatFunction (
73- startPoint = startPoint , endPoint = endPoint
74- )
75- self ._updateText (ruler_text )
76-
7778 def __init__ (
7879 self ,
7980 parent = None ,
@@ -98,10 +99,7 @@ def _callback(self, *args, **kwargs):
9899 if self ._lastRoiCreated is not None :
99100 self ._lastRoiCreated .setVisible (self .isChecked ())
100101 if self .isChecked ():
101- self ._roiManager .start (
102- self .RulerROI ,
103- self ,
104- )
102+ self ._roiManager .start (_RulerROI , self )
105103 self .__interactiveModeStarted (self ._roiManager )
106104 else :
107105 source = self ._roiManager .getInteractionSource ()
0 commit comments