Skip to content

Commit

Permalink
pycodestyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zarath committed Sep 15, 2022
1 parent ef6a3c2 commit cabb8a4
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 129 deletions.
4 changes: 3 additions & 1 deletion NanoVNASaver/Charts/Chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ def mouseReleaseEvent(self, a0: QtGui.QMouseEvent):
self.draggedMarker = None
if self.dragbox.state:
self.zoomTo(
self.dragbox.pos_start[0], self.dragbox.pos_start[1], a0.x(), a0.y())
self.dragbox.pos_start[0],
self.dragbox.pos_start[1],
a0.x(), a0.y())
self.dragbox.state = False
self.dragbox.pos = (-1, -1)
self.dragbox.pos_start = (0, 0)
Expand Down
44 changes: 28 additions & 16 deletions NanoVNASaver/Charts/Frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ def __init__(self, name):
self.menu.addAction(self.action_popout)
self.setFocusPolicy(QtCore.Qt.ClickFocus)

self.setMinimumSize(self.dim.width + self.rightMargin + self.leftMargin,
self.dim.height + self.topMargin + self.bottomMargin)
self.setMinimumSize(
self.dim.width + self.rightMargin + self.leftMargin,
self.dim.height + self.topMargin + self.bottomMargin)
self.setSizePolicy(
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
QtWidgets.QSizePolicy.MinimumExpanding))
Expand Down Expand Up @@ -435,8 +436,10 @@ def mouseMoveEvent(self, a0: QtGui.QMouseEvent):
m.frequencyInput.setText(str(f))

def resizeEvent(self, a0: QtGui.QResizeEvent) -> None:
self.dim.width = a0.size().width() - self.rightMargin - self.leftMargin
self.dim.height = a0.size().height() - self.bottomMargin - self.topMargin
self.dim.width = (
a0.size().width() - self.rightMargin - self.leftMargin)
self.dim.height = (
a0.size().height() - self.bottomMargin - self.topMargin)
self.update()

def paintEvent(self, _: QtGui.QPaintEvent) -> None:
Expand Down Expand Up @@ -478,10 +481,14 @@ def drawChart(self, qp: QtGui.QPainter):
headline += f" ({self.name_unit})"
qp.drawText(3, 15, headline)
qp.setPen(QtGui.QPen(Chart.color.foreground))
qp.drawLine(self.leftMargin, 20,
self.leftMargin, self.topMargin + self.dim.height + 5)
qp.drawLine(self.leftMargin - 5, self.topMargin + self.dim.height,
self.leftMargin + self.dim.width, self.topMargin + self.dim.height)
qp.drawLine(self.leftMargin,
20,
self.leftMargin,
self.topMargin + self.dim.height + 5)
qp.drawLine(self.leftMargin - 5,
self.topMargin + self.dim.height,
self.leftMargin + self.dim.width,
self.topMargin + self.dim.height)
self.drawTitle(qp)

def drawValues(self, qp: QtGui.QPainter):
Expand All @@ -506,7 +513,8 @@ def drawValues(self, qp: QtGui.QPainter):
span = max_value - min_value
if span == 0:
logger.info(
"Span is zero for %s-Chart, setting to a small value.", self.name)
"Span is zero for %s-Chart, setting to a small value.",
self.name)
span = 1e-15
self.span = span

