From 21e85bdb4908678bab2f747f0feeb8ac575b1b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20M=C3=BCller?= Date: Tue, 1 Aug 2023 12:42:38 +0200 Subject: [PATCH] fix swwep update crash #668 (#669) --- .gitignore | 1 + nanovna-saver.py | 4 +-- src/NanoVNASaver/Controls/SweepControl.py | 8 ++--- src/NanoVNASaver/Hardware/JNCRadio_VNA_3G.py | 2 +- src/NanoVNASaver/Hardware/SV4401A.py | 2 +- src/NanoVNASaver/Hardware/SV6301A.py | 2 +- src/NanoVNASaver/Marker/Values.py | 4 +-- src/NanoVNASaver/NanoVNASaver.py | 10 ++----- src/NanoVNASaver/Settings/Sweep.py | 30 +++++++++---------- src/NanoVNASaver/Version.py | 17 +++++------ src/NanoVNASaver/Windows/About.py | 6 ++-- .../Windows/CalibrationSettings.py | 18 +++++++---- src/NanoVNASaver/Windows/DeviceSettings.py | 17 +++++++---- src/NanoVNASaver/Windows/DisplaySettings.py | 2 +- 14 files changed, 64 insertions(+), 59 deletions(-) diff --git a/.gitignore b/.gitignore index c4421e9..8125cfa 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ docs/_build/* cover/* MANIFEST **/_version.py +.flatpak-builder/* # Per-project virtualenvs .venv*/ diff --git a/nanovna-saver.py b/nanovna-saver.py index 21f81a5..baa34ae 100755 --- a/nanovna-saver.py +++ b/nanovna-saver.py @@ -26,12 +26,12 @@ import sys src = os.path.join(os.path.dirname(__file__), "src") if os.path.exists(src): - sys.path.insert(0, src) + sys.path.insert(0, src) # pylint: disable-next=wrong-import-position import NanoVNASaver.__main__ # The traditional test does not make sense here. -assert __name__ == '__main__' +assert __name__ == "__main__" NanoVNASaver.__main__.main() diff --git a/src/NanoVNASaver/Controls/SweepControl.py b/src/NanoVNASaver/Controls/SweepControl.py index ba35735..8a5b489 100644 --- a/src/NanoVNASaver/Controls/SweepControl.py +++ b/src/NanoVNASaver/Controls/SweepControl.py @@ -217,8 +217,8 @@ class SweepControl(Control): def update_sweep(self): self.app.sweep.update( - start = self.get_start(), - end = self.get_end(), - segments = self.get_segments(), - points = self.app.vna.datapoints, + start=self.get_start(), + end=self.get_end(), + segments=self.get_segments(), + points=self.app.vna.datapoints, ) diff --git a/src/NanoVNASaver/Hardware/JNCRadio_VNA_3G.py b/src/NanoVNASaver/Hardware/JNCRadio_VNA_3G.py index 9f5357f..1c05f06 100644 --- a/src/NanoVNASaver/Hardware/JNCRadio_VNA_3G.py +++ b/src/NanoVNASaver/Hardware/JNCRadio_VNA_3G.py @@ -41,7 +41,7 @@ class JNCRadio_VNA_3G(NanoVNA): def getScreenshot(self) -> QPixmap: logger.debug("Capturing screenshot...") - self.serial.timeout=8 + self.serial.timeout = 8 if not self.connected(): return QPixmap() try: diff --git a/src/NanoVNASaver/Hardware/SV4401A.py b/src/NanoVNASaver/Hardware/SV4401A.py index ca5f279..1b430a2 100644 --- a/src/NanoVNASaver/Hardware/SV4401A.py +++ b/src/NanoVNASaver/Hardware/SV4401A.py @@ -41,7 +41,7 @@ class SV4401A(NanoVNA): def getScreenshot(self) -> QPixmap: logger.debug("Capturing screenshot...") - self.serial.timeout=8 + self.serial.timeout = 8 if not self.connected(): return QPixmap() try: diff --git a/src/NanoVNASaver/Hardware/SV6301A.py b/src/NanoVNASaver/Hardware/SV6301A.py index 93a1e6b..faf14f4 100644 --- a/src/NanoVNASaver/Hardware/SV6301A.py +++ b/src/NanoVNASaver/Hardware/SV6301A.py @@ -41,7 +41,7 @@ class SV6301A(NanoVNA): def getScreenshot(self) -> QPixmap: logger.debug("Capturing screenshot...") - self.serial.timeout=8 + self.serial.timeout = 8 if not self.connected(): return QPixmap() try: diff --git a/src/NanoVNASaver/Marker/Values.py b/src/NanoVNASaver/Marker/Values.py index be9d33a..96cb203 100644 --- a/src/NanoVNASaver/Marker/Values.py +++ b/src/NanoVNASaver/Marker/Values.py @@ -98,6 +98,6 @@ class Value: ] self.freq = s11[1].freq - self.s11 = s11[index - 1 : index + 2] + self.s11 = s11[index - 1: index + 2] if s21: - self.s21 = s21[index - 1 : index + 2] + self.s21 = s21[index - 1: index + 2] diff --git a/src/NanoVNASaver/NanoVNASaver.py b/src/NanoVNASaver/NanoVNASaver.py index d4daa77..7c07495 100644 --- a/src/NanoVNASaver/NanoVNASaver.py +++ b/src/NanoVNASaver/NanoVNASaver.py @@ -304,7 +304,6 @@ class NanoVNASaver(QWidget): self.marker_data_layout.addWidget(m.get_data_layout()) scroll2 = QtWidgets.QScrollArea() - # scroll2.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOn) scroll2.setWidgetResizable(True) scroll2.setVisible(True) @@ -468,7 +467,7 @@ class NanoVNASaver(QWidget): logger.debug("Finished building interface") - def auto_connect( self ): # connect if there is exactly one detected serial device + def auto_connect(self): # connect if there is exactly one detected serial device if self.serial_control.inp_port.count() == 1: self.serial_control.connect_device() @@ -512,11 +511,8 @@ class NanoVNASaver(QWidget): self.sweepSource = source else: time = strftime('%Y-%m-%d %H:%M:%S', localtime()) - name = self.sweep.properties.name - if name: - self.sweepSource = name + ' ' + time - else: - self.sweepSource = time + name = self.sweep.properties.name or 'nanovna' + self.sweepSource = f'{name}_{time}' def markerUpdated(self, marker: Marker): with self.dataLock: diff --git a/src/NanoVNASaver/Settings/Sweep.py b/src/NanoVNASaver/Settings/Sweep.py index 2ad44cf..4e29f7e 100644 --- a/src/NanoVNASaver/Settings/Sweep.py +++ b/src/NanoVNASaver/Settings/Sweep.py @@ -40,12 +40,12 @@ class Properties(NamedTuple): class Sweep: def __init__(self, - start: int = 3600000, - end: int = 30000000, - points: int = 101, - segments: int = 1, - properties: "Properties" = Properties(), - ): + start: int = 3600000, + end: int = 30000000, + points: int = 101, + segments: int = 1, + properties: "Properties" = Properties(), + ): self._start = start self._end = end self._points = points @@ -112,10 +112,10 @@ class Sweep: def update(self, start: int, end: int, segments: int, points: int) -> None: with self._lock: - self._start = start - self._end = end - self._segments = segments - self._points = points + self._start = max(start, 1) + self._end = max(end, start) + self._segments = max(segments, 1) + self._points = max(points, 1) self.check() def set_name(self, name: str) -> None: @@ -136,11 +136,11 @@ class Sweep: def check(self): if ( - self.segments <= 0 - or self.points <= 0 - or self.start < 0 - or self.end <= 0 - or self.stepsize < 1 + self.segments < 1 + or self.points < 1 + or self.start < 1 + or self.end < self.start + or self.stepsize < 0 ): raise ValueError(f"Illegal sweep settings: {self}") diff --git a/src/NanoVNASaver/Version.py b/src/NanoVNASaver/Version.py index f103d56..8ef790c 100644 --- a/src/NanoVNASaver/Version.py +++ b/src/NanoVNASaver/Version.py @@ -22,16 +22,13 @@ import typing logger = logging.getLogger(__name__) -_RXP = re.compile( - r"""^ - \D* - (?P\d+)\. - (?P\d+)\.? - (?P\d+)? - (?P.*) - $""", - re.VERBOSE, - ) +_RXP = re.compile(r"""^ + \D* + (?P\d+)\. + (?P\d+)\.? + (?P\d+)? + (?P.*) + $""", re.VERBOSE) class _Version(typing.NamedTuple): diff --git a/src/NanoVNASaver/Windows/About.py b/src/NanoVNASaver/Windows/About.py index dbec9fe..1cc64d0 100644 --- a/src/NanoVNASaver/Windows/About.py +++ b/src/NanoVNASaver/Windows/About.py @@ -42,7 +42,7 @@ class AboutWindow(QtWidgets.QWidget): make_scrollable(self, top_layout) upper_layout = QtWidgets.QHBoxLayout() - top_layout.addLayout( upper_layout ) + top_layout.addLayout(upper_layout) QtGui.QShortcut(QtCore.Qt.Key.Key_Escape, self, self.hide) icon_layout = QtWidgets.QVBoxLayout() @@ -84,7 +84,7 @@ class AboutWindow(QtWidgets.QWidget): info_layout.addWidget(QtWidgets.QLabel("")) lower_layout = QtWidgets.QVBoxLayout() - top_layout.addLayout( lower_layout ) + top_layout.addLayout(lower_layout) btn_check_version = QtWidgets.QPushButton("Check for NanoVNASaver updates") btn_check_version.clicked.connect(self.findUpdates) @@ -95,7 +95,7 @@ class AboutWindow(QtWidgets.QWidget): update_hbox.addWidget(btn_check_version) update_hbox.addStretch() lower_layout.addLayout(update_hbox) - lower_layout.addWidget( self.updateLabel ) + lower_layout.addWidget(self.updateLabel) lower_layout.addStretch() diff --git a/src/NanoVNASaver/Windows/CalibrationSettings.py b/src/NanoVNASaver/Windows/CalibrationSettings.py index 9f66a7b..ea8385c 100644 --- a/src/NanoVNASaver/Windows/CalibrationSettings.py +++ b/src/NanoVNASaver/Windows/CalibrationSettings.py @@ -282,7 +282,8 @@ class CalibrationWindow(QtWidgets.QWidget): "If you are certain you know what you are doing, click" " Yes." ), - QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.Cancel, + QtWidgets.QMessageBox.StandardButton.Yes | + QtWidgets.QMessageBox.StandardButton.Cancel, QtWidgets.QMessageBox.StandardButton.Cancel, ) @@ -798,7 +799,8 @@ class CalibrationWindow(QtWidgets.QWidget): " cable unconnected if desired.\n\n" "Press Ok when you are ready to continue." ), - QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel, + QtWidgets.QMessageBox.StandardButton.Ok | + QtWidgets.QMessageBox.StandardButton.Cancel, ) response = open_step.exec() @@ -824,7 +826,8 @@ class CalibrationWindow(QtWidgets.QWidget): " NanoVNA.\n\n" "Press Ok when you are ready to continue." ), - QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel, + QtWidgets.QMessageBox.StandardButton.Ok | + QtWidgets.QMessageBox.StandardButton.Cancel, ) response = load_step.exec() @@ -884,7 +887,8 @@ class CalibrationWindow(QtWidgets.QWidget): " port 0.\n\n" "Press Ok when you are ready to continue." ), - QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel, + QtWidgets.QMessageBox.StandardButton.Ok | + QtWidgets.QMessageBox.StandardButton.Cancel, ) response = isolation_step.exec() @@ -910,7 +914,8 @@ class CalibrationWindow(QtWidgets.QWidget): " port 0 and port 1 of the NanoVNA.\n\n" "Press Ok when you are ready to continue." ), - QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel, + QtWidgets.QMessageBox.StandardButton.Ok | + QtWidgets.QMessageBox.StandardButton.Cancel, ) response = through_step.exec() @@ -935,7 +940,8 @@ class CalibrationWindow(QtWidgets.QWidget): "The calibration process is now complete. Press" ' "Apply" to apply the calibration parameters.' ), - QtWidgets.QMessageBox.StandardButton.Apply | QtWidgets.QMessageBox.StandardButton.Cancel, + QtWidgets.QMessageBox.StandardButton.Apply | + QtWidgets.QMessageBox.StandardButton.Cancel, ) response = apply_step.exec() diff --git a/src/NanoVNASaver/Windows/DeviceSettings.py b/src/NanoVNASaver/Windows/DeviceSettings.py index d746d4a..c45897c 100644 --- a/src/NanoVNASaver/Windows/DeviceSettings.py +++ b/src/NanoVNASaver/Windows/DeviceSettings.py @@ -30,6 +30,7 @@ logger = logging.getLogger(__name__) class DeviceSettingsWindow(QtWidgets.QWidget): custom_points_checkBox = QtWidgets.QCheckBox custom_points_Eidt = QtWidgets.QLineEdit + def __init__(self, app: QtWidgets.QWidget): super().__init__() @@ -99,7 +100,9 @@ class DeviceSettingsWindow(QtWidgets.QWidget): self.custom_points_checkBox = QtWidgets.QCheckBox("Custom points") self.custom_points_checkBox.stateChanged.connect(self.customPoint_check) self.custom_points_Eidt = QtWidgets.QLineEdit("101") - self.custom_points_Eidt.setValidator(QIntValidator(self.app.vna.sweep_points_min,self.app.vna.sweep_points_max)) + self.custom_points_Eidt.setValidator( + QIntValidator(self.app.vna.sweep_points_min, + self.app.vna.sweep_points_max)) self.custom_points_Eidt.textEdited.connect(self.updatecustomPoint) self.custom_points_Eidt.setDisabled(True) @@ -152,7 +155,9 @@ class DeviceSettingsWindow(QtWidgets.QWidget): if "Customizable data points" in features: self.datapoints.clear() - self.custom_points_Eidt.setValidator(QIntValidator(self.app.vna.sweep_points_min,self.app.vna.sweep_points_max)) + self.custom_points_Eidt.setValidator( + QIntValidator(self.app.vna.sweep_points_min, + self.app.vna.sweep_points_max)) cur_dps = self.app.vna.datapoints for d in sorted(self.app.vna.valid_datapoints): self.datapoints.addItem(str(d)) @@ -200,16 +205,16 @@ class DeviceSettingsWindow(QtWidgets.QWidget): def customPoint_check(self, validate_data: bool): self.datapoints.setDisabled(validate_data) - self.custom_points_Eidt.setDisabled(not(validate_data)) + self.custom_points_Eidt.setDisabled(not validate_data) - def updatecustomPoint(self,points_str: str): + def updatecustomPoint(self, points_str: str): if self.custom_points_checkBox.isChecked(): - #points_str = self.custom_points_Eidt.text() + # points_str = self.custom_points_Eidt.text() if len(points_str) == 0: return points = int(points_str) if points < self.app.vna.sweep_points_min: - return + return if points > self.app.vna.sweep_points_max: points = int(self.app.vna.sweep_points_max) diff --git a/src/NanoVNASaver/Windows/DisplaySettings.py b/src/NanoVNASaver/Windows/DisplaySettings.py index 2e9061f..fa00133 100644 --- a/src/NanoVNASaver/Windows/DisplaySettings.py +++ b/src/NanoVNASaver/Windows/DisplaySettings.py @@ -551,7 +551,7 @@ class DisplaySettingsWindow(QtWidgets.QWidget): logger.info("Invalid color") return - setattr( Chart.color, attr, color ) # update trace color immediately + setattr(Chart.color, attr, color) # update trace color immediately palette = sender.palette() palette.setColor(QPalette.ColorRole.ButtonText, color) sender.setPalette(palette)