diff --git a/.coveragerc b/.coveragerc index ccf8ae1..9228c0b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,7 @@ [run] # ignore GUI code atm. omit = - NanoVNASaver/Analysis.py + NanoVNASaver/Analysis/*.py NanoVNASaver/Calibration.py NanoVNASaver/Charts/*.py NanoVNASaver/Hardware/*.py diff --git a/NanoVNASaver/Analysis/BandPassAnalysis.py b/NanoVNASaver/Analysis/BandPassAnalysis.py index 647b48e..dc7fc9a 100644 --- a/NanoVNASaver/Analysis/BandPassAnalysis.py +++ b/NanoVNASaver/Analysis/BandPassAnalysis.py @@ -35,14 +35,16 @@ class BandPassAnalysis(Analysis): layout = QtWidgets.QFormLayout() self._widget.setLayout(layout) layout.addRow(QtWidgets.QLabel("Band pass filter analysis")) - layout.addRow(QtWidgets.QLabel("Please place " + self.app.markers[0].name + " in the filter passband.")) + layout.addRow( + QtWidgets.QLabel( + f"Please place {self.app.markers[0].name} in the filter passband.")) self.result_label = QtWidgets.QLabel() self.lower_cutoff_label = QtWidgets.QLabel() self.lower_six_db_label = QtWidgets.QLabel() self.lower_sixty_db_label = QtWidgets.QLabel() self.lower_db_per_octave_label = QtWidgets.QLabel() self.lower_db_per_decade_label = QtWidgets.QLabel() - + self.upper_cutoff_label = QtWidgets.QLabel() self.upper_six_db_label = QtWidgets.QLabel() self.upper_sixty_db_label = QtWidgets.QLabel() @@ -111,7 +113,8 @@ class BandPassAnalysis(Analysis): if pass_band_location < 0: logger.debug("No location for %s", self.app.markers[0].name) - self.result_label.setText("Please place " + self.app.markers[0].name + " in the passband.") + self.result_label.setText( + f"Please place {self.app.markers[0].name} in the passband.") return pass_band_db = self.app.data21[pass_band_location].gain @@ -170,9 +173,9 @@ class BandPassAnalysis(Analysis): lower_cutoff_gain = self.app.data21[lower_cutoff_location].gain - pass_band_db if lower_cutoff_gain < -4: - logger.debug("Lower cutoff frequency found at %f dB - insufficient data points for true -3 dB point.", + logger.debug("Lower cutoff frequency found at %f dB" + " - insufficient data points for true -3 dB point.", lower_cutoff_gain) - logger.debug("Found true lower cutoff frequency at %d", lower_cutoff_frequency) self.lower_cutoff_label.setText(RFTools.formatFrequency(lower_cutoff_frequency) + @@ -192,13 +195,15 @@ class BandPassAnalysis(Analysis): upper_cutoff_frequency = self.app.data21[upper_cutoff_location].freq upper_cutoff_gain = self.app.data21[upper_cutoff_location].gain - pass_band_db if upper_cutoff_gain < -4: - logger.debug("Upper cutoff frequency found at %f dB - insufficient data points for true -3 dB point.", + logger.debug("Upper cutoff frequency found at %f dB" + " - insufficient data points for true -3 dB point.", upper_cutoff_gain) logger.debug("Found true upper cutoff frequency at %d", upper_cutoff_frequency) - self.upper_cutoff_label.setText(RFTools.formatFrequency(upper_cutoff_frequency) + - " (" + str(round(upper_cutoff_gain, 1)) + " dB)") + self.upper_cutoff_label.setText( + RFTools.formatFrequency(upper_cutoff_frequency) + + f" ({round(upper_cutoff_gain, 1)} dB)") self.app.markers[2].setFrequency(str(upper_cutoff_frequency)) self.app.markers[2].frequencyInput.setText(str(upper_cutoff_frequency)) @@ -252,19 +257,25 @@ class BandPassAnalysis(Analysis): if sixty_db_location > 0: if sixty_db_location > 0: sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq - self.lower_sixty_db_label.setText(RFTools.formatFrequency(sixty_db_cutoff_frequency)) + self.lower_sixty_db_label.setText( + RFTools.formatFrequency(sixty_db_cutoff_frequency)) elif ten_db_location != -1 and twenty_db_location != -1: ten = self.app.data21[ten_db_location].freq twenty = self.app.data21[twenty_db_location].freq - sixty_db_frequency = ten * 10 ** (5 * (math.log10(twenty) - math.log10(ten))) - self.lower_sixty_db_label.setText(RFTools.formatFrequency(sixty_db_frequency) + " (derived)") + sixty_db_frequency = ten * \ + 10 ** (5 * (math.log10(twenty) - math.log10(ten))) + self.lower_sixty_db_label.setText( + RFTools.formatFrequency(sixty_db_frequency) + " (derived)") else: self.lower_sixty_db_label.setText("Not calculated") if ten_db_location > 0 and twenty_db_location > 0 and ten_db_location != twenty_db_location: - octave_attenuation, decade_attenuation = self.calculateRolloff(ten_db_location, twenty_db_location) - self.lower_db_per_octave_label.setText(str(round(octave_attenuation, 3)) + " dB / octave") - self.lower_db_per_decade_label.setText(str(round(decade_attenuation, 3)) + " dB / decade") + octave_attenuation, decade_attenuation = self.calculateRolloff( + ten_db_location, twenty_db_location) + self.lower_db_per_octave_label.setText( + str(round(octave_attenuation, 3)) + " dB / octave") + self.lower_db_per_decade_label.setText( + str(round(decade_attenuation, 3)) + " dB / decade") else: self.lower_db_per_octave_label.setText("Not calculated") self.lower_db_per_decade_label.setText("Not calculated") @@ -311,25 +322,33 @@ class BandPassAnalysis(Analysis): if sixty_db_location > 0: sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq - self.upper_sixty_db_label.setText(RFTools.formatFrequency(sixty_db_cutoff_frequency)) + self.upper_sixty_db_label.setText( + RFTools.formatFrequency(sixty_db_cutoff_frequency)) elif ten_db_location != -1 and twenty_db_location != -1: ten = self.app.data21[ten_db_location].freq twenty = self.app.data21[twenty_db_location].freq - sixty_db_frequency = ten * 10 ** (5 * (math.log10(twenty) - math.log10(ten))) - self.upper_sixty_db_label.setText(RFTools.formatFrequency(sixty_db_frequency) + " (derived)") + sixty_db_frequency = ten * \ + 10 ** (5 * (math.log10(twenty) - math.log10(ten))) + self.upper_sixty_db_label.setText( + RFTools.formatFrequency(sixty_db_frequency) + " (derived)") else: self.upper_sixty_db_label.setText("Not calculated") if ten_db_location > 0 and twenty_db_location > 0 and ten_db_location != twenty_db_location: - octave_attenuation, decade_attenuation = self.calculateRolloff(ten_db_location, twenty_db_location) - self.upper_db_per_octave_label.setText(str(round(octave_attenuation, 3)) + " dB / octave") - self.upper_db_per_decade_label.setText(str(round(decade_attenuation, 3)) + " dB / decade") + octave_attenuation, decade_attenuation = self.calculateRolloff( + ten_db_location, twenty_db_location) + self.upper_db_per_octave_label.setText( + f"{round(octave_attenuation, 3)} dB / octave") + self.upper_db_per_decade_label.setText( + f"{round(decade_attenuation, 3)} dB / decade") else: self.upper_db_per_octave_label.setText("Not calculated") self.upper_db_per_decade_label.setText("Not calculated") if upper_cutoff_gain < -4 or lower_cutoff_gain < -4: - self.result_label.setText("Analysis complete (" + str(len(self.app.data)) + " points)\n" + - "Insufficient data for analysis. Increase segment count.") + self.result_label.setText( + f"Analysis complete ({len(self.app.data)} points)\n" + f"Insufficient data for analysis. Increase segment count.") else: - self.result_label.setText("Analysis complete (" + str(len(self.app.data)) + " points)") + self.result_label.setText( + f"Analysis complete ({len(self.app.data)} points)") diff --git a/NanoVNASaver/Analysis/BandStopAnalysis.py b/NanoVNASaver/Analysis/BandStopAnalysis.py index 28984d5..ac1ec97 100644 --- a/NanoVNASaver/Analysis/BandStopAnalysis.py +++ b/NanoVNASaver/Analysis/BandStopAnalysis.py @@ -126,7 +126,8 @@ class BandStopAnalysis(Analysis): lower_cutoff_gain = self.app.data21[lower_cutoff_location].gain - pass_band_db if lower_cutoff_gain < -4: - logger.debug("Lower cutoff frequency found at %f dB - insufficient data points for true -3 dB point.", + logger.debug("Lower cutoff frequency found at %f dB" + " - insufficient data points for true -3 dB point.", lower_cutoff_gain) logger.debug("Found true lower cutoff frequency at %d", lower_cutoff_frequency) @@ -147,7 +148,8 @@ class BandStopAnalysis(Analysis): upper_cutoff_frequency = self.app.data21[upper_cutoff_location].freq upper_cutoff_gain = self.app.data21[upper_cutoff_location].gain - pass_band_db if upper_cutoff_gain < -4: - logger.debug("Upper cutoff frequency found at %f dB - insufficient data points for true -3 dB point.", + logger.debug("Upper cutoff frequency found at %f dB" + " - insufficient data points for true -3 dB point.", upper_cutoff_gain) logger.debug("Found true upper cutoff frequency at %d", upper_cutoff_frequency) @@ -206,19 +208,27 @@ class BandStopAnalysis(Analysis): if sixty_db_location > 0: sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq - self.lower_sixty_db_label.setText(RFTools.formatFrequency(sixty_db_cutoff_frequency)) + self.lower_sixty_db_label.setText( + RFTools.formatFrequency(sixty_db_cutoff_frequency)) elif ten_db_location != -1 and twenty_db_location != -1: ten = self.app.data21[ten_db_location].freq twenty = self.app.data21[twenty_db_location].freq sixty_db_frequency = ten * 10 ** (5 * (math.log10(twenty) - math.log10(ten))) - self.lower_sixty_db_label.setText(RFTools.formatFrequency(sixty_db_frequency) + " (derived)") + self.lower_sixty_db_label.setText( + RFTools.formatFrequency(sixty_db_frequency) + + " (derived)") else: self.lower_sixty_db_label.setText("Not calculated") - if ten_db_location > 0 and twenty_db_location > 0 and ten_db_location != twenty_db_location: - octave_attenuation, decade_attenuation = self.calculateRolloff(ten_db_location, twenty_db_location) - self.lower_db_per_octave_label.setText(str(round(octave_attenuation, 3)) + " dB / octave") - self.lower_db_per_decade_label.setText(str(round(decade_attenuation, 3)) + " dB / decade") + if (ten_db_location > 0 and + twenty_db_location > 0 and + ten_db_location != twenty_db_location): + octave_attenuation, decade_attenuation = self.calculateRolloff( + ten_db_location, twenty_db_location) + self.lower_db_per_octave_label.setText( + f"{round(octave_attenuation, 3)} dB / octave") + self.lower_db_per_decade_label.setText( + f"{round(decade_attenuation, 3)} dB / decade") else: self.lower_db_per_octave_label.setText("Not calculated") self.lower_db_per_decade_label.setText("Not calculated") @@ -265,25 +275,36 @@ class BandStopAnalysis(Analysis): if sixty_db_location > 0: sixty_db_cutoff_frequency = self.app.data21[sixty_db_location].freq - self.upper_sixty_db_label.setText(RFTools.formatFrequency(sixty_db_cutoff_frequency)) + self.upper_sixty_db_label.setText( + RFTools.formatFrequency(sixty_db_cutoff_frequency)) elif ten_db_location != -1 and twenty_db_location != -1: ten = self.app.data21[ten_db_location].freq twenty = self.app.data21[twenty_db_location].freq - sixty_db_frequency = ten * 10 ** (5 * (math.log10(twenty) - math.log10(ten))) - self.upper_sixty_db_label.setText(RFTools.formatFrequency(sixty_db_frequency) + " (derived)") + sixty_db_frequency = ten * 10 ** ( + 5 * (math.log10(twenty) - math.log10(ten))) + self.upper_sixty_db_label.setText( + RFTools.formatFrequency(sixty_db_frequency) + + " (derived)") else: self.upper_sixty_db_label.setText("Not calculated") - if ten_db_location > 0 and twenty_db_location > 0 and ten_db_location != twenty_db_location: - octave_attenuation, decade_attenuation = self.calculateRolloff(ten_db_location, twenty_db_location) - self.upper_db_per_octave_label.setText(str(round(octave_attenuation, 3)) + " dB / octave") - self.upper_db_per_decade_label.setText(str(round(decade_attenuation, 3)) + " dB / decade") + if (ten_db_location > 0 and + twenty_db_location > 0 and + ten_db_location != twenty_db_location): + octave_attenuation, decade_attenuation = self.calculateRolloff( + ten_db_location, twenty_db_location) + self.upper_db_per_octave_label.setText( + f"{round(octave_attenuation, 3)} dB / octave") + self.upper_db_per_decade_label.setText( + f"{round(decade_attenuation, 3)} dB / decade") else: self.upper_db_per_octave_label.setText("Not calculated") self.upper_db_per_decade_label.setText("Not calculated") if upper_cutoff_gain < -4 or lower_cutoff_gain < -4: - self.result_label.setText("Analysis complete (" + str(len(self.app.data)) + " points)\n" + - "Insufficient data for analysis. Increase segment count.") + self.result_label.setText( + f"Analysis complete ({len(self.app.data)} points)\n" + f"Insufficient data for analysis. Increase segment count.") else: - self.result_label.setText("Analysis complete (" + str(len(self.app.data)) + " points)") + self.result_label.setText( + f"Analysis complete ({len(self.app.data)} points)") diff --git a/NanoVNASaver/Analysis/HighPassAnalysis.py b/NanoVNASaver/Analysis/HighPassAnalysis.py index b400690..d5ac5ff 100644 --- a/NanoVNASaver/Analysis/HighPassAnalysis.py +++ b/NanoVNASaver/Analysis/HighPassAnalysis.py @@ -36,7 +36,8 @@ class HighPassAnalysis(Analysis): layout = QtWidgets.QFormLayout() self._widget.setLayout(layout) layout.addRow(QtWidgets.QLabel("High pass filter analysis")) - layout.addRow(QtWidgets.QLabel("Please place " + self.app.markers[0].name + " in the filter passband.")) + layout.addRow(QtWidgets.QLabel( + f"Please place {self.app.markers[0].name} in the filter passband.")) self.result_label = QtWidgets.QLabel() self.cutoff_label = QtWidgets.QLabel() self.six_db_label = QtWidgets.QLabel() @@ -70,7 +71,8 @@ class HighPassAnalysis(Analysis): if pass_band_location < 0: logger.debug("No location for %s", self.app.markers[0].name) - self.result_label.setText("Please place " + self.app.markers[0].name + " in the passband.") + self.result_label.setText( + f"Please place {self.app.markers[0].name } in the passband.") return pass_band_db = self.app.data21[pass_band_location].gain @@ -116,9 +118,9 @@ class HighPassAnalysis(Analysis): cutoff_frequency = self.app.data21[cutoff_location].freq cutoff_gain = self.app.data21[cutoff_location].gain - pass_band_db if cutoff_gain < -4: - logger.debug("Cutoff frequency found at %f dB - insufficient data points for true -3 dB point.", + logger.debug("Cutoff frequency found at %f dB" + " - insufficient data points for true -3 dB point.", cutoff_gain) - logger.debug("Found true cutoff frequency at %d", cutoff_frequency) self.cutoff_label.setText(RFTools.formatFrequency(cutoff_frequency) + @@ -168,12 +170,14 @@ class HighPassAnalysis(Analysis): ten = self.app.data21[ten_db_location].freq twenty = self.app.data21[twenty_db_location].freq sixty_db_frequency = ten * 10 ** (5 * (math.log10(twenty) - math.log10(ten))) - self.sixty_db_label.setText(RFTools.formatFrequency(sixty_db_frequency) + " (derived)") + self.sixty_db_label.setText(RFTools.formatFrequency(sixty_db_frequency) + + " (derived)") else: self.sixty_db_label.setText("Not calculated") if ten_db_location > 0 and twenty_db_location > 0 and ten_db_location != twenty_db_location: - octave_attenuation, decade_attenuation = self.calculateRolloff(ten_db_location, twenty_db_location) + octave_attenuation, decade_attenuation = self.calculateRolloff( + ten_db_location, twenty_db_location) self.db_per_octave_label.setText(str(round(octave_attenuation, 3)) + " dB / octave") self.db_per_decade_label.setText(str(round(decade_attenuation, 3)) + " dB / decade") else: @@ -181,4 +185,3 @@ class HighPassAnalysis(Analysis): self.db_per_decade_label.setText("Not calculated") self.result_label.setText("Analysis complete (" + str(len(self.app.data)) + " points)") - diff --git a/NanoVNASaver/Calibration.py b/NanoVNASaver/Calibration.py index 7815a46..23d8657 100644 --- a/NanoVNASaver/Calibration.py +++ b/NanoVNASaver/Calibration.py @@ -93,8 +93,7 @@ class Calibration: return (False, "All of short, open and load calibration steps" "must be completed for calibration to be applied.") - else: - return False, "All calibration data sets must be the same size." + return False, "All calibration data sets must be the same size." self.frequencies = [int] * len(self.s11short) self.e00 = [np.complex] * len(self.s11short) self.e11 = [np.complex] * len(self.s11short) @@ -308,14 +307,11 @@ class Calibration: if line == ("# Hz ShortR ShortI OpenR OpenI LoadR Load" " ThroughR ThroughI IsolationR IsolationI"): parsed_header = True - continue - else: - # This is some other comment line - continue - if not parsed_header: - logger.warning("Warning: Read line without having read header: %s", line) continue - + if not parsed_header: + logger.warning( + "Warning: Read line without having read header: %s", line) + continue try: if line.count(" ") == 6: freq, shortr, shorti, openr, openi, loadr, loadi = line.split( diff --git a/NanoVNASaver/Charts/CLogMag.py b/NanoVNASaver/Charts/CLogMag.py index 0d3fe5c..865cc9e 100644 --- a/NanoVNASaver/Charts/CLogMag.py +++ b/NanoVNASaver/Charts/CLogMag.py @@ -242,8 +242,10 @@ class CombinedLogMagChart(FrequencyChart): logMag = 20 * math.log10((vswr-1)/(vswr+1)) if self.isInverted: logMag = logMag * -1 - y = self.topMargin + round((self.maxValue - logMag) / self.span * self.chartHeight) - qp.drawLine(self.leftMargin, y, self.leftMargin + self.chartWidth, y) + y = self.topMargin + round((self.maxValue - logMag) / + self.span * self.chartHeight) + qp.drawLine(self.leftMargin, y, + self.leftMargin + self.chartWidth, y) qp.drawText(self.leftMargin + 3, y - 1, "VSWR: " + str(vswr)) if len(self.data11) > 0: @@ -258,7 +260,8 @@ class CombinedLogMagChart(FrequencyChart): pen = QtGui.QPen(c) pen.setWidth(2) qp.setPen(pen) - qp.drawLine(self.leftMargin + self.chartWidth - 20, 9, self.leftMargin + self.chartWidth - 15, 9) + qp.drawLine(self.leftMargin + self.chartWidth - 20, 9, + self.leftMargin + self.chartWidth - 15, 9) if len(self.reference11) > 0: c = QtGui.QColor(self.referenceColor) @@ -272,7 +275,8 @@ class CombinedLogMagChart(FrequencyChart): pen = QtGui.QPen(c) pen.setWidth(2) qp.setPen(pen) - qp.drawLine(self.leftMargin + self.chartWidth - 20, 14, self.leftMargin + self.chartWidth - 15, 14) + qp.drawLine(self.leftMargin + self.chartWidth - 20, 14, + self.leftMargin + self.chartWidth - 15, 14) self.drawData(qp, self.data11, self.sweepColor) self.drawData(qp, self.data21, self.secondarySweepColor) @@ -295,8 +299,7 @@ class CombinedLogMagChart(FrequencyChart): def logMag(self, p: Datapoint) -> float: if self.isInverted: return -p.gain - else: - return p.gain + return p.gain def copy(self): new_chart: LogMagChart = super().copy() diff --git a/NanoVNASaver/Charts/Chart.py b/NanoVNASaver/Charts/Chart.py index 201a515..efd0a8b 100644 --- a/NanoVNASaver/Charts/Chart.py +++ b/NanoVNASaver/Charts/Chart.py @@ -197,18 +197,17 @@ class Chart(QtWidgets.QWidget): def shortenFrequency(frequency: int) -> str: if frequency < 50000: return str(frequency) - elif frequency < 5000000: + if frequency < 5000000: return str(round(frequency / 1000)) + "k" - elif frequency < 50000000: + if frequency < 50000000: return str(round(frequency / 1000000, 2)) + "M" - else: - return str(round(frequency / 1000000, 1)) + "M" + return str(round(frequency / 1000000, 1)) + "M" def mousePressEvent(self, event: QtGui.QMouseEvent) -> None: if event.buttons() == QtCore.Qt.RightButton: event.ignore() return - elif event.buttons() == QtCore.Qt.MiddleButton: + if event.buttons() == QtCore.Qt.MiddleButton: # Drag event event.accept() self.moveStartX = event.x() diff --git a/NanoVNASaver/Charts/Frequency.py b/NanoVNASaver/Charts/Frequency.py index bb594fb..6b28893 100644 --- a/NanoVNASaver/Charts/Frequency.py +++ b/NanoVNASaver/Charts/Frequency.py @@ -62,20 +62,24 @@ class FrequencyChart(Chart): self.action_automatic = QtWidgets.QAction("Automatic") self.action_automatic.setCheckable(True) self.action_automatic.setChecked(True) - self.action_automatic.changed.connect(lambda: self.setFixedSpan(self.action_fixed_span.isChecked())) + self.action_automatic.changed.connect( + lambda: self.setFixedSpan(self.action_fixed_span.isChecked())) self.action_fixed_span = QtWidgets.QAction("Fixed span") self.action_fixed_span.setCheckable(True) - self.action_fixed_span.changed.connect(lambda: self.setFixedSpan(self.action_fixed_span.isChecked())) + self.action_fixed_span.changed.connect( + lambda: self.setFixedSpan(self.action_fixed_span.isChecked())) mode_group.addAction(self.action_automatic) mode_group.addAction(self.action_fixed_span) self.x_menu.addAction(self.action_automatic) self.x_menu.addAction(self.action_fixed_span) self.x_menu.addSeparator() - self.action_set_fixed_start = QtWidgets.QAction("Start (" + Chart.shortenFrequency(self.minFrequency) + ")") + self.action_set_fixed_start = QtWidgets.QAction( + "Start (" + Chart.shortenFrequency(self.minFrequency) + ")") self.action_set_fixed_start.triggered.connect(self.setMinimumFrequency) - self.action_set_fixed_stop = QtWidgets.QAction("Stop (" + Chart.shortenFrequency(self.maxFrequency) + ")") + self.action_set_fixed_stop = QtWidgets.QAction( + "Stop (" + Chart.shortenFrequency(self.maxFrequency) + ")") self.action_set_fixed_stop.triggered.connect(self.setMaximumFrequency) self.x_menu.addAction(self.action_set_fixed_start) @@ -89,8 +93,10 @@ class FrequencyChart(Chart): self.action_set_logarithmic_x.setCheckable(True) frequency_mode_group.addAction(self.action_set_linear_x) frequency_mode_group.addAction(self.action_set_logarithmic_x) - self.action_set_linear_x.triggered.connect(lambda: self.setLogarithmicX(False)) - self.action_set_logarithmic_x.triggered.connect(lambda: self.setLogarithmicX(True)) + self.action_set_linear_x.triggered.connect( + lambda: self.setLogarithmicX(False)) + self.action_set_logarithmic_x.triggered.connect( + lambda: self.setLogarithmicX(True)) self.action_set_linear_x.setChecked(True) self.x_menu.addAction(self.action_set_linear_x) self.x_menu.addAction(self.action_set_logarithmic_x) @@ -99,10 +105,12 @@ class FrequencyChart(Chart): self.y_action_automatic = QtWidgets.QAction("Automatic") self.y_action_automatic.setCheckable(True) self.y_action_automatic.setChecked(True) - self.y_action_automatic.changed.connect(lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())) + self.y_action_automatic.changed.connect( + lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())) self.y_action_fixed_span = QtWidgets.QAction("Fixed span") self.y_action_fixed_span.setCheckable(True) - self.y_action_fixed_span.changed.connect(lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())) + self.y_action_fixed_span.changed.connect( + lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())) mode_group = QtWidgets.QActionGroup(self) mode_group.addAction(self.y_action_automatic) mode_group.addAction(self.y_action_fixed_span) @@ -110,10 +118,12 @@ class FrequencyChart(Chart): self.y_menu.addAction(self.y_action_fixed_span) self.y_menu.addSeparator() - self.action_set_fixed_maximum = QtWidgets.QAction("Maximum (" + str(self.maxDisplayValue) + ")") + self.action_set_fixed_maximum = QtWidgets.QAction( + f"Maximum ({self.maxDisplayValue})") self.action_set_fixed_maximum.triggered.connect(self.setMaximumValue) - self.action_set_fixed_minimum = QtWidgets.QAction("Minimum (" + str(self.minDisplayValue) + ")") + self.action_set_fixed_minimum = QtWidgets.QAction( + f"Minimum ({self.minDisplayValue})") self.action_set_fixed_minimum.triggered.connect(self.setMinimumValue) self.y_menu.addAction(self.action_set_fixed_maximum) @@ -124,15 +134,20 @@ class FrequencyChart(Chart): self.menu.addSeparator() self.menu.addAction(self.action_save_screenshot) self.action_popout = QtWidgets.QAction("Popout chart") - self.action_popout.triggered.connect(lambda: self.popoutRequested.emit(self)) + self.action_popout.triggered.connect( + lambda: self.popoutRequested.emit(self)) self.menu.addAction(self.action_popout) self.setFocusPolicy(QtCore.Qt.ClickFocus) def contextMenuEvent(self, event): - self.action_set_fixed_start.setText("Start (" + Chart.shortenFrequency(self.minFrequency) + ")") - self.action_set_fixed_stop.setText("Stop (" + Chart.shortenFrequency(self.maxFrequency) + ")") - self.action_set_fixed_minimum.setText("Minimum (" + str(self.minDisplayValue) + ")") - self.action_set_fixed_maximum.setText("Maximum (" + str(self.maxDisplayValue) + ")") + self.action_set_fixed_start.setText( + f"Start ({Chart.shortenFrequency(self.minFrequency)})") + self.action_set_fixed_stop.setText( + f"Stop ({Chart.shortenFrequency(self.maxFrequency)})") + self.action_set_fixed_minimum.setText( + f"Minimum ({self.minDisplayValue})") + self.action_set_fixed_maximum.setText( + f"Maximum ({self.maxDisplayValue})") if self.fixedSpan: self.action_fixed_span.setChecked(True) @@ -167,8 +182,9 @@ class FrequencyChart(Chart): self.update() def setMinimumFrequency(self): - min_freq_str, selected = QtWidgets.QInputDialog.getText(self, "Start frequency", - "Set start frequency", text=str(self.minFrequency)) + min_freq_str, selected = QtWidgets.QInputDialog.getText( + self, "Start frequency", + "Set start frequency", text=str(self.minFrequency)) if not selected: return min_freq = RFTools.parseFrequency(min_freq_str) @@ -178,8 +194,9 @@ class FrequencyChart(Chart): self.update() def setMaximumFrequency(self): - max_freq_str, selected = QtWidgets.QInputDialog.getText(self, "Stop frequency", - "Set stop frequency", text=str(self.maxFrequency)) + max_freq_str, selected = QtWidgets.QInputDialog.getText( + self, "Stop frequency", + "Set stop frequency", text=str(self.maxFrequency)) if not selected: return max_freq = RFTools.parseFrequency(max_freq_str) @@ -189,9 +206,10 @@ class FrequencyChart(Chart): self.update() def setMinimumValue(self): - min_val, selected = QtWidgets.QInputDialog.getDouble(self, "Minimum value", - "Set minimum value", value=self.minDisplayValue, - decimals=3) + min_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Minimum value", + "Set minimum value", value=self.minDisplayValue, + decimals=3) if not selected: return if not (self.fixedValues and min_val >= self.maxDisplayValue): @@ -200,9 +218,10 @@ class FrequencyChart(Chart): self.update() def setMaximumValue(self): - max_val, selected = QtWidgets.QInputDialog.getDouble(self, "Maximum value", - "Set maximum value", value=self.maxDisplayValue, - decimals=3) + max_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Maximum value", + "Set maximum value", value=self.maxDisplayValue, + decimals=3) if not selected: return if not (self.fixedValues and max_val <= self.minDisplayValue): @@ -226,43 +245,45 @@ class FrequencyChart(Chart): span = math.log(self.fstop) - math.log(self.fstart) return self.leftMargin +\ round(self.chartWidth * (math.log(d.freq) - math.log(self.fstart)) / span) - else: - return self.leftMargin + round(self.chartWidth * (d.freq - self.fstart) / span) - else: - return math.floor(self.width()/2) + return self.leftMargin + round(self.chartWidth * (d.freq - self.fstart) / span) + return math.floor(self.width()/2) def frequencyAtPosition(self, x, limit=True) -> int: """ Calculates the frequency at a given X-position - :param limit: Determines whether frequencies outside the currently displayed span can be returned. - :param x: The X position to calculate for. - :return: The frequency at the given position, if one exists, or -1 otherwise. If limit is True, and the value - is before or after the chart, returns minimum or maximum frequencies. + :param limit: Determines whether frequencies outside the + currently displayed span can be returned. + :param x: The X position to calculate for. + :return: The frequency at the given position, if one + exists or -1 otherwise. If limit is True, + and the value is before or after the chart, + returns minimum or maximum frequencies. """ if self.fstop - self.fstart > 0: absx = x - self.leftMargin if limit and absx < 0: return self.fstart - elif limit and absx > self.chartWidth: + if limit and absx > self.chartWidth: return self.fstop - elif self.logarithmicX: + if self.logarithmicX: span = math.log(self.fstop) - math.log(self.fstart) step = span/self.chartWidth return round(math.exp(math.log(self.fstart) + absx * step)) - else: - span = self.fstop - self.fstart - step = span/self.chartWidth - return round(self.fstart + absx * step) - else: - return -1 + span = self.fstop - self.fstart + step = span/self.chartWidth + return round(self.fstart + absx * step) + return -1 def valueAtPosition(self, y) -> List[float]: """ Returns the chart-specific value(s) at the specified Y-position :param y: The Y position to calculate for. - :return: A list of the values at the Y-position, either containing a single value, or the two values for the - chart from left to right Y-axis. If no value can be found, returns the empty list. If the frequency - is above or below the chart, returns maximum or minimum values. + :return: A list of the values at the Y-position, either + containing a single value, or the two values for the + chart from left to right Y-axis. If no value can be + found, returns the empty list. If the frequency + is above or below the chart, returns maximum + or minimum values. """ return [] @@ -343,7 +364,7 @@ class FrequencyChart(Chart): self.update() - def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None: + def mouseMoveEvent(self, a0: QtGui.QMouseEvent): if a0.buttons() == QtCore.Qt.RightButton: a0.ignore() return @@ -354,7 +375,8 @@ class FrequencyChart(Chart): dx = self.moveStartX - a0.x() dy = self.moveStartY - a0.y() self.zoomTo(self.leftMargin + dx, self.topMargin + dy, - self.leftMargin + self.chartWidth + dx, self.topMargin + self.chartHeight + dy) + self.leftMargin + self.chartWidth + dx, + self.topMargin + self.chartHeight + dy) self.moveStartX = a0.x() self.moveStartY = a0.y() @@ -372,13 +394,11 @@ class FrequencyChart(Chart): if x == -1: a0.ignore() return - else: - a0.accept() - m = self.getActiveMarker() - if m is not None: - m.setFrequency(str(f)) - m.frequencyInput.setText(str(f)) - return + a0.accept() + m = self.getActiveMarker() + if m is not None: + m.setFrequency(str(f)) + m.frequencyInput.setText(str(f)) def resizeEvent(self, a0: QtGui.QResizeEvent) -> None: self.chartWidth = a0.size().width()-self.rightMargin-self.leftMargin @@ -389,15 +409,19 @@ class FrequencyChart(Chart): qp = QtGui.QPainter(self) self.drawChart(qp) self.drawValues(qp) - if len(self.data) > 0\ - and (self.data[0].freq > self.fstop or self.data[len(self.data)-1].freq < self.fstart) \ - and (len(self.reference) == 0 or self.reference[0].freq > self.fstop or - self.reference[len(self.reference)-1].freq < self.fstart): + if (len(self.data) > 0 and + (self.data[0].freq > self.fstop or + self.data[len(self.data)-1].freq < self.fstart) + and + (len(self.reference) == 0 or + self.reference[0].freq > self.fstop or + self.reference[len(self.reference)-1].freq < self.fstart)): # Data outside frequency range qp.setBackgroundMode(QtCore.Qt.OpaqueMode) qp.setBackground(self.backgroundColor) qp.setPen(self.textColor) - qp.drawText(self.leftMargin + self.chartWidth/2 - 70, self.topMargin + self.chartHeight/2 - 20, + qp.drawText(self.leftMargin + self.chartWidth/2 - 70, + self.topMargin + self.chartHeight/2 - 20, "Data outside frequency span") if self.draggedBox and self.draggedBoxCurrent[0] != -1: dashed_pen = QtGui.QPen(self.foregroundColor, 1, QtCore.Qt.DashLine) @@ -421,7 +445,9 @@ class FrequencyChart(Chart): def drawFrequencyTicks(self, qp): fspan = self.fstop - self.fstart qp.setPen(self.textColor) - qp.drawText(self.leftMargin - 20, self.topMargin + self.chartHeight + 15, Chart.shortenFrequency(self.fstart)) + qp.drawText(self.leftMargin - 20, + self.topMargin + self.chartHeight + 15, + Chart.shortenFrequency(self.fstart)) ticks = math.floor(self.chartWidth / 100) # Number of ticks does not include the origin for i in range(ticks): x = self.leftMargin + round((i + 1) * self.chartWidth / ticks) @@ -433,7 +459,9 @@ class FrequencyChart(Chart): qp.setPen(QtGui.QPen(self.foregroundColor)) qp.drawLine(x, self.topMargin, x, self.topMargin + self.chartHeight + 5) qp.setPen(self.textColor) - qp.drawText(x - 20, self.topMargin + self.chartHeight + 15, Chart.shortenFrequency(freq)) + qp.drawText(x - 20, + self.topMargin + self.chartHeight + 15, + Chart.shortenFrequency(freq)) def drawBands(self, qp, fstart, fstop): qp.setBrush(self.bands.color) @@ -443,20 +471,30 @@ class FrequencyChart(Chart): # The band is entirely within the chart x_start = self.getXPosition(Datapoint(start, 0, 0)) x_end = self.getXPosition(Datapoint(end, 0, 0)) - qp.drawRect(x_start, self.topMargin, x_end - x_start, self.chartHeight) + qp.drawRect(x_start, + self.topMargin, + x_end - x_start, + self.chartHeight) elif fstart < start < fstop: # Only the start of the band is within the chart x_start = self.getXPosition(Datapoint(start, 0, 0)) - qp.drawRect(x_start, self.topMargin, self.leftMargin + self.chartWidth - x_start, self.chartHeight) + qp.drawRect(x_start, + self.topMargin, + self.leftMargin + self.chartWidth - x_start, + self.chartHeight) elif fstart < end < fstop: # Only the end of the band is within the chart x_end = self.getXPosition(Datapoint(end, 0, 0)) - qp.drawRect(self.leftMargin + 1, self.topMargin, x_end - (self.leftMargin + 1), self.chartHeight) + qp.drawRect(self.leftMargin + 1, + self.topMargin, + x_end - (self.leftMargin + 1), + self.chartHeight) elif start < fstart < fstop < end: # All the chart is in a band, we won't show it(?) pass - def drawData(self, qp: QtGui.QPainter, data: List[Datapoint], color: QtGui.QColor, y_function=None): + def drawData(self, qp: QtGui.QPainter, data: List[Datapoint], + color: QtGui.QColor, y_function=None): if y_function is None: y_function = self.getYPosition pen = QtGui.QPen(color) @@ -464,9 +502,9 @@ class FrequencyChart(Chart): line_pen = QtGui.QPen(color) line_pen.setWidth(self.lineThickness) qp.setPen(pen) - for i in range(len(data)): - x = self.getXPosition(data[i]) - y = y_function(data[i]) + for i, d in enumerate(data): + x = self.getXPosition(d) + y = y_function(d) if y is None: continue if self.isPlotable(x, y): @@ -527,8 +565,7 @@ class FrequencyChart(Chart): num = np.dot(dap, dp) result = (num / denom.astype(float)) * db + p3 return result[0], result[1] - else: - return x, y + return x, y def copy(self): new_chart: FrequencyChart = super().copy() @@ -558,8 +595,10 @@ class FrequencyChart(Chart): m = self.getActiveMarker() if m is not None and a0.modifiers() == QtCore.Qt.NoModifier: if a0.key() == QtCore.Qt.Key_Down or a0.key() == QtCore.Qt.Key_Left: - m.frequencyInput.keyPressEvent(QtGui.QKeyEvent(a0.type(), QtCore.Qt.Key_Down, a0.modifiers())) + m.frequencyInput.keyPressEvent(QtGui.QKeyEvent( + a0.type(), QtCore.Qt.Key_Down, a0.modifiers())) elif a0.key() == QtCore.Qt.Key_Up or a0.key() == QtCore.Qt.Key_Right: - m.frequencyInput.keyPressEvent(QtGui.QKeyEvent(a0.type(), QtCore.Qt.Key_Up, a0.modifiers())) + m.frequencyInput.keyPressEvent(QtGui.QKeyEvent( + a0.type(), QtCore.Qt.Key_Up, a0.modifiers())) else: super().keyPressEvent(a0) diff --git a/NanoVNASaver/Charts/LogMag.py b/NanoVNASaver/Charts/LogMag.py index a73797b..b461c5a 100644 --- a/NanoVNASaver/Charts/LogMag.py +++ b/NanoVNASaver/Charts/LogMag.py @@ -217,8 +217,7 @@ class LogMagChart(FrequencyChart): def logMag(self, p: Datapoint) -> float: if self.isInverted: return -p.gain - else: - return p.gain + return p.gain def copy(self): new_chart: LogMagChart = super().copy() diff --git a/NanoVNASaver/Charts/Permeability.py b/NanoVNASaver/Charts/Permeability.py index f35573e..69238d5 100644 --- a/NanoVNASaver/Charts/Permeability.py +++ b/NanoVNASaver/Charts/Permeability.py @@ -47,8 +47,11 @@ class PermeabilityChart(FrequencyChart): # Set up size policy and palette # - self.setMinimumSize(self.chartWidth + self.leftMargin + self.rightMargin, self.chartHeight + 40) - self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)) + self.setMinimumSize(self.chartWidth + self.leftMargin + + self.rightMargin, self.chartHeight + 40) + self.setSizePolicy(QtWidgets.QSizePolicy( + QtWidgets.QSizePolicy.MinimumExpanding, + QtWidgets.QSizePolicy.MinimumExpanding)) pal = QtGui.QPalette() pal.setColor(QtGui.QPalette.Background, self.backgroundColor) self.setPalette(pal) @@ -167,12 +170,15 @@ class PermeabilityChart(FrequencyChart): for i in range(horizontal_ticks): y = self.topMargin + round(i * self.chartHeight / horizontal_ticks) qp.setPen(QtGui.QPen(self.foregroundColor)) - qp.drawLine(self.leftMargin - 5, y, self.leftMargin + self.chartWidth + 5, y) + qp.drawLine(self.leftMargin - 5, y, + self.leftMargin + self.chartWidth + 5, y) qp.setPen(QtGui.QPen(self.textColor)) val = Value(self.valueAtPosition(y)[0], fmt=fmt) qp.drawText(3, y + 4, str(val)) - qp.drawText(3, self.chartHeight + self.topMargin, str(Value(min_val, fmt=fmt))) + qp.drawText(3, + self.chartHeight + self.topMargin, + str(Value(min_val, fmt=fmt))) self.drawFrequencyTicks(qp) @@ -189,7 +195,9 @@ class PermeabilityChart(FrequencyChart): c.setAlpha(255) pen.setColor(c) qp.setPen(pen) - qp.drawLine(self.leftMargin + self.chartWidth, 9, self.leftMargin + self.chartWidth + 5, 9) + qp.drawLine( + self.leftMargin + self.chartWidth, 9, + self.leftMargin + self.chartWidth + 5, 9) primary_pen.setWidth(self.pointSize) secondary_pen.setWidth(self.pointSize) @@ -250,7 +258,8 @@ class PermeabilityChart(FrequencyChart): pen = QtGui.QPen(c) pen.setWidth(2) qp.setPen(pen) - qp.drawLine(self.leftMargin + self.chartWidth, 14, self.leftMargin + self.chartWidth + 5, 14) + qp.drawLine(self.leftMargin + self.chartWidth, 14, + self.leftMargin + self.chartWidth + 5, 14) for i in range(len(self.reference)): if self.reference[i].freq < fstart or self.reference[i].freq > fstop: @@ -312,9 +321,11 @@ class PermeabilityChart(FrequencyChart): span = math.log(self.max) - math.log(min_val) else: return -1 - return self.topMargin + round((math.log(self.max) - math.log(im)) / span * self.chartHeight) - else: - return self.topMargin + round((self.max - im) / self.span * self.chartHeight) + return self.topMargin + round( + (math.log(self.max) - math.log(im)) / + span * self.chartHeight) + return self.topMargin + round( + (self.max - im) / self.span * self.chartHeight) def getReYPosition(self, d: Datapoint) -> int: re = d.impedance().real @@ -325,9 +336,11 @@ class PermeabilityChart(FrequencyChart): span = math.log(self.max) - math.log(min_val) else: return -1 - return self.topMargin + round((math.log(self.max) - math.log(re)) / span * self.chartHeight) - else: - return self.topMargin + round((self.max - re) / self.span * self.chartHeight) + return self.topMargin + round( + (math.log(self.max) - math.log(re)) / + span * self.chartHeight) + return self.topMargin + round( + (self.max - re) / self.span * self.chartHeight) def valueAtPosition(self, y) -> List[float]: absy = y - self.topMargin diff --git a/NanoVNASaver/Charts/Polar.py b/NanoVNASaver/Charts/Polar.py index ca3fd79..7abc1fc 100644 --- a/NanoVNASaver/Charts/Polar.py +++ b/NanoVNASaver/Charts/Polar.py @@ -48,21 +48,24 @@ class PolarChart(SquareChart): qp.setPen(QtGui.QPen(self.textColor)) qp.drawText(3, 15, self.name) qp.setPen(QtGui.QPen(self.foregroundColor)) - qp.drawEllipse(QtCore.QPoint(centerX, centerY), int(self.chartWidth/2), int(self.chartHeight/2)) - qp.drawEllipse(QtCore.QPoint(centerX, centerY), int(self.chartWidth/4), int(self.chartHeight/4)) - qp.drawLine(centerX - int(self.chartWidth/2), centerY, centerX + int(self.chartWidth/2), centerY) - qp.drawLine(centerX, centerY - int(self.chartHeight/2), centerX, centerY + int(self.chartHeight/2)) - + qp.drawEllipse(QtCore.QPoint(centerX, centerY), + int(self.chartWidth / 2), + int(self.chartHeight / 2)) + qp.drawEllipse(QtCore.QPoint(centerX, centerY), + int(self.chartWidth / 4), + int(self.chartHeight / 4)) + qp.drawLine(centerX - int(self.chartWidth / 2), centerY, + centerX + int(self.chartWidth / 2), centerY) + qp.drawLine(centerX, centerY - int(self.chartHeight / 2), + centerX, centerY + int(self.chartHeight / 2)) qp.drawLine(centerX + int(self.chartHeight / 2 * math.sin(math.pi / 4)), centerY + int(self.chartHeight / 2 * math.sin(math.pi / 4)), centerX - int(self.chartHeight / 2 * math.sin(math.pi / 4)), centerY - int(self.chartHeight / 2 * math.sin(math.pi / 4))) - qp.drawLine(centerX + int(self.chartHeight / 2 * math.sin(math.pi / 4)), centerY - int(self.chartHeight / 2 * math.sin(math.pi / 4)), centerX - int(self.chartHeight / 2 * math.sin(math.pi / 4)), centerY + int(self.chartHeight / 2 * math.sin(math.pi / 4))) - self.drawTitle(qp) def drawValues(self, qp: QtGui.QPainter): @@ -90,10 +93,10 @@ class PolarChart(SquareChart): qp.setPen(pen) if len(self.data) > 0: fstart = self.data[0].freq - fstop = self.data[len(self.data)-1].freq + fstop = self.data[len(self.data) -1].freq else: fstart = self.reference[0].freq - fstop = self.reference[len(self.reference)-1].freq + fstop = self.reference[len(self.reference) - 1].freq for i in range(len(self.reference)): data = self.reference[i] if data.freq < fstart or data.freq > fstop: diff --git a/NanoVNASaver/Charts/RI.py b/NanoVNASaver/Charts/RI.py index d73c46b..d4c75c5 100644 --- a/NanoVNASaver/Charts/RI.py +++ b/NanoVNASaver/Charts/RI.py @@ -57,10 +57,12 @@ class RealImaginaryChart(FrequencyChart): self.y_action_automatic = QtWidgets.QAction("Automatic") self.y_action_automatic.setCheckable(True) self.y_action_automatic.setChecked(True) - self.y_action_automatic.changed.connect(lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())) + self.y_action_automatic.changed.connect( + lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())) self.y_action_fixed_span = QtWidgets.QAction("Fixed span") self.y_action_fixed_span.setCheckable(True) - self.y_action_fixed_span.changed.connect(lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())) + self.y_action_fixed_span.changed.connect( + lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())) mode_group = QtWidgets.QActionGroup(self) mode_group.addAction(self.y_action_automatic) mode_group.addAction(self.y_action_fixed_span) @@ -68,17 +70,25 @@ class RealImaginaryChart(FrequencyChart): self.y_menu.addAction(self.y_action_fixed_span) self.y_menu.addSeparator() - self.action_set_fixed_maximum_real = QtWidgets.QAction("Maximum R (" + str(self.maxDisplayReal) + ")") - self.action_set_fixed_maximum_real.triggered.connect(self.setMaximumRealValue) + self.action_set_fixed_maximum_real = QtWidgets.QAction( + f"Maximum R ({self.maxDisplayReal})") + self.action_set_fixed_maximum_real.triggered.connect( + self.setMaximumRealValue) - self.action_set_fixed_minimum_real = QtWidgets.QAction("Minimum R (" + str(self.minDisplayReal) + ")") - self.action_set_fixed_minimum_real.triggered.connect(self.setMinimumRealValue) + self.action_set_fixed_minimum_real = QtWidgets.QAction( + f"Minimum R ({self.minDisplayReal})") + self.action_set_fixed_minimum_real.triggered.connect( + self.setMinimumRealValue) - self.action_set_fixed_maximum_imag = QtWidgets.QAction("Maximum jX (" + str(self.maxDisplayImag) + ")") - self.action_set_fixed_maximum_imag.triggered.connect(self.setMaximumImagValue) + self.action_set_fixed_maximum_imag = QtWidgets.QAction( + f"Maximum jX ({self.maxDisplayImag})") + self.action_set_fixed_maximum_imag.triggered.connect( + self.setMaximumImagValue) - self.action_set_fixed_minimum_imag = QtWidgets.QAction("Minimum jX (" + str(self.minDisplayImag) + ")") - self.action_set_fixed_minimum_imag.triggered.connect(self.setMinimumImagValue) + self.action_set_fixed_minimum_imag = QtWidgets.QAction( + f"Minimum jX ({self.minDisplayImag})") + self.action_set_fixed_minimum_imag.triggered.connect( + self.setMinimumImagValue) self.y_menu.addAction(self.action_set_fixed_maximum_real) self.y_menu.addAction(self.action_set_fixed_minimum_real) @@ -90,9 +100,13 @@ class RealImaginaryChart(FrequencyChart): # Set up size policy and palette # - self.setMinimumSize(self.chartWidth + self.leftMargin + self.rightMargin, self.chartHeight + 40) - self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, - QtWidgets.QSizePolicy.MinimumExpanding)) + self.setMinimumSize( + self.chartWidth + self.leftMargin + self.rightMargin, + self.chartHeight + 40) + self.setSizePolicy( + QtWidgets.QSizePolicy( + QtWidgets.QSizePolicy.MinimumExpanding, + QtWidgets.QSizePolicy.MinimumExpanding)) pal = QtGui.QPalette() pal.setColor(QtGui.QPalette.Background, self.backgroundColor) self.setPalette(pal) @@ -109,13 +123,19 @@ class RealImaginaryChart(FrequencyChart): def drawChart(self, qp: QtGui.QPainter): qp.setPen(QtGui.QPen(self.textColor)) - qp.drawText(self.leftMargin + 5, 15, self.name + " (\N{OHM SIGN})") + qp.drawText(self.leftMargin + 5, 15, + f"{self.name} (\N{OHM SIGN})") qp.drawText(10, 15, "R") qp.drawText(self.leftMargin + self.chartWidth + 10, 15, "X") qp.setPen(QtGui.QPen(self.foregroundColor)) - qp.drawLine(self.leftMargin, self.topMargin - 5, self.leftMargin, self.topMargin + self.chartHeight + 5) - qp.drawLine(self.leftMargin-5, self.topMargin + self.chartHeight, - self.leftMargin + self.chartWidth + 5, self.topMargin + self.chartHeight) + qp.drawLine(self.leftMargin, + self.topMargin - 5, + self.leftMargin, + self.topMargin + self.chartHeight + 5) + qp.drawLine(self.leftMargin-5, + self.topMargin + self.chartHeight, + self.leftMargin + self.chartWidth + 5, + self.topMargin + self.chartHeight) self.drawTitle(qp) def drawValues(self, qp: QtGui.QPainter): @@ -180,7 +200,8 @@ class RealImaginaryChart(FrequencyChart): if im < min_imag: min_imag = im - max_real = max(8, math.ceil(max_real)) # Always have at least 8 numbered horizontal lines + # Always have at least 8 numbered horizontal lines + max_real = max(8, math.ceil(max_real)) min_real = max(0, math.floor(min_real)) # Negative real resistance? No. max_imag = math.ceil(max_imag) min_imag = math.floor(min_imag) @@ -238,7 +259,9 @@ class RealImaginaryChart(FrequencyChart): qp.drawText(self.leftMargin + self.chartWidth + 8, y + 4, str(round(im, 1))) qp.drawText(3, self.chartHeight + self.topMargin, str(round(min_real, 1))) - qp.drawText(self.leftMargin + self.chartWidth + 8, self.chartHeight + self.topMargin, str(round(min_imag, 1))) + qp.drawText(self.leftMargin + self.chartWidth + 8, + self.chartHeight + self.topMargin, + str(round(min_imag, 1))) self.drawFrequencyTicks(qp) @@ -255,7 +278,8 @@ class RealImaginaryChart(FrequencyChart): c.setAlpha(255) pen.setColor(c) qp.setPen(pen) - qp.drawLine(self.leftMargin + self.chartWidth, 9, self.leftMargin + self.chartWidth + 5, 9) + qp.drawLine(self.leftMargin + self.chartWidth, 9, + self.leftMargin + self.chartWidth + 5, 9) primary_pen.setWidth(self.pointSize) secondary_pen.setWidth(self.pointSize) @@ -316,7 +340,8 @@ class RealImaginaryChart(FrequencyChart): pen = QtGui.QPen(c) pen.setWidth(2) qp.setPen(pen) - qp.drawLine(self.leftMargin + self.chartWidth, 14, self.leftMargin + self.chartWidth + 5, 14) + qp.drawLine(self.leftMargin + self.chartWidth, 14, + self.leftMargin + self.chartWidth + 5, 14) for i in range(len(self.reference)): if self.reference[i].freq < fstart or self.reference[i].freq > fstop: @@ -422,9 +447,10 @@ class RealImaginaryChart(FrequencyChart): return nearest def setMinimumRealValue(self): - min_val, selected = QtWidgets.QInputDialog.getDouble(self, "Minimum real value", - "Set minimum real value", value=self.minDisplayReal, - decimals=2) + min_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Minimum real value", + "Set minimum real value", value=self.minDisplayReal, + decimals=2) if not selected: return if not (self.fixedValues and min_val >= self.maxDisplayReal): @@ -433,9 +459,10 @@ class RealImaginaryChart(FrequencyChart): self.update() def setMaximumRealValue(self): - max_val, selected = QtWidgets.QInputDialog.getDouble(self, "Maximum real value", - "Set maximum real value", value=self.maxDisplayReal, - decimals=2) + max_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Maximum real value", + "Set maximum real value", value=self.maxDisplayReal, + decimals=2) if not selected: return if not (self.fixedValues and max_val <= self.minDisplayReal): @@ -444,9 +471,10 @@ class RealImaginaryChart(FrequencyChart): self.update() def setMinimumImagValue(self): - min_val, selected = QtWidgets.QInputDialog.getDouble(self, "Minimum imaginary value", - "Set minimum imaginary value", value=self.minDisplayImag, - decimals=2) + min_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Minimum imaginary value", + "Set minimum imaginary value", value=self.minDisplayImag, + decimals=2) if not selected: return if not (self.fixedValues and min_val >= self.maxDisplayImag): @@ -455,9 +483,10 @@ class RealImaginaryChart(FrequencyChart): self.update() def setMaximumImagValue(self): - max_val, selected = QtWidgets.QInputDialog.getDouble(self, "Maximum imaginary value", - "Set maximum imaginary value", value=self.maxDisplayImag, - decimals=2) + max_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Maximum imaginary value", + "Set maximum imaginary value", value=self.maxDisplayImag, + decimals=2) if not selected: return if not (self.fixedValues and max_val <= self.minDisplayImag): @@ -467,18 +496,25 @@ class RealImaginaryChart(FrequencyChart): def setFixedValues(self, fixed_values: bool): self.fixedValues = fixed_values - if fixed_values and (self.minDisplayReal >= self.maxDisplayReal or self.minDisplayImag > self.maxDisplayImag): + if (fixed_values and + (self.minDisplayReal >= self.maxDisplayReal or + self.minDisplayImag > self.maxDisplayImag)): self.fixedValues = False self.y_action_automatic.setChecked(True) self.y_action_fixed_span.setChecked(False) self.update() def contextMenuEvent(self, event): - self.action_set_fixed_start.setText("Start (" + Chart.shortenFrequency(self.minFrequency) + ")") - self.action_set_fixed_stop.setText("Stop (" + Chart.shortenFrequency(self.maxFrequency) + ")") - self.action_set_fixed_minimum_real.setText("Minimum R (" + str(self.minDisplayReal) + ")") - self.action_set_fixed_maximum_real.setText("Maximum R (" + str(self.maxDisplayReal) + ")") - self.action_set_fixed_minimum_imag.setText("Minimum jX (" + str(self.minDisplayImag) + ")") - self.action_set_fixed_maximum_imag.setText("Maximum jX (" + str(self.maxDisplayImag) + ")") - + self.action_set_fixed_start.setText( + f"Start ({Chart.shortenFrequency(self.minFrequency)})") + self.action_set_fixed_stop.setText( + f"Stop ({Chart.shortenFrequency(self.maxFrequency)})") + self.action_set_fixed_minimum_real.setText( + f"Minimum R ({self.minDisplayReal})") + self.action_set_fixed_maximum_real.setText( + f"Maximum R ({self.maxDisplayReal})") + self.action_set_fixed_minimum_imag.setText( + f"Minimum jX ({self.minDisplayImag})") + self.action_set_fixed_maximum_imag.setText( + f"Maximum jX ({self.maxDisplayImag})") self.menu.exec_(event.globalPos()) diff --git a/NanoVNASaver/Charts/SParam.py b/NanoVNASaver/Charts/SParam.py index 82e130b..7c7d071 100644 --- a/NanoVNASaver/Charts/SParam.py +++ b/NanoVNASaver/Charts/SParam.py @@ -172,8 +172,7 @@ class SParameterChart(FrequencyChart): def logMag(self, p: Datapoint) -> float: if self.isInverted: return -p.gain - else: - return p.gain + return p.gain def copy(self): new_chart: LogMagChart = super().copy() diff --git a/NanoVNASaver/Charts/Smith.py b/NanoVNASaver/Charts/Smith.py index af5654e..babbb82 100644 --- a/NanoVNASaver/Charts/Smith.py +++ b/NanoVNASaver/Charts/Smith.py @@ -50,8 +50,14 @@ class SmithChart(SquareChart): qp.setPen(QtGui.QPen(self.textColor)) qp.drawText(3, 15, self.name) qp.setPen(QtGui.QPen(self.foregroundColor)) - qp.drawEllipse(QtCore.QPoint(centerX, centerY), int(self.chartWidth/2), int(self.chartHeight/2)) - qp.drawLine(centerX - int(self.chartWidth/2), centerY, centerX + int(self.chartWidth/2), centerY) + qp.drawEllipse(QtCore.QPoint(centerX, centerY), + int(self.chartWidth / 2), + int(self.chartHeight / 2)) + qp.drawLine( + centerX - int(self.chartWidth / 2), + centerY, + centerX + int(self.chartWidth / 2), + centerY) qp.drawEllipse(QtCore.QPoint(centerX + int(self.chartWidth/4), centerY), int(self.chartWidth/4), int(self.chartHeight/4)) # Re(Z) = 1 @@ -75,16 +81,24 @@ class SmithChart(SquareChart): int(self.chartHeight/2), 90*16, 127*16) # Im(Z) = -2 qp.drawArc(centerX + int(self.chartWidth/4), centerY, int(self.chartWidth/2), -int(self.chartHeight/2), -90*16, -127*16) # Im(Z) = 2 - qp.drawArc(centerX, centerY, self.chartWidth, self.chartHeight, 90*16, 90*16) # Im(Z) = -1 - qp.drawArc(centerX, centerY, self.chartWidth, -self.chartHeight, -90 * 16, -90 * 16) # Im(Z) = 1 - qp.drawArc(centerX - int(self.chartWidth/2), centerY, - self.chartWidth*2, self.chartHeight*2, int(99.5*16), int(43.5*16)) # Im(Z) = -0.5 - qp.drawArc(centerX - int(self.chartWidth/2), centerY, - self.chartWidth*2, -self.chartHeight*2, int(-99.5 * 16), int(-43.5 * 16)) # Im(Z) = 0.5 + qp.drawArc(centerX, centerY, + self.chartWidth, self.chartHeight, + 90*16, 90*16) # Im(Z) = -1 + qp.drawArc(centerX, centerY, + self.chartWidth, -self.chartHeight, + -90 * 16, -90 * 16) # Im(Z) = 1 + qp.drawArc(centerX - int(self.chartWidth / 2), centerY, + self.chartWidth * 2, self.chartHeight * 2, + int(99.5*16), int(43.5*16)) # Im(Z) = -0.5 + qp.drawArc(centerX - int(self.chartWidth / 2), centerY, + self.chartWidth * 2, -self.chartHeight * 2, + int(-99.5 * 16), int(-43.5 * 16)) # Im(Z) = 0.5 + qp.drawArc(centerX - self.chartWidth * 2, centerY, + self.chartWidth * 5, self.chartHeight * 5, + int(93.85 * 16), int(18.85 * 16)) # Im(Z) = -0.2 qp.drawArc(centerX - self.chartWidth*2, centerY, - self.chartWidth*5, self.chartHeight*5, int(93.85*16), int(18.85*16)) # Im(Z) = -0.2 - qp.drawArc(centerX - self.chartWidth*2, centerY, - self.chartWidth*5, -self.chartHeight*5, int(-93.85 * 16), int(-18.85 * 16)) # Im(Z) = 0.2 + self.chartWidth*5, -self.chartHeight*5, + int(-93.85 * 16), int(-18.85 * 16)) # Im(Z) = 0.2 self.drawTitle(qp) @@ -95,7 +109,9 @@ class SmithChart(SquareChart): gamma = (swr - 1)/(swr + 1) r = round(gamma * self.chartWidth/2) qp.drawEllipse(QtCore.QPoint(centerX, centerY), r, r) - qp.drawText(QtCore.QRect(centerX - 50, centerY - 4 + r, 100, 20), QtCore.Qt.AlignCenter, str(swr)) + qp.drawText( + QtCore.QRect(centerX - 50, centerY - 4 + r, 100, 20), + QtCore.Qt.AlignCenter, str(swr)) def drawValues(self, qp: QtGui.QPainter): if len(self.data) == 0 and len(self.reference) == 0: diff --git a/NanoVNASaver/Charts/Square.py b/NanoVNASaver/Charts/Square.py index 6d04d60..6430ba3 100644 --- a/NanoVNASaver/Charts/Square.py +++ b/NanoVNASaver/Charts/Square.py @@ -1,4 +1,5 @@ -# NanoVNASaver - a python program to view and export Touchstone data from a NanoVNA +# NanoVNASaver +# A python program to view and export Touchstone data from a NanoVNA # Copyright (C) 2019. Rune B. Broberg # # This program is free software: you can redistribute it and/or modify @@ -13,27 +14,20 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import collections -import math -from typing import List, Set -import numpy as np import logging -from scipy import signal -from PyQt5 import QtWidgets, QtGui, QtCore -from PyQt5.QtCore import pyqtSignal +from PyQt5 import QtWidgets, QtGui from NanoVNASaver.Charts.Chart import Chart -from NanoVNASaver.RFTools import Datapoint, RFTools -from NanoVNASaver.SITools import Format, Value -from NanoVNASaver.Marker import Marker -logger = logging.getLogger(__name__) +logger = logging.getLogger(__name__) class SquareChart(Chart): def __init__(self, name): super().__init__(name) - sizepolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.MinimumExpanding) + sizepolicy = QtWidgets.QSizePolicy( + QtWidgets.QSizePolicy.Fixed, + QtWidgets.QSizePolicy.MinimumExpanding) self.setSizePolicy(sizepolicy) self.chartWidth = self.width()-40 self.chartHeight = self.height()-40 @@ -47,5 +41,3 @@ class SquareChart(Chart): min_dimension = min(a0.size().height(), a0.size().width()) self.chartWidth = self.chartHeight = min_dimension - 40 self.update() - - diff --git a/NanoVNASaver/Charts/TDR.py b/NanoVNASaver/Charts/TDR.py index ebd76fc..4f62dbb 100644 --- a/NanoVNASaver/Charts/TDR.py +++ b/NanoVNASaver/Charts/TDR.py @@ -43,8 +43,10 @@ class TDRChart(Chart): self.bottomMargin = 25 self.topMargin = 20 self.setMinimumSize(300, 300) - self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, - QtWidgets.QSizePolicy.MinimumExpanding)) + self.setSizePolicy( + QtWidgets.QSizePolicy( + QtWidgets.QSizePolicy.MinimumExpanding, + QtWidgets.QSizePolicy.MinimumExpanding)) pal = QtGui.QPalette() pal.setColor(QtGui.QPalette.Background, self.backgroundColor) self.setPalette(pal) @@ -62,20 +64,24 @@ class TDRChart(Chart): self.action_automatic = QtWidgets.QAction("Automatic") self.action_automatic.setCheckable(True) self.action_automatic.setChecked(True) - self.action_automatic.changed.connect(lambda: self.setFixedSpan(self.action_fixed_span.isChecked())) + self.action_automatic.changed.connect( + lambda: self.setFixedSpan(self.action_fixed_span.isChecked())) self.action_fixed_span = QtWidgets.QAction("Fixed span") self.action_fixed_span.setCheckable(True) - self.action_fixed_span.changed.connect(lambda: self.setFixedSpan(self.action_fixed_span.isChecked())) + self.action_fixed_span.changed.connect( + lambda: self.setFixedSpan(self.action_fixed_span.isChecked())) self.mode_group.addAction(self.action_automatic) self.mode_group.addAction(self.action_fixed_span) self.x_menu.addAction(self.action_automatic) self.x_menu.addAction(self.action_fixed_span) self.x_menu.addSeparator() - self.action_set_fixed_start = QtWidgets.QAction("Start (" + str(self.minDisplayLength) + ")") + self.action_set_fixed_start = QtWidgets.QAction( + f"Start ({self.minDisplayLength})") self.action_set_fixed_start.triggered.connect(self.setMinimumLength) - self.action_set_fixed_stop = QtWidgets.QAction("Stop (" + str(self.maxDisplayLength) + ")") + self.action_set_fixed_stop = QtWidgets.QAction( + f"Stop ({self.maxDisplayLength})") self.action_set_fixed_stop.triggered.connect(self.setMaximumLength) self.x_menu.addAction(self.action_set_fixed_start) @@ -86,20 +92,24 @@ class TDRChart(Chart): self.y_action_automatic = QtWidgets.QAction("Automatic") self.y_action_automatic.setCheckable(True) self.y_action_automatic.setChecked(True) - self.y_action_automatic.changed.connect(lambda: self.setFixedValues(self.y_action_fixed.isChecked())) + self.y_action_automatic.changed.connect( + lambda: self.setFixedValues(self.y_action_fixed.isChecked())) self.y_action_fixed = QtWidgets.QAction("Fixed") self.y_action_fixed.setCheckable(True) - self.y_action_fixed.changed.connect(lambda: self.setFixedValues(self.y_action_fixed.isChecked())) + self.y_action_fixed.changed.connect( + lambda: self.setFixedValues(self.y_action_fixed.isChecked())) self.y_mode_group.addAction(self.y_action_automatic) self.y_mode_group.addAction(self.y_action_fixed) self.y_menu.addAction(self.y_action_automatic) self.y_menu.addAction(self.y_action_fixed) self.y_menu.addSeparator() - self.y_action_set_fixed_maximum = QtWidgets.QAction("Maximum (" + str(self.maxImpedance) + ")") + self.y_action_set_fixed_maximum = QtWidgets.QAction( + f"Maximum ({self.maxImpedance})") self.y_action_set_fixed_maximum.triggered.connect(self.setMaximumImpedance) - self.y_action_set_fixed_minimum = QtWidgets.QAction("Minimum (" + str(self.minImpedance) + ")") + self.y_action_set_fixed_minimum = QtWidgets.QAction( + f"Minimum ({self.minImpedance})") self.y_action_set_fixed_minimum.triggered.connect(self.setMinimumImpedance) self.y_menu.addAction(self.y_action_set_fixed_maximum) @@ -110,17 +120,22 @@ class TDRChart(Chart): self.menu.addSeparator() self.menu.addAction(self.action_save_screenshot) self.action_popout = QtWidgets.QAction("Popout chart") - self.action_popout.triggered.connect(lambda: self.popoutRequested.emit(self)) + self.action_popout.triggered.connect( + lambda: self.popoutRequested.emit(self)) self.menu.addAction(self.action_popout) self.chartWidth = self.width() - self.leftMargin - self.rightMargin self.chartHeight = self.height() - self.bottomMargin - self.topMargin def contextMenuEvent(self, event): - self.action_set_fixed_start.setText("Start (" + str(self.minDisplayLength) + ")") - self.action_set_fixed_stop.setText("Stop (" + str(self.maxDisplayLength) + ")") - self.y_action_set_fixed_minimum.setText("Minimum (" + str(self.minImpedance) + ")") - self.y_action_set_fixed_maximum.setText("Maximum (" + str(self.maxImpedance) + ")") + self.action_set_fixed_start.setText( + f"Start ({self.minDisplayLength})") + self.action_set_fixed_stop.setText( + f"Stop ({self.maxDisplayLength})") + self.y_action_set_fixed_minimum.setText( + f"Minimum ({self.minImpedance})") + self.y_action_set_fixed_maximum.setText( + f"Maximum ({self.maxImpedance})") self.menu.exec_(event.globalPos()) def isPlotable(self, x, y): @@ -141,9 +156,10 @@ class TDRChart(Chart): self.update() def setMinimumLength(self): - min_val, selected = QtWidgets.QInputDialog.getDouble(self, "Start length (m)", - "Set start length (m)", value=self.minDisplayLength, - min=0, decimals=1) + min_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Start length (m)", + "Set start length (m)", value=self.minDisplayLength, + min=0, decimals=1) if not selected: return if not (self.fixedSpan and min_val >= self.maxDisplayLength): @@ -152,9 +168,10 @@ class TDRChart(Chart): self.update() def setMaximumLength(self): - max_val, selected = QtWidgets.QInputDialog.getDouble(self, "Stop length (m)", - "Set stop length (m)", value=self.minDisplayLength, - min=0.1, decimals=1) + max_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Stop length (m)", + "Set stop length (m)", value=self.minDisplayLength, + min=0.1, decimals=1) if not selected: return if not (self.fixedSpan and max_val <= self.minDisplayLength): @@ -167,10 +184,11 @@ class TDRChart(Chart): self.update() def setMinimumImpedance(self): - min_val, selected = QtWidgets.QInputDialog.getDouble(self, "Minimum impedance (\N{OHM SIGN})", - "Set minimum impedance (\N{OHM SIGN})", - value=self.minDisplayLength, - min=0, decimals=1) + min_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Minimum impedance (\N{OHM SIGN})", + "Set minimum impedance (\N{OHM SIGN})", + value=self.minDisplayLength, + min=0, decimals=1) if not selected: return if not (self.fixedValues and min_val >= self.maxImpedance): @@ -179,10 +197,11 @@ class TDRChart(Chart): self.update() def setMaximumImpedance(self): - max_val, selected = QtWidgets.QInputDialog.getDouble(self, "Maximum impedance (\N{OHM SIGN})", - "Set maximum impedance (\N{OHM SIGN})", - value=self.minDisplayLength, - min=0.1, decimals=1) + max_val, selected = QtWidgets.QInputDialog.getDouble( + self, "Maximum impedance (\N{OHM SIGN})", + "Set maximum impedance (\N{OHM SIGN})", + value=self.minDisplayLength, + min=0.1, decimals=1) if not selected: return if not (self.fixedValues and max_val <= self.minImpedance): @@ -213,8 +232,8 @@ class TDRChart(Chart): dx = self.moveStartX - a0.x() dy = self.moveStartY - a0.y() self.zoomTo(self.leftMargin + dx, self.topMargin + dy, - self.leftMargin + self.chartWidth + dx, self.topMargin + self.chartHeight + dy) - + self.leftMargin + self.chartWidth + dx, + self.topMargin + self.chartHeight + dy) self.moveStartX = a0.x() self.moveStartY = a0.y() return @@ -256,12 +275,16 @@ class TDRChart(Chart): height = self.height() - self.bottomMargin - self.topMargin qp.setPen(QtGui.QPen(self.foregroundColor)) - qp.drawLine(self.leftMargin - 5, self.height() - self.bottomMargin, self.width() - self.rightMargin, + qp.drawLine(self.leftMargin - 5, + self.height() - self.bottomMargin, + self.width() - self.rightMargin, self.height() - self.bottomMargin) - qp.drawLine(self.leftMargin, self.topMargin - 5, self.leftMargin, self.height() - self.bottomMargin + 5) - - ticks = math.floor((self.width() - self.leftMargin)/100) # Number of ticks does not include the origin - + qp.drawLine(self.leftMargin, + self.topMargin - 5, + self.leftMargin, + self.height() - self.bottomMargin + 5) + # Number of ticks does not include the origin + ticks = math.floor((self.width() - self.leftMargin) / 100) self.drawTitle(qp) if len(self.tdrWindow.td) > 0: @@ -285,8 +308,12 @@ class TDRChart(Chart): max_impedance = max(0.1, self.maxImpedance) else: # TODO: Limit the search to the selected span? - min_impedance = max(0, np.min(self.tdrWindow.step_response_Z) / 1.05) - max_impedance = min(1000, np.max(self.tdrWindow.step_response_Z) * 1.05) + min_impedance = max( + 0, + np.min(self.tdrWindow.step_response_Z) / 1.05) + max_impedance = min( + 1000, + np.max(self.tdrWindow.step_response_Z) * 1.05) y_step = np.max(self.tdrWindow.td) * 1.1 / height y_impedance_step = (max_impedance - min_impedance) / height @@ -296,16 +323,21 @@ class TDRChart(Chart): qp.setPen(QtGui.QPen(self.foregroundColor)) qp.drawLine(x, self.topMargin, x, self.topMargin + height) qp.setPen(QtGui.QPen(self.textColor)) - qp.drawText(x - 15, self.topMargin + height + 15, - str(round(self.tdrWindow.distance_axis[min_index + - int((x - self.leftMargin) * x_step) - 1]/2, - 1) - ) - + "m") + qp.drawText( + x - 15, + self.topMargin + height + 15, + str(round( + self.tdrWindow.distance_axis[ + min_index + + int((x - self.leftMargin) * x_step) - 1] / 2, + 1)) + "m") qp.setPen(QtGui.QPen(self.textColor)) - qp.drawText(self.leftMargin - 10, self.topMargin + height + 15, - str(round(self.tdrWindow.distance_axis[min_index]/2, 1)) + "m") + qp.drawText( + self.leftMargin - 10, + self.topMargin + height + 15, + str(round(self.tdrWindow.distance_axis[min_index] / 2, + 1)) + "m") y_ticks = math.floor(height / 60) y_tick_step = height/y_ticks @@ -343,21 +375,29 @@ class TDRChart(Chart): qp.drawPoint(x, y) id_max = np.argmax(self.tdrWindow.td) - max_point = QtCore.QPoint(self.leftMargin + int((id_max - min_index) / x_step), - (self.topMargin + height) - int(self.tdrWindow.td[id_max] / y_step)) + max_point = QtCore.QPoint( + self.leftMargin + int((id_max - min_index) / x_step), + (self.topMargin + height) - int(self.tdrWindow.td[id_max] / y_step)) qp.setPen(self.markers[0].color) qp.drawEllipse(max_point, 2, 2) qp.setPen(self.textColor) qp.drawText(max_point.x() - 10, max_point.y() - 5, - str(round(self.tdrWindow.distance_axis[id_max]/2, 2)) + "m") + str(round(self.tdrWindow.distance_axis[id_max] / 2, + 2)) + "m") if self.markerLocation != -1: - marker_point = QtCore.QPoint(self.leftMargin + int((self.markerLocation - min_index) / x_step), - (self.topMargin + height) - int(self.tdrWindow.td[self.markerLocation] / y_step)) + marker_point = QtCore.QPoint( + self.leftMargin + + int((self.markerLocation - min_index) / x_step), + (self.topMargin + height) - + int(self.tdrWindow.td[self.markerLocation] / y_step)) qp.setPen(self.textColor) qp.drawEllipse(marker_point, 2, 2) - qp.drawText(marker_point.x() - 10, marker_point.y() - 5, - str(round(self.tdrWindow.distance_axis[self.markerLocation] / 2, 2)) + "m") + qp.drawText( + marker_point.x() - 10, + marker_point.y() - 5, + str(round(self.tdrWindow.distance_axis[self.markerLocation] / 2, + 2)) + "m") if self.draggedBox and self.draggedBoxCurrent[0] != -1: dashed_pen = QtGui.QPen(self.foregroundColor, 1, QtCore.Qt.DashLine) @@ -377,12 +417,15 @@ class TDRChart(Chart): min_impedance = self.minImpedance max_impedance = self.maxImpedance else: - min_impedance = max(0, np.min(self.tdrWindow.step_response_Z) / 1.05) - max_impedance = min(1000, np.max(self.tdrWindow.step_response_Z) * 1.05) + min_impedance = max( + 0, + np.min(self.tdrWindow.step_response_Z) / 1.05) + max_impedance = min( + 1000, + np.max(self.tdrWindow.step_response_Z) * 1.05) y_step = (max_impedance - min_impedance) / height return y_step * absy + min_impedance - else: - return 0 + return 0 def lengthAtPosition(self, x, limit=True): if len(self.tdrWindow.td) > 0: @@ -394,15 +437,15 @@ class TDRChart(Chart): x_step = (max_length - min_length) / width else: min_length = 0 - max_length = self.tdrWindow.distance_axis[math.ceil(len(self.tdrWindow.distance_axis) / 2)]/2 + max_length = self.tdrWindow.distance_axis[ + math.ceil(len(self.tdrWindow.distance_axis) / 2)] / 2 x_step = max_length / width if limit and absx < 0: return min_length if limit and absx > width: return max_length return absx * x_step + min_length - else: - return 0 + return 0 def zoomTo(self, x1, y1, x2, y2): logger.debug("Zoom to (x,y) by (x,y): (%d, %d) by (%d, %d)", x1, y1, x2, y2) @@ -453,7 +496,8 @@ class TDRChart(Chart): absy = max(0, a0.y() - self.topMargin) ratiox = absx/chart_width ratioy = absy/chart_height - # TODO: Change zoom to center on the mouse if possible, or extend box to the side that has room if not. + # TODO: Change zoom to center on the mouse if possible, + # or extend box to the side that has room if not. p1x = int(self.leftMargin + ratiox * zoomx) p1y = int(self.topMargin + ratioy * zoomy) p2x = int(self.leftMargin + chart_width - (1 - ratiox) * zoomx) diff --git a/NanoVNASaver/Charts/VSWR.py b/NanoVNASaver/Charts/VSWR.py index c6792d1..3a52264 100644 --- a/NanoVNASaver/Charts/VSWR.py +++ b/NanoVNASaver/Charts/VSWR.py @@ -187,8 +187,7 @@ class VSWRChart(FrequencyChart): return ( self.topMargin + round((math.log(self.maxVSWR) - math.log(vswr)) / span * self.chartHeight)) - else: - return self.topMargin + round((self.maxVSWR - vswr) / self.span * self.chartHeight) + return self.topMargin + round((self.maxVSWR - vswr) / self.span * self.chartHeight) def getYPosition(self, d: Datapoint) -> int: return self.getYPositionFromValue(d.vswr) diff --git a/NanoVNASaver/Hardware/Hardware.py b/NanoVNASaver/Hardware/Hardware.py index 388803a..457c7d2 100644 --- a/NanoVNASaver/Hardware/Hardware.py +++ b/NanoVNASaver/Hardware/Hardware.py @@ -98,12 +98,11 @@ def get_VNA(app, serial_port: serial.Serial) -> 'VNA': if firmware.find("NanoVNA-F") > 0: logger.info("Type: NanoVNA-F") return NanoVNA_F(app, serial_port) - elif firmware.find("NanoVNA") > 0: + if firmware.find("NanoVNA") > 0: logger.info("Type: Generic NanoVNA") return NanoVNA(app, serial_port) - else: - logger.warning("Did not recognize NanoVNA type from firmware.") - return NanoVNA(app, serial_port) + logger.warning("Did not recognize NanoVNA type from firmware.") + return NanoVNA(app, serial_port) def detect_version(serialPort: serial.Serial) -> str: diff --git a/NanoVNASaver/Hardware/NanoVNA_F.py b/NanoVNASaver/Hardware/NanoVNA_F.py index 2fefc81..9dc4583 100644 --- a/NanoVNASaver/Hardware/NanoVNA_F.py +++ b/NanoVNASaver/Hardware/NanoVNA_F.py @@ -58,17 +58,32 @@ class NanoVNA_F(NanoVNA): unwrapped_array = np.empty( self.screenwidth*self.screenheight, dtype=np.uint32) - for y in range(self.screenheight//2): - for x in range(self.screenwidth//2): - unwrapped_array[2 * x + 2 * y * self.screenwidth] = rgba_array[x + y * self.screenwidth] - unwrapped_array[(2 * x) + 1 + 2 * y * self.screenwidth] = \ - rgba_array[x + (self.screenheight//2 + y) * self.screenwidth] - unwrapped_array[2 * x + (2 * y + 1) * self.screenwidth] = \ - rgba_array[x + self.screenwidth//2 + y * self.screenwidth] - unwrapped_array[(2 * x) + 1 + (2 * y + 1) * self.screenwidth] = \ - rgba_array[x + self.screenwidth//2 + (self.screenheight//2 + y) * self.screenwidth] + for y in range(self.screenheight // 2): + for x in range(self.screenwidth // 2): + unwrapped_array[ + 2 * x + 2 * y * self.screenwidth + ] = rgba_array[x + y * self.screenwidth] + unwrapped_array[ + (2 * x) + 1 + 2 * y * self.screenwidth + ] = rgba_array[ + x + (self.screenheight//2 + y) * self.screenwidth + ] + unwrapped_array[ + 2 * x + (2 * y + 1) * self.screenwidth + ] = rgba_array[ + x + self.screenwidth // 2 + y * self.screenwidth + ] + unwrapped_array[ + (2 * x) + 1 + (2 * y + 1) * self.screenwidth + ] = rgba_array[ + x + self.screenwidth // 2 + + (self.screenheight//2 + y) * self.screenwidth + ] - image = QtGui.QImage(unwrapped_array, self.screenwidth, self.screenheight, QtGui.QImage.Format_ARGB32) + image = QtGui.QImage( + unwrapped_array, + self.screenwidth, self.screenheight, + QtGui.QImage.Format_ARGB32) logger.debug("Captured screenshot") return QtGui.QPixmap(image) except serial.SerialException as exc: diff --git a/NanoVNASaver/Hardware/VNA.py b/NanoVNASaver/Hardware/VNA.py index 5e8c83d..1da2f49 100644 --- a/NanoVNASaver/Hardware/VNA.py +++ b/NanoVNASaver/Hardware/VNA.py @@ -99,13 +99,13 @@ class VNA: data = self.serial.readline().decode('ascii') result += data except serial.SerialException as exc: - logger.exception("Exception while reading firmware data: %s", exc) + logger.exception( + "Exception while reading firmware data: %s", exc) finally: self.app.serialLock.release() return result - else: - logger.error("Unable to acquire serial lock to read firmware.") - return "" + logger.error("Unable to acquire serial lock to read firmware.") + return "" def readFromCommand(self, command) -> str: if self.app.serialLock.acquire(): @@ -122,13 +122,13 @@ class VNA: data = self.serial.readline().decode('ascii') result += data except serial.SerialException as exc: - logger.exception("Exception while reading %s: %s", command, exc) + logger.exception( + "Exception while reading %s: %s", command, exc) finally: self.app.serialLock.release() return result - else: - logger.error("Unable to acquire serial lock to read %s", command) - return "" + logger.error("Unable to acquire serial lock to read %s", command) + return "" def readValues(self, value) -> List[str]: logger.debug("VNA reading %s", value) @@ -147,26 +147,31 @@ class VNA: result += data values = result.split("\r\n") except serial.SerialException as exc: - logger.exception("Exception while reading %s: %s", value, exc) + logger.exception( + "Exception while reading %s: %s", value, exc) return [] finally: self.app.serialLock.release() - logger.debug("VNA done reading %s (%d values)", value, len(values)-2) + logger.debug( + "VNA done reading %s (%d values)", + value, len(values)-2) return values[1:-1] - else: - logger.error("Unable to acquire serial lock to read %s", value) - return [] + logger.error("Unable to acquire serial lock to read %s", value) + return [] def writeSerial(self, command): if not self.serial.is_open: - logger.warning("Writing without serial port being opened (%s)", command) + logger.warning("Writing without serial port being opened (%s)", + command) return if self.app.serialLock.acquire(): try: self.serial.write(str(command + "\r").encode('ascii')) self.serial.readline() except serial.SerialException as exc: - logger.exception("Exception while writing to serial port (%s): %s", command, exc) + logger.exception( + "Exception while writing to serial port (%s): %s", + command, exc) finally: self.app.serialLock.release() return diff --git a/NanoVNASaver/Marker/Settings.py b/NanoVNASaver/Marker/Settings.py index cb889f6..e1b173b 100644 --- a/NanoVNASaver/Marker/Settings.py +++ b/NanoVNASaver/Marker/Settings.py @@ -49,7 +49,8 @@ class MarkerSettingsWindow(QtWidgets.QWidget): settings_group_box = QtWidgets.QGroupBox("Settings") settings_group_box_layout = QtWidgets.QFormLayout(settings_group_box) self.checkboxColouredMarker = QtWidgets.QCheckBox("Colored marker name") - self.checkboxColouredMarker.setChecked(self.app.settings.value("ColoredMarkerNames", True, bool)) + self.checkboxColouredMarker.setChecked( + self.app.settings.value("ColoredMarkerNames", True, bool)) self.checkboxColouredMarker.stateChanged.connect(self.updateMarker) settings_group_box_layout.addRow(self.checkboxColouredMarker) diff --git a/NanoVNASaver/Marker/Widget.py b/NanoVNASaver/Marker/Widget.py index 4d91e8e..cc86fc9 100644 --- a/NanoVNASaver/Marker/Widget.py +++ b/NanoVNASaver/Marker/Widget.py @@ -117,9 +117,9 @@ class Marker(QtCore.QObject, Value): self.layout.addWidget(self.btnColorPicker) self.layout.addWidget(self.isMouseControlledRadioButton) - ################################################################################################################ + ############################################################### # Data display layout - ################################################################################################################ + ############################################################### self.group_box = QtWidgets.QGroupBox(self.name) self.group_box.setMaximumWidth(340) diff --git a/NanoVNASaver/Settings.py b/NanoVNASaver/Settings.py index b58acc9..2c35731 100644 --- a/NanoVNASaver/Settings.py +++ b/NanoVNASaver/Settings.py @@ -88,13 +88,11 @@ class BandsModel(QtCore.QAbstractTableModel): if (role == QtCore.Qt.DisplayRole or role == QtCore.Qt.ItemDataRole or role == QtCore.Qt.EditRole): return QtCore.QVariant(self.bands[index.row()][index.column()]) - elif role == QtCore.Qt.TextAlignmentRole: + if role == QtCore.Qt.TextAlignmentRole: if index.column() == 0: return QtCore.QVariant(QtCore.Qt.AlignCenter) - else: - return QtCore.QVariant(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - else: - return QtCore.QVariant() + return QtCore.QVariant(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) + return QtCore.QVariant() def setData(self, index: QModelIndex, value: typing.Any, role: int = ...) -> bool: if role == QtCore.Qt.EditRole and index.isValid(): @@ -128,18 +126,18 @@ class BandsModel(QtCore.QAbstractTableModel): self.saveSettings() return True - def headerData(self, section: int, orientation: QtCore.Qt.Orientation, role: int = ...): - if role == QtCore.Qt.DisplayRole and orientation == QtCore.Qt.Horizontal: + def headerData(self, section: int, + orientation: QtCore.Qt.Orientation, role: int = ...): + if (role == QtCore.Qt.DisplayRole and + orientation == QtCore.Qt.Horizontal): if section == 0: return "Band" if section == 1: return "Start (Hz)" if section == 2: return "End (Hz)" - else: - return "Invalid" - else: - super().headerData(section, orientation, role) + return "Invalid" + super().headerData(section, orientation, role) def flags(self, index: QModelIndex) -> QtCore.Qt.ItemFlags: if index.isValid(): @@ -147,8 +145,7 @@ class BandsModel(QtCore.QAbstractTableModel): QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - else: - super().flags(index) + super().flags(index) def setColor(self, color): self.color = color diff --git a/NanoVNASaver/Windows/CalibrationSettings.py b/NanoVNASaver/Windows/CalibrationSettings.py index 6f4a2f2..46e8b00 100644 --- a/NanoVNASaver/Windows/CalibrationSettings.py +++ b/NanoVNASaver/Windows/CalibrationSettings.py @@ -236,10 +236,8 @@ class CalibrationWindow(QtWidgets.QWidget): if response == QtWidgets.QMessageBox.Yes: self.app.settings.setValue("ExpertCalibrationUser", True) return True - else: - return False - else: - return True + return False + return True def manualSaveShort(self): if self.checkExpertUser(): @@ -722,6 +720,8 @@ class CalibrationWindow(QtWidgets.QWidget): def automaticCalibrationStep(self): if self.nextStep == -1: self.app.worker.signals.finished.disconnect(self.automaticCalibrationStep) + return + if self.nextStep == 0: # Short self.saveShort() @@ -743,11 +743,10 @@ class CalibrationWindow(QtWidgets.QWidget): self.app.worker.signals.finished.disconnect( self.automaticCalibrationStep) return - else: - self.app.sweep() - return + self.app.sweep() + return - elif self.nextStep == 1: + if self.nextStep == 1: # Open self.saveOpen() self.nextStep = 2 @@ -765,9 +764,8 @@ class CalibrationWindow(QtWidgets.QWidget): self.app.worker.signals.finished.disconnect( self.automaticCalibrationStep) return - else: - self.app.sweep() - return + self.app.sweep() + return if self.nextStep == 2: # Load @@ -789,32 +787,31 @@ class CalibrationWindow(QtWidgets.QWidget): self.app.worker.signals.finished.disconnect(self.automaticCalibrationStep) self.btn_automatic.setDisabled(False) return - elif response != QtWidgets.QMessageBox.Yes: + if response != QtWidgets.QMessageBox.Yes: self.btn_automatic.setDisabled(False) self.nextStep = -1 self.app.worker.signals.finished.disconnect(self.automaticCalibrationStep) return - else: - isolation_step = QtWidgets.QMessageBox( - QtWidgets.QMessageBox.Information, - "Calibrate isolation", - "Please connect the \"load\" standard to port 1 of the NanoVNA.\n\n" - "If available, also connect a load standard to port 0.\n\n" - "Press Ok when you are ready to continue.", - QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) - response = isolation_step.exec() - if response != QtWidgets.QMessageBox.Ok: - self.btn_automatic.setDisabled(False) - self.nextStep = -1 - self.app.worker.signals.finished.disconnect( - self.automaticCalibrationStep) - return - else: - self.app.sweep() - return + isolation_step = QtWidgets.QMessageBox( + QtWidgets.QMessageBox.Information, + "Calibrate isolation", + "Please connect the \"load\" standard to port 1 of the NanoVNA.\n\n" + "If available, also connect a load standard to port 0.\n\n" + "Press Ok when you are ready to continue.", + QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) - elif self.nextStep == 3: + response = isolation_step.exec() + if response != QtWidgets.QMessageBox.Ok: + self.btn_automatic.setDisabled(False) + self.nextStep = -1 + self.app.worker.signals.finished.disconnect( + self.automaticCalibrationStep) + return + self.app.sweep() + return + + if self.nextStep == 3: # Isolation self.saveIsolation() self.nextStep = 4 @@ -833,11 +830,10 @@ class CalibrationWindow(QtWidgets.QWidget): self.app.worker.signals.finished.disconnect( self.automaticCalibrationStep) return - else: - self.app.sweep() - return + self.app.sweep() + return - elif self.nextStep == 4: + if self.nextStep == 4: # Done self.saveThrough() apply_step = QtWidgets.QMessageBox( @@ -854,11 +850,9 @@ class CalibrationWindow(QtWidgets.QWidget): self.app.worker.signals.finished.disconnect( self.automaticCalibrationStep) return - else: - self.calculate() - self.btn_automatic.setDisabled(False) - self.nextStep = -1 - self.app.worker.signals.finished.disconnect( - self.automaticCalibrationStep) - return - return + self.calculate() + self.btn_automatic.setDisabled(False) + self.nextStep = -1 + self.app.worker.signals.finished.disconnect( + self.automaticCalibrationStep) + return diff --git a/NanoVNASaver/Windows/DisplaySettings.py b/NanoVNASaver/Windows/DisplaySettings.py index 6f489d0..808d11b 100644 --- a/NanoVNASaver/Windows/DisplaySettings.py +++ b/NanoVNASaver/Windows/DisplaySettings.py @@ -18,7 +18,7 @@ from typing import List from PyQt5 import QtWidgets, QtCore, QtGui -from NanoVNASaver.Windows.Bands import BandsWindow +from NanoVNASaver.Windows.Bands import BandsWindow from NanoVNASaver.Windows.MarkerSettings import MarkerSettingsWindow from NanoVNASaver.Marker import Marker logger = logging.getLogger(__name__) @@ -73,18 +73,21 @@ class DisplaySettingsWindow(QtWidgets.QWidget): self.btnColorPicker = QtWidgets.QPushButton("█") self.btnColorPicker.setFixedWidth(20) - self.sweepColor = self.app.settings.value("SweepColor", defaultValue=QtGui.QColor(160, 140, 20, 128), - type=QtGui.QColor) + self.sweepColor = self.app.settings.value( + "SweepColor", defaultValue=QtGui.QColor(160, 140, 20, 128), + type=QtGui.QColor) self.setSweepColor(self.sweepColor) self.btnColorPicker.clicked.connect(lambda: self.setSweepColor( - QtWidgets.QColorDialog.getColor(self.sweepColor, options=QtWidgets.QColorDialog.ShowAlphaChannel))) + QtWidgets.QColorDialog.getColor( + self.sweepColor, options=QtWidgets.QColorDialog.ShowAlphaChannel))) display_options_layout.addRow("Sweep color", self.btnColorPicker) self.btnSecondaryColorPicker = QtWidgets.QPushButton("█") self.btnSecondaryColorPicker.setFixedWidth(20) self.secondarySweepColor = self.app.settings.value("SecondarySweepColor", - defaultValue=QtGui.QColor(20, 160, 140, 128), + defaultValue=QtGui.QColor( + 20, 160, 140, 128), type=QtGui.QColor) self.setSecondarySweepColor(self.secondarySweepColor) self.btnSecondaryColorPicker.clicked.connect(lambda: self.setSecondarySweepColor( @@ -95,25 +98,32 @@ class DisplaySettingsWindow(QtWidgets.QWidget): self.btnReferenceColorPicker = QtWidgets.QPushButton("█") self.btnReferenceColorPicker.setFixedWidth(20) - self.referenceColor = self.app.settings.value("ReferenceColor", defaultValue=QtGui.QColor(0, 0, 255, 48), - type=QtGui.QColor) + self.referenceColor = self.app.settings.value( + "ReferenceColor", defaultValue=QtGui.QColor(0, 0, 255, 48), + type=QtGui.QColor) self.setReferenceColor(self.referenceColor) self.btnReferenceColorPicker.clicked.connect(lambda: self.setReferenceColor( - QtWidgets.QColorDialog.getColor(self.referenceColor, options=QtWidgets.QColorDialog.ShowAlphaChannel))) + QtWidgets.QColorDialog.getColor( + self.referenceColor, options=QtWidgets.QColorDialog.ShowAlphaChannel))) display_options_layout.addRow("Reference color", self.btnReferenceColorPicker) self.btnSecondaryReferenceColorPicker = QtWidgets.QPushButton("█") self.btnSecondaryReferenceColorPicker.setFixedWidth(20) - self.secondaryReferenceColor = self.app.settings.value("SecondaryReferenceColor", - defaultValue=QtGui.QColor(0, 0, 255, 48), - type=QtGui.QColor) + self.secondaryReferenceColor = self.app.settings.value( + "SecondaryReferenceColor", + defaultValue=QtGui.QColor(0, 0, 255, 48), + type=QtGui.QColor) self.setSecondaryReferenceColor(self.secondaryReferenceColor) - self.btnSecondaryReferenceColorPicker.clicked.connect(lambda: self.setSecondaryReferenceColor( - QtWidgets.QColorDialog.getColor(self.secondaryReferenceColor, - options=QtWidgets.QColorDialog.ShowAlphaChannel))) + self.btnSecondaryReferenceColorPicker.clicked.connect( + lambda: self.setSecondaryReferenceColor( + QtWidgets.QColorDialog.getColor( + self.secondaryReferenceColor, + options=QtWidgets.QColorDialog.ShowAlphaChannel))) - display_options_layout.addRow("Second reference color", self.btnSecondaryReferenceColorPicker) + display_options_layout.addRow( + "Second reference color", + self.btnSecondaryReferenceColorPicker) self.pointSizeInput = QtWidgets.QSpinBox() pointsize = self.app.settings.value("PointSize", 2, int) @@ -347,7 +357,8 @@ class DisplaySettingsWindow(QtWidgets.QWidget): chart00_selection.setCurrentText(chart00) else: chart00_selection.setCurrentText("S11 Smith Chart") - chart00_selection.currentTextChanged.connect(lambda: self.changeChart(0, 0, chart00_selection.currentText())) + chart00_selection.currentTextChanged.connect( + lambda: self.changeChart(0, 0, chart00_selection.currentText())) charts_layout.addWidget(chart00_selection, 0, 0) chart01_selection = QtWidgets.QComboBox() @@ -357,7 +368,8 @@ class DisplaySettingsWindow(QtWidgets.QWidget): chart01_selection.setCurrentText(chart01) else: chart01_selection.setCurrentText("S11 Return Loss") - chart01_selection.currentTextChanged.connect(lambda: self.changeChart(0, 1, chart01_selection.currentText())) + chart01_selection.currentTextChanged.connect( + lambda: self.changeChart(0, 1, chart01_selection.currentText())) charts_layout.addWidget(chart01_selection, 0, 1) chart02_selection = QtWidgets.QComboBox() @@ -367,7 +379,8 @@ class DisplaySettingsWindow(QtWidgets.QWidget): chart02_selection.setCurrentText(chart02) else: chart02_selection.setCurrentText("None") - chart02_selection.currentTextChanged.connect(lambda: self.changeChart(0, 2, chart02_selection.currentText())) + chart02_selection.currentTextChanged.connect( + lambda: self.changeChart(0, 2, chart02_selection.currentText())) charts_layout.addWidget(chart02_selection, 0, 2) chart10_selection = QtWidgets.QComboBox() @@ -377,7 +390,8 @@ class DisplaySettingsWindow(QtWidgets.QWidget): chart10_selection.setCurrentText(chart10) else: chart10_selection.setCurrentText("S21 Polar Plot") - chart10_selection.currentTextChanged.connect(lambda: self.changeChart(1, 0, chart10_selection.currentText())) + chart10_selection.currentTextChanged.connect( + lambda: self.changeChart(1, 0, chart10_selection.currentText())) charts_layout.addWidget(chart10_selection, 1, 0) chart11_selection = QtWidgets.QComboBox() @@ -387,7 +401,8 @@ class DisplaySettingsWindow(QtWidgets.QWidget): chart11_selection.setCurrentText(chart11) else: chart11_selection.setCurrentText("S21 Gain") - chart11_selection.currentTextChanged.connect(lambda: self.changeChart(1, 1, chart11_selection.currentText())) + chart11_selection.currentTextChanged.connect( + lambda: self.changeChart(1, 1, chart11_selection.currentText())) charts_layout.addWidget(chart11_selection, 1, 1) chart12_selection = QtWidgets.QComboBox() @@ -397,7 +412,8 @@ class DisplaySettingsWindow(QtWidgets.QWidget): chart12_selection.setCurrentText(chart12) else: chart12_selection.setCurrentText("None") - chart12_selection.currentTextChanged.connect(lambda: self.changeChart(1, 2, chart12_selection.currentText())) + chart12_selection.currentTextChanged.connect( + lambda: self.changeChart(1, 2, chart12_selection.currentText())) charts_layout.addWidget(chart12_selection, 1, 2) self.changeChart(0, 0, chart00_selection.currentText()) @@ -407,24 +423,34 @@ class DisplaySettingsWindow(QtWidgets.QWidget): self.changeChart(1, 1, chart11_selection.currentText()) self.changeChart(1, 2, chart12_selection.currentText()) - self.backgroundColor = self.app.settings.value("BackgroundColor", defaultValue=QtGui.QColor("white"), - type=QtGui.QColor) - self.foregroundColor = self.app.settings.value("ForegroundColor", defaultValue=QtGui.QColor("lightgray"), - type=QtGui.QColor) - self.textColor = self.app.settings.value("TextColor", defaultValue=QtGui.QColor("black"), - type=QtGui.QColor) - self.bandsColor = self.app.settings.value("BandsColor", defaultValue=QtGui.QColor(128, 128, 128, 48), - type=QtGui.QColor) + self.backgroundColor = self.app.settings.value( + "BackgroundColor", defaultValue=QtGui.QColor("white"), + type=QtGui.QColor) + self.foregroundColor = self.app.settings.value( + "ForegroundColor", defaultValue=QtGui.QColor("lightgray"), + type=QtGui.QColor) + self.textColor = self.app.settings.value( + "TextColor", defaultValue=QtGui.QColor("black"), + type=QtGui.QColor) + self.bandsColor = self.app.settings.value( + "BandsColor", defaultValue=QtGui.QColor(128, 128, 128, 48), + type=QtGui.QColor) self.app.bands.color = self.bandsColor - self.vswrColor = self.app.settings.value("VSWRColor", defaultValue=QtGui.QColor(192, 0, 0, 128), - type=QtGui.QColor) + self.vswrColor = self.app.settings.value( + "VSWRColor", defaultValue=QtGui.QColor(192, 0, 0, 128), + type=QtGui.QColor) - self.dark_mode_option.setChecked(self.app.settings.value("DarkMode", False, bool)) - self.show_lines_option.setChecked(self.app.settings.value("ShowLines", False, bool)) - self.show_marker_number_option.setChecked(self.app.settings.value("ShowMarkerNumbers", False, bool)) - self.filled_marker_option.setChecked(self.app.settings.value("FilledMarkers", False, bool)) + self.dark_mode_option.setChecked( + self.app.settings.value("DarkMode", False, bool)) + self.show_lines_option.setChecked( + self.app.settings.value("ShowLines", False, bool)) + self.show_marker_number_option.setChecked( + self.app.settings.value("ShowMarkerNumbers", False, bool)) + self.filled_marker_option.setChecked( + self.app.settings.value("FilledMarkers", False, bool)) - if self.app.settings.value("UseCustomColors", defaultValue=False, type=bool): + if self.app.settings.value("UseCustomColors", + defaultValue=False, type=bool): self.dark_mode_option.setDisabled(True) self.dark_mode_option.setChecked(False) self.use_custom_colors.setChecked(True) @@ -713,8 +739,8 @@ class DisplaySettingsWindow(QtWidgets.QWidget): label.hide() def addVSWRMarker(self): - value, selected = QtWidgets.QInputDialog.getDouble(self, "Add VSWR Marker", - "VSWR value to show:", min=1.001, decimals=3) + value, selected = QtWidgets.QInputDialog.getDouble( + self, "Add VSWR Marker", "VSWR value to show:", min=1.001, decimals=3) if selected: self.vswrMarkers.append(value) if self.vswr_marker_dropdown.itemText(0) == "None": @@ -738,4 +764,3 @@ class DisplaySettingsWindow(QtWidgets.QWidget): self.app.settings.setValue("VSWRMarkers", self.vswrMarkers) for c in self.app.s11charts: c.removeSWRMarker(value) - diff --git a/NanoVNASaver/Windows/MarkerSettings.py b/NanoVNASaver/Windows/MarkerSettings.py index cb889f6..e1b173b 100644 --- a/NanoVNASaver/Windows/MarkerSettings.py +++ b/NanoVNASaver/Windows/MarkerSettings.py @@ -49,7 +49,8 @@ class MarkerSettingsWindow(QtWidgets.QWidget): settings_group_box = QtWidgets.QGroupBox("Settings") settings_group_box_layout = QtWidgets.QFormLayout(settings_group_box) self.checkboxColouredMarker = QtWidgets.QCheckBox("Colored marker name") - self.checkboxColouredMarker.setChecked(self.app.settings.value("ColoredMarkerNames", True, bool)) + self.checkboxColouredMarker.setChecked( + self.app.settings.value("ColoredMarkerNames", True, bool)) self.checkboxColouredMarker.stateChanged.connect(self.updateMarker) settings_group_box_layout.addRow(self.checkboxColouredMarker)