1111
1212# guitest: show
1313
14- from typing import TYPE_CHECKING
15-
16- import qtpy .QtWidgets as QW
14+ import numpy as np
1715from guidata .qthelpers import exec_dialog , qt_app_context
18- from numpy import linspace , sin
16+ from qtpy import QtWidgets as QW
1917
2018from plotpy .builder import make
2119from plotpy .config import _
2220from plotpy .interfaces .items import ICurveItemType
2321from plotpy .plot .plotwidget import PlotDialog
2422from plotpy .tools import EditPointTool
2523
26- if TYPE_CHECKING :
27- from plotpy .items .curve .base import CurveItem
28-
2924
3025def callback_function (tool : EditPointTool ):
3126 """Callback function to be called by the tool after a point has moved
@@ -47,9 +42,9 @@ def make_new_bbox(dialog: PlotDialog):
4742 and dialog .button_layout is not None
4843 and (tool := dialog .manager .get_tool (EditPointTool )) is not None
4944 ):
50- custom_button = QW .QPushButton (_ ("Insert point" ), dialog )
51- custom_button .clicked .connect (tool .trigger_insert_point_at_selection )
52- dialog .button_layout .insertWidget (0 , custom_button )
45+ insert_btn = QW .QPushButton (_ ("Insert point" ), dialog )
46+ insert_btn .clicked .connect (tool .trigger_insert_point_at_selection )
47+ dialog .button_layout .insertWidget (0 , insert_btn )
5348
5449
5550def edit_curve (* args ):
@@ -69,7 +64,7 @@ def edit_curve(*args):
6964 default .activate ()
7065 plot = win .manager .get_plot ()
7166 for cx , cy in args [:- 1 ]:
72- item : CurveItem = make .mcurve (cx , cy )
67+ item = make .mcurve (cx , cy )
7368 plot .add_item (item )
7469 item = make .mcurve (* args [- 1 ], "r-+" )
7570 plot .add_item (item )
@@ -82,12 +77,12 @@ def edit_curve(*args):
8277
8378def test_edit_curve ():
8479 """Test"""
85- with qt_app_context (exec_loop = False ):
86- x = linspace (- 10 , 10 , num = 100 )
87- y = 0.25 * sin (sin (sin (x * 0.5 )))
88- x2 = linspace (- 10 , 10 , num = 100 )
89- y2 = sin (sin (sin (x2 )))
90- edited_args = edit_curve ((x , y ), (x2 , y2 ), (x , sin (2 * y )))
80+ with qt_app_context ():
81+ x = np . linspace (- 10 , 10 , num = 100 )
82+ y = 0.25 * np . sin (np . sin (np . sin (x * 0.5 )))
83+ x2 = np . linspace (- 10 , 10 , num = 100 )
84+ y2 = np . sin (np . sin (np . sin (x2 )))
85+ edited_args = edit_curve ((x , y ), (x2 , y2 ), (x , np . sin (2 * y )))
9186 edit_curve (* edited_args )
9287 print ((y2 == edited_args [1 ][1 ]).all ())
9388
0 commit comments