|
9 | 9 | from qwt import QwtPlotItem |
10 | 10 |
|
11 | 11 | from plotpy.interfaces.items import ICurveItemType, IItemType |
| 12 | +from plotpy.plot.base import BasePlot |
12 | 13 | from plotpy.tests import vistools as ptv |
13 | 14 | from plotpy.tests.features.test_auto_curve_image import make_curve_image_legend |
14 | 15 | from plotpy.tools import CommandTool, InteractiveTool |
|
26 | 27 | ToolT = TypeVar("ToolT", bound=Union[InteractiveTool, CommandTool]) |
27 | 28 |
|
28 | 29 |
|
| 30 | +def rel_pos_to_canvas_pos( |
| 31 | + canvas: BasePlot, relative_xy: tuple[float, float] |
| 32 | +) -> tuple[QC.QPointF, QC.QPointF]: |
| 33 | + """Computes and return the relative position on the canvas and the corresponding |
| 34 | + abolute position in the window. |
| 35 | +
|
| 36 | + Args: |
| 37 | + canvas: Plot canvas |
| 38 | + relative_xy: Relative position on the canvas (0 < xy <1) |
| 39 | +
|
| 40 | + Returns: |
| 41 | + Tuple of the relative position on the canvas and the corresponding absolute |
| 42 | + position in the window. |
| 43 | + """ |
| 44 | + size = canvas.size() |
| 45 | + pos_x, pos_y = ( |
| 46 | + relative_xy[0] * size.width(), |
| 47 | + relative_xy[1] * size.height(), |
| 48 | + ) |
| 49 | + canvas_pos = QC.QPointF(pos_x, pos_y) |
| 50 | + return canvas_pos, QC.QPointF(canvas.mapToGlobal(canvas_pos.toPoint())) |
| 51 | + |
| 52 | + |
29 | 53 | def keyboard_event( |
30 | 54 | win: PlotDialog | PlotWindow, |
31 | 55 | qapp: QW.QApplication, |
@@ -70,22 +94,14 @@ def mouse_event_at_relative_plot_pos( |
70 | 94 | None |
71 | 95 | """ |
72 | 96 | plot = win.manager.get_plot() |
73 | | - |
74 | | - plot = win.manager.get_plot() |
75 | | - canvas: QW.QWidget = plot.canvas() # type: ignore |
76 | | - size = canvas.size() |
77 | | - pos_x, pos_y = ( |
78 | | - relative_xy[0] * size.width(), |
79 | | - relative_xy[1] * size.height(), |
80 | | - ) |
81 | | - canvas_pos = QC.QPointF(pos_x, pos_y) |
82 | | - glob_pos = QC.QPointF(canvas.mapToGlobal(canvas_pos.toPoint())) |
| 97 | + canvas = plot.canvas() |
| 98 | + canvas_pos, glob_pos = rel_pos_to_canvas_pos(plot, relative_xy) |
83 | 99 |
|
84 | 100 | for type_ in click_types: |
85 | 101 | mouse_event = QG.QMouseEvent( |
86 | 102 | type_, |
87 | 103 | canvas_pos, |
88 | | - glob_pos, |
| 104 | + # glob_pos, |
89 | 105 | QC.Qt.MouseButton.LeftButton, |
90 | 106 | QC.Qt.MouseButton.LeftButton, |
91 | 107 | mod, |
|
0 commit comments