mirror of https://gitlab.com/pamhyr/pamhyr2
add mouse selection in kpz geometry window
parent
dfe12c8bcb
commit
31b37a7792
|
|
@ -50,6 +50,7 @@ class PlotAC(PamhyrPlot):
|
||||||
self.previous_plot_selected = None
|
self.previous_plot_selected = None
|
||||||
self.plot_selected = None
|
self.plot_selected = None
|
||||||
self.next_plot_selected = None
|
self.next_plot_selected = None
|
||||||
|
self._rect_select = None
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ import logging
|
||||||
|
|
||||||
from tools import timer
|
from tools import timer
|
||||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from PyQt5.QtCore import Qt
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
@ -51,6 +53,48 @@ class PlotKPZ(PamhyrPlot):
|
||||||
self.before_plot_selected = None
|
self.before_plot_selected = None
|
||||||
self.plot_selected = None
|
self.plot_selected = None
|
||||||
self.after_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
|
@timer
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
|
@ -91,7 +135,8 @@ class PlotKPZ(PamhyrPlot):
|
||||||
self.line_kp_zmin_zmax = self.canvas.axes.vlines(
|
self.line_kp_zmin_zmax = self.canvas.axes.vlines(
|
||||||
x=kp, ymin=z_min, ymax=z_max,
|
x=kp, ymin=z_min, ymax=z_max,
|
||||||
color=self.color_plot,
|
color=self.color_plot,
|
||||||
lw=1.
|
lw=1.,
|
||||||
|
picker=10
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw_z_line_highlight(self):
|
def draw_z_line_highlight(self):
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ class PlotXY(PamhyrPlot):
|
||||||
self.before_plot_selected = None
|
self.before_plot_selected = None
|
||||||
self.plot_selected = None
|
self.plot_selected = None
|
||||||
self.after_plot_selected = None
|
self.after_plot_selected = None
|
||||||
|
self._rect_select = None
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ class Plot(PamhyrPlot):
|
||||||
|
|
||||||
points, hyd = self.highlight
|
points, hyd = self.highlight
|
||||||
|
|
||||||
ind, point = self._closer_point(event)
|
ind, point = self._closest_point(event)
|
||||||
|
|
||||||
if modifiers == Qt.ControlModifier:
|
if modifiers == Qt.ControlModifier:
|
||||||
rows = self._parent.index_selected_rows()
|
rows = self._parent.index_selected_rows()
|
||||||
|
|
@ -191,7 +191,7 @@ class Plot(PamhyrPlot):
|
||||||
self._table.scrollTo(self._table.model().index(ind2, 0))
|
self._table.scrollTo(self._table.model().index(ind2, 0))
|
||||||
self._table.blockSignals(False)
|
self._table.blockSignals(False)
|
||||||
|
|
||||||
def _closer_point(self, event):
|
def _closest_point(self, event):
|
||||||
points_ind = event.ind
|
points_ind = event.ind
|
||||||
axes = self.canvas.axes
|
axes = self.canvas.axes
|
||||||
bx, by = axes.get_xlim(), axes.get_ylim()
|
bx, by = axes.get_xlim(), axes.get_ylim()
|
||||||
|
|
@ -217,11 +217,11 @@ class Plot(PamhyrPlot):
|
||||||
)
|
)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
closer = min(
|
closest = min(
|
||||||
points, key=dist_mouse
|
points, key=dist_mouse
|
||||||
)
|
)
|
||||||
|
|
||||||
return closer
|
return closest
|
||||||
|
|
||||||
def _get_z_from_click(self, event):
|
def _get_z_from_click(self, event):
|
||||||
return event.ydata
|
return event.ydata
|
||||||
|
|
|
||||||
|
|
@ -382,7 +382,8 @@ class GeometryWindow(PamhyrWindow):
|
||||||
study=self._study,
|
study=self._study,
|
||||||
data=self._reach,
|
data=self._reach,
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
toolbar=self._toolbar_kpc
|
toolbar=self._toolbar_kpc,
|
||||||
|
parent=self
|
||||||
)
|
)
|
||||||
self._plot_kpc.draw()
|
self._plot_kpc.draw()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
import matplotlib.colors as mplcolors
|
import matplotlib.colors as mplcolors
|
||||||
from matplotlib.widgets import RectangleSelector
|
from matplotlib.widgets import RectangleSelector
|
||||||
from matplotlib import ticker
|
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.PamhyrCanvas import MplCanvas
|
||||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class PamhyrPlot(APlot):
|
class PamhyrPlot(APlot):
|
||||||
color_axes = "black"
|
color_axes = "black"
|
||||||
|
|
@ -245,5 +249,5 @@ class PamhyrPlot(APlot):
|
||||||
'eclick and erelease are the press and release events'
|
'eclick and erelease are the press and release events'
|
||||||
x1, y1 = eclick.xdata, eclick.ydata
|
x1, y1 = eclick.xdata, eclick.ydata
|
||||||
x2, y2 = erelease.xdata, erelease.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
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue