Commit 7d4091eb authored by Theophile Terraz's avatar Theophile Terraz
Browse files

pep8

No related merge requests found
Pipeline #55952 passed with stages
in 3 minutes and 31 seconds
Showing with 205 additions and 185 deletions
+205 -185
......@@ -21,7 +21,7 @@ import logging
from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import(
from PyQt5.QtCore import (
Qt, QItemSelectionModel,
QItemSelection, QItemSelectionRange,
)
......@@ -57,8 +57,8 @@ class PlotKPZ(PamhyrPlot):
self.before_plot_selected = None
self.plot_selected = None
self.after_plot_selected = None
self.parent=parent
self._table=table
self.parent = parent
self._table = table
self._colors = []
def onpick(self, event):
......@@ -68,47 +68,49 @@ class PlotKPZ(PamhyrPlot):
return
modifiers = QApplication.keyboardModifiers()
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
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)
if modifiers == Qt.ControlModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
if self.parent._table is None:
return
self.parent._table.blockSignals(True)
if modifiers == Qt.ControlModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
if ind in rows:
rows.remove(ind)
self._select_in_table(rows)
else:
self._select_in_table(rows+[ind])
elif modifiers == Qt.ShiftModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
)
if ind in rows:
rows.remove(ind)
self._select_in_table(rows)
else:
self._select_in_table(rows+[ind])
elif modifiers == Qt.ShiftModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
if len(rows)>0:
i1 = min(rows[0], rows[-1], ind)
i2 = max(rows[0], rows[-1], ind)
else:
i1 = ind
i2 = ind
self._select_range_in_table(i1, i2)
)
if len(rows) > 0:
i1 = min(rows[0], rows[-1], ind)
i2 = max(rows[0], rows[-1], ind)
else:
self.parent.select_row_profile_slider(ind)
self.parent._table.blockSignals(False)
i1 = ind
i2 = ind
self._select_range_in_table(i1, i2)
else:
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]
x = [i[0, 0] for i in s]
mx = event.mouseevent.xdata
points = enumerate(x)
......@@ -124,22 +126,28 @@ class PlotKPZ(PamhyrPlot):
return closest
def _select_in_table(self, ind):
if self._table is not None:
self._table.setFocus()
selection = self._table.selectionModel()
index = QItemSelection()
if len(ind) > 0:
for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0)))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
if self._table is None:
return
self._table.setFocus()
selection = self._table.selectionModel()
index = QItemSelection()
if len(ind) == 0:
return
for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0)))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
if len(ind) > 0:
self._table.scrollTo(self._table.model().index(ind[-1], 0))
if len(ind) > 0:
self._table.scrollTo(self._table.model().index(ind[-1], 0))
def _select_range_in_table(self, ind1, ind2):
if self._table is not None:
......@@ -195,7 +203,7 @@ class PlotKPZ(PamhyrPlot):
self.line_kp_zmin_zmax = self.canvas.axes.vlines(
x=kp, ymin=z_min, ymax=z_max,
color=self._colors,
linestyle = self._style,
linestyle=self._style,
lw=1.,
picker=10,
)
......@@ -208,7 +216,7 @@ class PlotKPZ(PamhyrPlot):
))
colors = [self.color_plot for row in range(len(self._data))]
style = ["-" for row in range(len(self._data))]
if len(rows) >0:
if len(rows) > 0:
for row in rows:
colors[row] = self.color_plot_current
if rows[0] > 0:
......@@ -334,19 +342,19 @@ class PlotKPZ(PamhyrPlot):
self.line_kp_zmin.set_data(kp, z_min)
# TODO comprendre à quoi sert ce bout de code
# ========>
#self.line_kp_zmin_zmax.remove()
#self._colors, self._style = self.color_hightlight()
#self.line_kp_zmin_zmax = self.canvas.axes.vlines(
#x=kp,
#ymin=z_min,
#ymax=z_max,
#color=self._colors,
#linestyle = self._style,
#lw=1.
#)
# <========
# TODO comprendre à quoi sert ce bout de code
# ========>
# self.line_kp_zmin_zmax.remove()
# self._colors, self._style = self.color_hightlight()
# self.line_kp_zmin_zmax = self.canvas.axes.vlines(
# x=kp,
# ymin=z_min,
# ymax=z_max,
# color=self._colors,
# linestyle = self._style,
# lw=1.
# )
# <========
z_complete = self.data.get_guidelines_z()
try:
......
......@@ -51,9 +51,9 @@ class PlotXY(PamhyrPlot):
self.before_plot_selected = None
self.plot_selected = None
self.after_plot_selected = None
self.parent=parent
self.parent = parent
self.line_xy_collection = None
self._table=table
self._table = table
self._colors = []
self._style = []
......@@ -64,41 +64,43 @@ class PlotXY(PamhyrPlot):
return
modifiers = QApplication.keyboardModifiers()
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
if modifiers not in [Qt.ControlModifier,
Qt.NoModifier,
Qt.ShiftModifier]:
return
ind, point = self._closest_section(event)
if self._table is not None:
self._table.blockSignals(True)
if modifiers == Qt.ControlModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
if self._table is None:
return
self._table.blockSignals(True)
if modifiers == Qt.ControlModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
if ind in rows:
rows.remove(ind)
self._select_in_table(rows)
else:
self._select_in_table(rows+[ind])
elif modifiers == Qt.ShiftModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
)
if ind in rows:
rows.remove(ind)
self._select_in_table(rows)
else:
self._select_in_table(rows + [ind])
elif modifiers == Qt.ShiftModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
if len(rows)>0:
i1 = min(rows[0], rows[-1], ind)
i2 = max(rows[0], rows[-1], ind)
else:
i1 = ind
i2 = ind
self._select_range_in_table(i1, i2)
)
if len(rows) > 0:
i1 = min(rows[0], rows[-1], ind)
i2 = max(rows[0], rows[-1], ind)
else:
self.parent.select_row_profile_slider(ind)
self._table.blockSignals(False)
i1 = ind
i2 = ind
self._select_range_in_table(i1, i2)
else:
self.parent.select_row_profile_slider(ind)
self._table.blockSignals(False)
#self.update()
return
def _closest_section(self, event):
......@@ -113,7 +115,7 @@ class PlotXY(PamhyrPlot):
points = []
for i in ind:
points = points + [[i, j] for j in segments[i]]
points = points + [[i, j] for j in segments[i]]
def dist_mouse(point):
x, y = point[1]
......@@ -127,22 +129,24 @@ class PlotXY(PamhyrPlot):
return closest
def _select_in_table(self, ind):
if self._table is not None:
self._table.setFocus()
selection = self._table.selectionModel()
index = QItemSelection()
if len(ind) > 0:
for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0)))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
if self._table is None:
return
self._table.setFocus()
selection = self._table.selectionModel()
index = QItemSelection()
if len(ind) == 0:
return
for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0)))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
if len(ind) > 0:
self._table.scrollTo(self._table.model().index(ind[-1], 0))
if len(ind) > 0:
self._table.scrollTo(self._table.model().index(ind[-1], 0))
def _select_range_in_table(self, ind1, ind2):
if self._table is not None:
......@@ -184,10 +188,12 @@ class PlotXY(PamhyrPlot):
self.line_xy.append(np.column_stack(xy))
self._colors, self._style = self.color_hightlight()
self.line_xy_collection = collections.LineCollection(self.line_xy,
colors = self._colors,
linestyle = self._style,
picker=10)
self.line_xy_collection = collections.LineCollection(
self.line_xy,
colors=self._colors,
linestyle=self._style,
picker=10
)
self.canvas.axes.add_collection(self.line_xy_collection)
def color_hightlight(self):
......@@ -198,7 +204,7 @@ class PlotXY(PamhyrPlot):
))
colors = [self.color_plot for row in range(len(self._data))]
style = ["-" for row in range(len(self._data))]
if len(rows) >0:
if len(rows) > 0:
for row in rows:
colors[row] = self.color_plot_current
if rows[0] > 0:
......@@ -274,24 +280,24 @@ class PlotXY(PamhyrPlot):
x_complete = list(self.data.get_guidelines_x())
y_complete = list(self.data.get_guidelines_y())
# TODO comprendre à quoi sert ce bout de code
# ========>
#for i in range(self.data.number_profiles):
#if i < len(self.line_xy):
#self.line_xy[i][0].set_data(
#self.data.profile(i).x(),
#self.data.profile(i).y()
#)
#else:
#self.line_xy.append(
#self.canvas.axes.plot(
#self.data.profile(i).x(),
#self.data.profile(i).y(),
#color='r',
#**self.plot_default_kargs
#)
#)
# <========
# TODO comprendre à quoi sert ce bout de code
# ========>
# for i in range(self.data.number_profiles):
# if i < len(self.line_xy):
# self.line_xy[i][0].set_data(
# self.data.profile(i).x(),
# self.data.profile(i).y()
# )
# else:
# self.line_xy.append(
# self.canvas.axes.plot(
# self.data.profile(i).x(),
# self.data.profile(i).y(),
# color='r',
# **self.plot_default_kargs
# )
# )
# <========
for i in range(len(x_complete)):
if i < len(self.line_gl):
......
......@@ -72,17 +72,20 @@ class Plot(PamhyrPlot):
# wet_preimeter, water_width)
)
self._onpickevent = None
self._rect_select = RectangleSelector(ax=self.canvas.axes,
onselect=self.rect_select_callback,
useblit=True,
button=[1], # don't use middle nor right button
minspanx=2.0,
minspany=2.0,
spancoords='pixels',
interactive=False)
self._rect_select = RectangleSelector(
ax=self.canvas.axes,
onselect=self.rect_select_callback,
useblit=True,
button=[1], # don't use middle nor right button
minspanx=2.0,
minspany=2.0,
spancoords='pixels',
interactive=False
)
def onrelease(self, event):
# we need to do that to prevent conflicst between onpick and rect_select_callback
# we need to do that to prevent conflicst
# between onpick and rect_select_callback
modifiers = QApplication.keyboardModifiers()
points, hyd = self.highlight
if self._onpickevent is not None:
......@@ -91,7 +94,7 @@ class Plot(PamhyrPlot):
rows = self._parent.index_selected_rows()
if ind in rows:
rows.remove(ind)
del(points[ind])
del (points[ind])
self.highlight = (points, hyd)
self._select_in_table(rows)
else:
......@@ -99,10 +102,13 @@ class Plot(PamhyrPlot):
self._select_in_table(rows+[ind])
elif modifiers == Qt.ShiftModifier:
rows = self._parent.index_selected_rows()
if len(rows)>0:
if len(rows) > 0:
i1 = min(rows[0], rows[-1], ind)
i2 = max(rows[0], rows[-1], ind)
p = [[self.data.points[i].x,self.data.points[i].y] for i in range(i1, i2)]
p = [
[self.data.points[i].x, self.data.points[i].y]
for i in range(i1, i2)
]
else:
i1 = ind
i2 = ind
......@@ -122,7 +128,9 @@ class Plot(PamhyrPlot):
return
modifiers = QApplication.keyboardModifiers()
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
if modifiers not in [Qt.ControlModifier,
Qt.NoModifier,
Qt.ShiftModifier]:
return
self._onpickevent = event
......@@ -178,7 +186,9 @@ class Plot(PamhyrPlot):
index = QItemSelection()
if len(ind) > 0:
for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0)))
index.append(QItemSelectionRange(
self._table.model().index(i, 0))
)
selection.select(
index,
QItemSelectionModel.Rows |
......@@ -244,11 +254,10 @@ class Plot(PamhyrPlot):
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
if(max(abs(x1-x2), abs(y1-y2))<0.001):
if (max(abs(x1-x2), abs(y1-y2)) < 0.001):
return
modifiers = QApplication.keyboardModifiers()
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
......@@ -259,7 +268,7 @@ class Plot(PamhyrPlot):
if all(i in rows for i in inds):
for ind in sorted(inds, reverse=True):
rows.remove(ind)
del(points[ind])
del (points[ind])
self.highlight = (points, hyd)
self._select_in_table(rows)
else:
......@@ -276,12 +285,12 @@ class Plot(PamhyrPlot):
listp = []
station = self.data._get_station(self.data.points)
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)):
if (min(x1, x2) < station[i] < max(x1, x2)
and min(y1, y2) < p.z < max(y1, y2)):
listi.append(i)
listp.append((station[i], p.z))
return listi, listp
def _compute_hydraulics(self, z):
profile = self.data
......
......@@ -181,7 +181,9 @@ class PlotKPC(PamhyrPlot):
return
modifiers = QApplication.keyboardModifiers()
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
if modifiers not in [Qt.ControlModifier,
Qt.NoModifier,
Qt.ShiftModifier]:
return
closest = self._closest_profile(event)
......@@ -194,7 +196,7 @@ class PlotKPC(PamhyrPlot):
def _closest_profile(self, event):
s = event.artist.get_segments()
x = [i[0,0] for i in s]
x = [i[0, 0] for i in s]
mx = event.mouseevent.xdata
points = enumerate(x)
......
......@@ -51,16 +51,16 @@ class PlotXY(PamhyrPlot):
self.before_plot_selected = None
self.plot_selected = None
self.after_plot_selected = None
self.parent=parent
self.parent = parent
self.line_xy_collection = None
self._table=table
self._table = table
self._colors = []
self._style = []
def onpick(self, event):
if event.mouseevent.inaxes != self.canvas.axes:
return
if event.mouseevent.button.value not in [1,3]:
if event.mouseevent.button.value not in [1, 3]:
return
closest = self._closest_section(event)
......@@ -75,7 +75,6 @@ class PlotXY(PamhyrPlot):
if event.mouseevent.button.value == 3:
table.setData(index[4], kp[closest[0]])
#self.update()
return
def _closest_section(self, event):
......@@ -90,7 +89,7 @@ class PlotXY(PamhyrPlot):
points = []
for i in ind:
points = points + [[i, j] for j in segments[i]]
points = points + [[i, j] for j in segments[i]]
def dist_mouse(point):
x, y = point[1]
......@@ -129,10 +128,12 @@ class PlotXY(PamhyrPlot):
self.line_xy.append(np.column_stack(xy))
self._colors, self._style = self.color_hightlight()
self.line_xy_collection = collections.LineCollection(self.line_xy,
colors = self._colors,
linestyle = self._style,
picker=10)
self.line_xy_collection = collections.LineCollection(
self.line_xy,
colors=self._colors,
linestyle=self._style,
picker=10
)
self.canvas.axes.add_collection(self.line_xy_collection)
def color_hightlight(self):
......@@ -213,24 +214,24 @@ class PlotXY(PamhyrPlot):
x_complete = list(self.data.get_guidelines_x())
y_complete = list(self.data.get_guidelines_y())
# TODO comprendre à quoi sert ce bout de code
# ========>
#for i in range(self.data.number_profiles):
#if i < len(self.line_xy):
#self.line_xy[i][0].set_data(
#self.data.profile(i).x(),
#self.data.profile(i).y()
#)
#else:
#self.line_xy.append(
#self.canvas.axes.plot(
#self.data.profile(i).x(),
#self.data.profile(i).y(),
#color='r',
#**self.plot_default_kargs
#)
#)
# <========
# TODO comprendre à quoi sert ce bout de code
# ========>
# for i in range(self.data.number_profiles):
# if i < len(self.line_xy):
# self.line_xy[i][0].set_data(
# self.data.profile(i).x(),
# self.data.profile(i).y()
# )
# else:
# self.line_xy.append(
# self.canvas.axes.plot(
# self.data.profile(i).x(),
# self.data.profile(i).y(),
# color='r',
# **self.plot_default_kargs
# )
# )
# <========
for i in range(len(x_complete)):
if i < len(self.line_gl):
......
......@@ -297,9 +297,3 @@ class LateralContributionWindow(PamhyrWindow):
parent=self
)
win.show()
#@pyqtSlot()
def onChange(self,i): #changed!
QtGui.QMessageBox.information(self,
"Tab Index Changed!",
"Current Tab Index: %d" % i ) #changed!
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment