deal with conflicts between onpick and rect select in Profile plot

0.0.9
Theophile Terraz 2024-06-11 11:55:52 +02:00
parent fe57890da4
commit c6b28ba3a0
4 changed files with 49 additions and 44 deletions

View File

@ -202,11 +202,11 @@ class PlotKPZ(PamhyrPlot):
)
def color_hightlight(self):
rows = list(
rows = sorted(list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
)
))
colors = [self.color_plot for row in range(len(self._data))]
style = ["-" for row in range(len(self._data))]
if len(rows) >0:

View File

@ -193,11 +193,11 @@ class PlotXY(PamhyrPlot):
self.canvas.axes.add_collection(self.line_xy_collection)
def color_hightlight(self):
rows = list(
rows = sorted(list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
)
))
colors = [self.color_plot for row in range(len(self._data))]
style = ["-" for row in range(len(self._data))]
if len(rows) >0:

View File

@ -70,22 +70,14 @@ class Plot(PamhyrPlot):
None # Hydrolic values (z, wet_area,
# wet_preimeter, water_width)
)
self.events = []
def onpick(self, event):
if event.mouseevent.inaxes != self.canvas.axes:
return
if event.mouseevent.button.value != 1:
return
self._onpickevent = None
def onrelease(self, event):
# we need to do that to prevent conflicst between onpick and rect_select_callback
modifiers = QApplication.keyboardModifiers()
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
return
points, hyd = self.highlight
ind, point = self._closest_point(event)
if self._onpickevent is not None:
ind, point = self._closest_point(self._onpickevent)
if modifiers == Qt.ControlModifier:
rows = self._parent.index_selected_rows()
if ind in rows:
@ -112,7 +104,19 @@ class Plot(PamhyrPlot):
self.highlight = ([point], hyd)
self._select_in_table([ind])
self.update()
self._onpickevent = None
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
self._onpickevent = event
return
def onclick(self, event):
@ -227,6 +231,7 @@ class Plot(PamhyrPlot):
def rect_select_callback(self, eclick, erelease):
points, hyd = self.highlight
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
@ -234,13 +239,12 @@ class Plot(PamhyrPlot):
return
modifiers = QApplication.keyboardModifiers()
points, hyd = self.highlight
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
inds, points2 = self._points_in_rectangle(x1, y1, x2, y2)
self._onclickevent = None
if modifiers == Qt.ControlModifier:
rows = self._parent.index_selected_rows()
if all(i in rows for i in inds):
@ -255,8 +259,6 @@ class Plot(PamhyrPlot):
else:
self.highlight = (points2, hyd)
self._select_in_table(inds)
self.update()
return
def _points_in_rectangle(self, x1, y1, x2, y2):
@ -267,7 +269,7 @@ class Plot(PamhyrPlot):
for i, p in enumerate(self.data.points):
if (min(x1,x2)<station[i]<max(x1,x2) and min(y1,y2)<p.z<max(y1,y2)):
listi.append(i)
listp.append(p)
listp.append((station[i], p.z))
return listi, listp
@ -359,7 +361,6 @@ class Plot(PamhyrPlot):
x, y,
color=self.color_plot_highlight,
lw=1.5, markersize=7, marker='+',
picker=30
)
)

View File

@ -82,6 +82,7 @@ class PamhyrPlot(APlot):
connector = {
'pick_event': self.onpick,
'button_press_event': self.onclick,
'button_release_event': self.onrelease,
}
for event in connector:
@ -109,8 +110,8 @@ class PamhyrPlot(APlot):
onselect=self.rect_select_callback,
useblit=True,
button=[1], # don't use middle nor right button
minspanx=1.0,
minspany=1.0,
minspanx=2.0,
minspany=2.0,
spancoords='pixels',
interactive=False)
@ -245,6 +246,9 @@ class PamhyrPlot(APlot):
def onclick(self, event):
return
def onrelease(self, event):
return
def rect_select_callback(self, eclick, erelease):
'eclick and erelease are the press and release events'
x1, y1 = eclick.xdata, eclick.ydata