add mouse selection in kpz geometry window

0.0.9
Theophile Terraz 2024-06-07 16:23:09 +02:00
parent dfe12c8bcb
commit 31b37a7792
6 changed files with 59 additions and 7 deletions

View File

@ -50,6 +50,7 @@ class PlotAC(PamhyrPlot):
self.previous_plot_selected = None
self.plot_selected = None
self.next_plot_selected = None
self._rect_select = None
@timer
def draw(self):

View File

@ -20,6 +20,8 @@ import logging
from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
logger = logging.getLogger()
@ -51,6 +53,48 @@ class PlotKPZ(PamhyrPlot):
self.before_plot_selected = None
self.plot_selected = None
self.after_plot_selected = None
self._rect_select = None
self.parent=parent
def onpick(self, event):
if event.mouseevent.inaxes != self.canvas.axes:
return
if event.mouseevent.button.value != 1:
return
modifiers = QApplication.keyboardModifiers()
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
return
ind, point = self._closest_kp(event)
if self.parent._table is not None:
self.parent._table.blockSignals(True)
self.parent.select_row_profile_slider(ind)
self.parent._table.blockSignals(False)
self.update()
return
def _closest_kp(self, event):
s = event.artist.get_segments()
x = [i[0,0] for i in s]
print(x)
mx = event.mouseevent.xdata
points = enumerate(x)
def dist_mouse(point):
x = point[1]
d = abs(mx - x)
return d
closest = min(
points, key=dist_mouse
)
print("closest = "+str(closest))
return closest
@timer
def draw(self):
@ -91,7 +135,8 @@ class PlotKPZ(PamhyrPlot):
self.line_kp_zmin_zmax = self.canvas.axes.vlines(
x=kp, ymin=z_min, ymax=z_max,
color=self.color_plot,
lw=1.
lw=1.,
picker=10
)
def draw_z_line_highlight(self):

View File

@ -46,6 +46,7 @@ class PlotXY(PamhyrPlot):
self.before_plot_selected = None
self.plot_selected = None
self.after_plot_selected = None
self._rect_select = None
@timer
def draw(self):

View File

@ -83,7 +83,7 @@ class Plot(PamhyrPlot):
points, hyd = self.highlight
ind, point = self._closer_point(event)
ind, point = self._closest_point(event)
if modifiers == Qt.ControlModifier:
rows = self._parent.index_selected_rows()
@ -191,7 +191,7 @@ class Plot(PamhyrPlot):
self._table.scrollTo(self._table.model().index(ind2, 0))
self._table.blockSignals(False)
def _closer_point(self, event):
def _closest_point(self, event):
points_ind = event.ind
axes = self.canvas.axes
bx, by = axes.get_xlim(), axes.get_ylim()
@ -217,11 +217,11 @@ class Plot(PamhyrPlot):
)
return d
closer = min(
closest = min(
points, key=dist_mouse
)
return closer
return closest
def _get_z_from_click(self, event):
return event.ydata

View File

@ -382,7 +382,8 @@ class GeometryWindow(PamhyrWindow):
study=self._study,
data=self._reach,
trad=self._trad,
toolbar=self._toolbar_kpc
toolbar=self._toolbar_kpc,
parent=self
)
self._plot_kpc.draw()

View File

@ -16,6 +16,8 @@
# -*- coding: utf-8 -*-
import logging
import matplotlib.colors as mplcolors
from matplotlib.widgets import RectangleSelector
from matplotlib import ticker
@ -26,6 +28,8 @@ from View.Tools.Plot.APlot import APlot
from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
logger = logging.getLogger()
class PamhyrPlot(APlot):
color_axes = "black"
@ -245,5 +249,5 @@ class PamhyrPlot(APlot):
'eclick and erelease are the press and release events'
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
print("(%3.2f, %3.2f) --> (%3.2f, %3.2f)" % (x1, y1, x2, y2))
logging.debug("(%3.2f, %3.2f) --> (%3.2f, %3.2f)" % (x1, y1, x2, y2))
return