Expand Down Expand Up @@ -575,7 +583,9 @@ def drawFrequencyTicks(self, qp):
if self.logarithmicX:
fspan = math.log(self.fstop) - math.log(self.fstart)
freq = round(
math.exp(((i + 1) * fspan / ticks) + math.log(self.fstart)))
math.exp(
((i + 1) * fspan / ticks) +
math.log(self.fstart)))
else:
freq = round(fspan / ticks * (i + 1) + self.fstart)
qp.setPen(QtGui.QPen(Chart.color.foreground))
Expand Down Expand Up @@ -629,12 +639,14 @@ def drawData(self, qp: QtGui.QPainter, data: List[Datapoint],
if prevy is None:
continue
qp.setPen(line_pen)
if self.isPlotable(x, y) and self.isPlotable(prevx, prevy):
qp.drawLine(x, y, prevx, prevy)
elif self.isPlotable(x, y) and not self.isPlotable(prevx, prevy):
new_x, new_y = self.getPlotable(x, y, prevx, prevy)
qp.drawLine(x, y, new_x, new_y)
elif not self.isPlotable(x, y) and self.isPlotable(prevx, prevy):
if self.isPlotable(x, y):
if self.isPlotable(prevx, prevy):
qp.drawLine(x, y, prevx, prevy)
else:
new_x, new_y = self.getPlotable(
x, y, prevx, prevy)
qp.drawLine(x, y, new_x, new_y)
elif self.isPlotable(prevx, prevy):
new_x, new_y = self.getPlotable(prevx, prevy, x, y)
qp.drawLine(prevx, prevy, new_x, new_y)
qp.setPen(pen)
Expand Down
18 changes: 10 additions & 8 deletions NanoVNASaver/Charts/GroupDelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,13 @@ def draw_data(self, qp: QtGui.QPainter, color: QtGui.QColor,
prevx = self.getXPosition(data[i - 1])
prevy = self.getYPositionFromDelay(delay[i - 1])
qp.setPen(line_pen)
if self.isPlotable(x, y) and self.isPlotable(prevx, prevy):
qp.drawLine(x, y, prevx, prevy)
elif self.isPlotable(x, y) and not self.isPlotable(prevx, prevy):
new_x, new_y = self.getPlotable(x, y, prevx, prevy)
qp.drawLine(x, y, new_x, new_y)
elif not self.isPlotable(x, y) and self.isPlotable(prevx, prevy):
if self.isPlotable(x, y):
if self.isPlotable(prevx, prevy):
qp.drawLine(x, y, prevx, prevy)
else:
new_x, new_y = self.getPlotable(x, y, prevx, prevy)
qp.drawLine(x, y, new_x, new_y)
elif self.isPlotable(prevx, prevy):
new_x, new_y = self.getPlotable(prevx, prevy, x, y)
qp.drawLine(prevx, prevy, new_x, new_y)
qp.setPen(pen)
Expand All @@ -197,8 +198,9 @@ def getYPosition(self, d: Datapoint) -> int:
delay = 0
return self.getYPositionFromDelay(delay)

def getYPositionFromDelay(self, delay: float):
return self.topMargin + round((self.maxDelay - delay) / self.span * self.dim.height)
def getYPositionFromDelay(self, delay: float) -> int:
return self.topMargin + int(
(self.maxDelay - delay) / self.span * self.dim.height)

def valueAtPosition(self, y) -> List[float]:
absy = y - self.topMargin
Expand Down
6 changes: 4 additions & 2 deletions NanoVNASaver/Charts/Magnitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def drawValues(self, qp: QtGui.QPainter):
mag = self.magnitude(d)
max_value = max(max_value, mag)
min_value = min(min_value, mag)
for d in self.reference: # Also check min/max for the reference sweep
# Also check min/max for the reference sweep
for d in self.reference:
if d.freq < self.fstart or d.freq > self.fstop:
continue
max_value = max(max_value, mag)
Expand Down Expand Up @@ -114,7 +115,8 @@ def drawValues(self, qp: QtGui.QPainter):

def getYPosition(self, d: Datapoint) -> int:
mag = self.magnitude(d)
return self.topMargin + round((self.maxValue - mag) / self.span * self.dim.height)
return self.topMargin + int(
(self.maxValue - mag) / self.span * self.dim.height)

def valueAtPosition(self, y) -> List[float]:
absy = y - self.topMargin
Expand Down
11 changes: 7 additions & 4 deletions NanoVNASaver/Charts/MagnitudeZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def drawValues(self, qp: QtGui.QPainter):
continue
self.maxValue = max(self.maxValue, mag)
self.minValue = min(self.minValue, mag)
for d in self.reference: # Also check min/max for the reference sweep
# Also check min/max for the reference sweep
for d in self.reference:
if d.freq < self.fstart or d.freq > self.fstop:
continue
mag = self.magnitude(d)
Expand Down Expand Up @@ -114,9 +115,11 @@ def getYPosition(self, d: Datapoint) -> int:
if math.isfinite(mag):
if self.logarithmicY:
span = math.log(self.maxValue) - math.log(self.minValue)
return self.topMargin + round(
(math.log(self.maxValue) - math.log(mag)) / span * self.dim.height)
return self.topMargin + round((self.maxValue - mag) / self.span * self.dim.height)
return self.topMargin + int(
(math.log(self.maxValue) - math.log(mag)) /
span * self.dim.height)
return self.topMargin + int(
(self.maxValue - mag) / self.span * self.dim.height)
return self.topMargin

def valueAtPosition(self, y) -> List[float]:
Expand Down
59 changes: 34 additions & 25 deletions NanoVNASaver/Charts/Permeability.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def drawValues(self, qp: QtGui.QPainter):
max_val = max(max_val, im)
min_val = min(min_val, re)
min_val = min(min_val, im)
for d in self.reference: # Also check min/max for the reference sweep
# Also check min/max for the reference sweep
for d in self.reference:
if d.freq < self.fstart or d.freq > self.fstop:
continue
imp = d.impedance()
Expand Down Expand Up @@ -171,24 +172,28 @@ def drawValues(self, qp: QtGui.QPainter):
# Real part first
line_pen.setColor(Chart.color.sweep)
qp.setPen(line_pen)
if self.isPlotable(x, y_re) and self.isPlotable(prev_x, prev_y_re):
qp.drawLine(x, y_re, prev_x, prev_y_re)
elif self.isPlotable(x, y_re) and not self.isPlotable(prev_x, prev_y_re):
new_x, new_y = self.getPlotable(x, y_re, prev_x, prev_y_re)
qp.drawLine(x, y_re, new_x, new_y)
elif not self.isPlotable(x, y_re) and self.isPlotable(prev_x, prev_y_re):
if self.isPlotable(x, y_re):
if self.isPlotable(prev_x, prev_y_re):
qp.drawLine(x, y_re, prev_x, prev_y_re)
else:
new_x, new_y = self.getPlotable(
x, y_re, prev_x, prev_y_re)
qp.drawLine(x, y_re, new_x, new_y)
elif self.isPlotable(prev_x, prev_y_re):
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
qp.drawLine(prev_x, prev_y_re, new_x, new_y)

# Imag part second
line_pen.setColor(Chart.color.sweep_secondary)
qp.setPen(line_pen)
if self.isPlotable(x, y_im) and self.isPlotable(prev_x, prev_y_im):
qp.drawLine(x, y_im, prev_x, prev_y_im)
elif self.isPlotable(x, y_im) and not self.isPlotable(prev_x, prev_y_im):
new_x, new_y = self.getPlotable(x, y_im, prev_x, prev_y_im)
qp.drawLine(x, y_im, new_x, new_y)
elif not self.isPlotable(x, y_im) and self.isPlotable(prev_x, prev_y_im):
if self.isPlotable(x, y_im):
if self.isPlotable(prev_x, prev_y_im):
qp.drawLine(x, y_im, prev_x, prev_y_im)
else:
new_x, new_y = self.getPlotable(
x, y_im, prev_x, prev_y_im)
qp.drawLine(x, y_im, new_x, new_y)
elif self.isPlotable(prev_x, prev_y_im):
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
qp.drawLine(prev_x, prev_y_im, new_x, new_y)

Expand Down Expand Up @@ -231,24 +236,28 @@ def drawValues(self, qp: QtGui.QPainter):
line_pen.setColor(Chart.color.reference)
qp.setPen(line_pen)
# Real part first
if self.isPlotable(x, y_re) and self.isPlotable(prev_x, prev_y_re):
qp.drawLine(x, y_re, prev_x, prev_y_re)
elif self.isPlotable(x, y_re) and not self.isPlotable(prev_x, prev_y_re):
new_x, new_y = self.getPlotable(x, y_re, prev_x, prev_y_re)
qp.drawLine(x, y_re, new_x, new_y)
elif not self.isPlotable(x, y_re) and self.isPlotable(prev_x, prev_y_re):
if self.isPlotable(x, y_re):
if self.isPlotable(prev_x, prev_y_re):
qp.drawLine(x, y_re, prev_x, prev_y_re)
else:
new_x, new_y = self.getPlotable(
x, y_re, prev_x, prev_y_re)
qp.drawLine(x, y_re, new_x, new_y)
elif self.isPlotable(prev_x, prev_y_re):
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
qp.drawLine(prev_x, prev_y_re, new_x, new_y)

line_pen.setColor(Chart.color.reference_secondary)
qp.setPen(line_pen)
# Imag part second
if self.isPlotable(x, y_im) and self.isPlotable(prev_x, prev_y_im):
qp.drawLine(x, y_im, prev_x, prev_y_im)
elif self.isPlotable(x, y_im) and not self.isPlotable(prev_x, prev_y_im):
new_x, new_y = self.getPlotable(x, y_im, prev_x, prev_y_im)
qp.drawLine(x, y_im, new_x, new_y)
elif not self.isPlotable(x, y_im) and self.isPlotable(prev_x, prev_y_im):
if self.isPlotable(x, y_im):
if self.isPlotable(prev_x, prev_y_im):
qp.drawLine(x, y_im, prev_x, prev_y_im)
else:
new_x, new_y = self.getPlotable(
x, y_im, prev_x, prev_y_im)
qp.drawLine(x, y_im, new_x, new_y)
elif self.isPlotable(prev_x, prev_y_im):
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
qp.drawLine(prev_x, prev_y_im, new_x, new_y)

Expand Down
50 changes: 22 additions & 28 deletions NanoVNASaver/Charts/Phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __init__(self, name=""):
self.y_menu.addSeparator()
self.action_unwrap = QtWidgets.QAction("Unwrap")
self.action_unwrap.setCheckable(True)
self.action_unwrap.triggered.connect(lambda: self.setUnwrap(self.action_unwrap.isChecked()))
self.action_unwrap.triggered.connect(
lambda: self.setUnwrap(self.action_unwrap.isChecked()))
self.y_menu.addAction(self.action_unwrap)

def copy(self):
Expand All @@ -67,14 +68,8 @@ def drawValues(self, qp: QtGui.QPainter):
return

if self.unwrap:
rawData = []
for d in self.data:
rawData.append(d.phase)

rawReference = []
for d in self.reference:
rawReference.append(d.phase)

rawData = [d.phase for d in self.data]
rawReference = [d.phase for d in self.reference]
self.unwrappedData = np.degrees(np.unwrap(rawData))
self.unwrappedReference = np.degrees(np.unwrap(rawReference))

Expand Down Expand Up @@ -102,27 +97,28 @@ def drawValues(self, qp: QtGui.QPainter):

for i in range(tickcount):
angle = minAngle + span * i / tickcount
y = self.topMargin + round((self.maxAngle - angle) / self.span * self.dim.height)
if angle != minAngle and angle != maxAngle:
y = self.topMargin + int(
(self.maxAngle - angle) / self.span * self.dim.height)
if angle not in [minAngle, maxAngle]:
qp.setPen(QtGui.QPen(Chart.color.text))
if angle != 0:
digits = max(0, min(2, math.floor(3 - math.log10(abs(angle)))))
if digits == 0:
anglestr = str(round(angle))
else:
anglestr = str(round(angle, digits))
digits = max(
0, min(2, math.floor(3 - math.log10(abs(angle)))))
anglestr = str(round(angle)) if digits == 0 else str(
round(angle, digits))
else:
anglestr = "0"
qp.drawText(3, y + 3, anglestr + "°")
qp.drawText(3, y + 3, f"{anglestr}°")
qp.setPen(QtGui.QPen(Chart.color.foreground))
qp.drawLine(self.leftMargin - 5, y, self.leftMargin + self.dim.width, y)
qp.drawLine(self.leftMargin - 5, y,
self.leftMargin + self.dim.width, y)
qp.drawLine(self.leftMargin - 5,
self.topMargin,
self.leftMargin + self.dim.width,
self.topMargin)
qp.setPen(Chart.color.text)
qp.drawText(3, self.topMargin + 5, str(maxAngle) + "°")
qp.drawText(3, self.dim.height + self.topMargin, str(minAngle) + "°")
qp.drawText(3, self.topMargin + 5, f"{maxAngle}°")
qp.drawText(3, self.dim.height + self.topMargin, f"{minAngle}°")

self._set_start_stop()

Expand All @@ -136,16 +132,14 @@ def drawValues(self, qp: QtGui.QPainter):
self.drawMarkers(qp)

def getYPosition(self, d: Datapoint) -> int:
if self.unwrap:
if d in self.data:
angle = self.unwrappedData[self.data.index(d)]
elif d in self.reference:
angle = self.unwrappedReference[self.reference.index(d)]
else:
angle = math.degrees(d.phase)
if self.unwrap and d in self.data:
angle = self.unwrappedData[self.data.index(d)]
elif self.unwrap and d in self.reference:
angle = self.unwrappedReference[self.reference.index(d)]
else:
angle = math.degrees(d.phase)
return self.topMargin + round((self.maxAngle - angle) / self.span * self.dim.height)
return self.topMargin + int(
(self.maxAngle - angle) / self.span * self.dim.height)

def valueAtPosition(self, y) -> List[float]:
absy = y - self.topMargin
Expand Down
Loading

0 comments on commit cabb8a4

Please sign in to comment.