Skip to content

Commit 21e85bd

Browse files
authored
fix swwep update crash #668 (#669)
1 parent b480010 commit 21e85bd

File tree

14 files changed

+64
-59
lines changed

14 files changed

+64
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ docs/_build/*
4848
cover/*
4949
MANIFEST
5050
**/_version.py
51+
.flatpak-builder/*
5152

5253
# Per-project virtualenvs
5354
.venv*/

nanovna-saver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
src = os.path.join(os.path.dirname(__file__), "src")
2727

2828
if os.path.exists(src):
29-
sys.path.insert(0, src)
29+
sys.path.insert(0, src)
3030

3131
# pylint: disable-next=wrong-import-position
3232
import NanoVNASaver.__main__
3333

3434
# The traditional test does not make sense here.
35-
assert __name__ == '__main__'
35+
assert __name__ == "__main__"
3636

3737
NanoVNASaver.__main__.main()

src/NanoVNASaver/Controls/SweepControl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ def update_step_size(self):
217217

218218
def update_sweep(self):
219219
self.app.sweep.update(
220-
start = self.get_start(),
221-
end = self.get_end(),
222-
segments = self.get_segments(),
223-
points = self.app.vna.datapoints,
220+
start=self.get_start(),
221+
end=self.get_end(),
222+
segments=self.get_segments(),
223+
points=self.app.vna.datapoints,
224224
)

src/NanoVNASaver/Hardware/JNCRadio_VNA_3G.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, iface: Interface):
4141

4242
def getScreenshot(self) -> QPixmap:
4343
logger.debug("Capturing screenshot...")
44-
self.serial.timeout=8
44+
self.serial.timeout = 8
4545
if not self.connected():
4646
return QPixmap()
4747
try:

src/NanoVNASaver/Hardware/SV4401A.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, iface: Interface):
4141

4242
def getScreenshot(self) -> QPixmap:
4343
logger.debug("Capturing screenshot...")
44-
self.serial.timeout=8
44+
self.serial.timeout = 8
4545
if not self.connected():
4646
return QPixmap()
4747
try:

src/NanoVNASaver/Hardware/SV6301A.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, iface: Interface):
4141

4242
def getScreenshot(self) -> QPixmap:
4343
logger.debug("Capturing screenshot...")
44-
self.serial.timeout=8
44+
self.serial.timeout = 8
4545
if not self.connected():
4646
return QPixmap()
4747
try:

src/NanoVNASaver/Marker/Values.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@ def store(self, index: int, s11: list[Datapoint], s21: list[Datapoint]):
9898
]
9999

100100
self.freq = s11[1].freq
101-
self.s11 = s11[index - 1 : index + 2]
101+
self.s11 = s11[index - 1: index + 2]
102102
if s21:
103-
self.s21 = s21[index - 1 : index + 2]
103+
self.s21 = s21[index - 1: index + 2]

src/NanoVNASaver/NanoVNASaver.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ def __init__(self):
304304
self.marker_data_layout.addWidget(m.get_data_layout())
305305

306306
scroll2 = QtWidgets.QScrollArea()
307-
# scroll2.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
308307
scroll2.setWidgetResizable(True)
309308
scroll2.setVisible(True)
310309

@@ -468,7 +467,7 @@ def __init__(self):
468467

469468
logger.debug("Finished building interface")
470469

471-
def auto_connect( self ): # connect if there is exactly one detected serial device
470+
def auto_connect(self): # connect if there is exactly one detected serial device
472471
if self.serial_control.inp_port.count() == 1:
473472
self.serial_control.connect_device()
474473

@@ -512,11 +511,8 @@ def saveData(self, data, data21, source=None):
512511
self.sweepSource = source
513512
else:
514513
time = strftime('%Y-%m-%d %H:%M:%S', localtime())
515-
name = self.sweep.properties.name
516-
if name:
517-
self.sweepSource = name + ' ' + time
518-
else:
519-
self.sweepSource = time
514+
name = self.sweep.properties.name or 'nanovna'
515+
self.sweepSource = f'{name}_{time}'
520516

521517
def markerUpdated(self, marker: Marker):
522518
with self.dataLock:

src/NanoVNASaver/Settings/Sweep.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class Properties(NamedTuple):
4040

4141
class Sweep:
4242
def __init__(self,
43-
start: int = 3600000,
44-
end: int = 30000000,
45-
points: int = 101,
46-
segments: int = 1,
47-
properties: "Properties" = Properties(),
48-
):
43+
start: int = 3600000,
44+
end: int = 30000000,
45+
points: int = 101,
46+
segments: int = 1,
47+
properties: "Properties" = Properties(),
48+
):
4949
self._start = start
5050
self._end = end
5151
self._points = points
@@ -112,10 +112,10 @@ def set_points(self, points: int) -> None:
112112

113113
def update(self, start: int, end: int, segments: int, points: int) -> None:
114114
with self._lock:
115-
self._start = start
116-
self._end = end
117-
self._segments = segments
118-
self._points = points
115+
self._start = max(start, 1)
116+
self._end = max(end, start)
117+
self._segments = max(segments, 1)
118+
self._points = max(points, 1)
119119
self.check()
120120

121121
def set_name(self, name: str) -> None:
@@ -136,11 +136,11 @@ def set_logarithmic(self, logarithmic: bool) -> None:
136136

137137
def check(self):
138138
if (
139-
self.segments <= 0
140-
or self.points <= 0
141-
or self.start < 0
142-
or self.end <= 0
143-
or self.stepsize < 1
139+
self.segments < 1
140+
or self.points < 1
141+
or self.start < 1
142+
or self.end < self.start
143+
or self.stepsize < 0
144144
):
145145
raise ValueError(f"Illegal sweep settings: {self}")
146146

src/NanoVNASaver/Version.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@
2222
logger = logging.getLogger(__name__)
2323

2424

25-
_RXP = re.compile(
26-
r"""^
27-
\D*
28-
(?P<major>\d+)\.
29-
(?P<minor>\d+)\.?
30-
(?P<revision>\d+)?
31-
(?P<note>.*)
32-
$""",
33-
re.VERBOSE,
34-
)
25+
_RXP = re.compile(r"""^
26+
\D*
27+
(?P<major>\d+)\.
28+
(?P<minor>\d+)\.?
29+
(?P<revision>\d+)?
30+
(?P<note>.*)
31+
$""", re.VERBOSE)
3532

3633

3734
class _Version(typing.NamedTuple):

src/NanoVNASaver/Windows/About.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, app: QtWidgets.QWidget):
4242
make_scrollable(self, top_layout)
4343

4444
upper_layout = QtWidgets.QHBoxLayout()
45-
top_layout.addLayout( upper_layout )
45+
top_layout.addLayout(upper_layout)
4646
QtGui.QShortcut(QtCore.Qt.Key.Key_Escape, self, self.hide)
4747

4848
icon_layout = QtWidgets.QVBoxLayout()
@@ -84,7 +84,7 @@ def __init__(self, app: QtWidgets.QWidget):
8484
info_layout.addWidget(QtWidgets.QLabel(""))
8585

8686
lower_layout = QtWidgets.QVBoxLayout()
87-
top_layout.addLayout( lower_layout )
87+
top_layout.addLayout(lower_layout)
8888

8989
btn_check_version = QtWidgets.QPushButton("Check for NanoVNASaver updates")
9090
btn_check_version.clicked.connect(self.findUpdates)
@@ -95,7 +95,7 @@ def __init__(self, app: QtWidgets.QWidget):
9595
update_hbox.addWidget(btn_check_version)
9696
update_hbox.addStretch()
9797
lower_layout.addLayout(update_hbox)
98-
lower_layout.addWidget( self.updateLabel )
98+
lower_layout.addWidget(self.updateLabel)
9999

100100
lower_layout.addStretch()
101101

src/NanoVNASaver/Windows/CalibrationSettings.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ def checkExpertUser(self):
282282
"If you are certain you know what you are doing, click"
283283
" Yes."
284284
),
285-
QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.Cancel,
285+
QtWidgets.QMessageBox.StandardButton.Yes |
286+
QtWidgets.QMessageBox.StandardButton.Cancel,
286287
QtWidgets.QMessageBox.StandardButton.Cancel,
287288
)
288289

@@ -798,7 +799,8 @@ def automaticCalibrationStep(self):
798799
" cable unconnected if desired.\n\n"
799800
"Press Ok when you are ready to continue."
800801
),
801-
QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel,
802+
QtWidgets.QMessageBox.StandardButton.Ok |
803+
QtWidgets.QMessageBox.StandardButton.Cancel,
802804
)
803805

804806
response = open_step.exec()
@@ -824,7 +826,8 @@ def automaticCalibrationStep(self):
824826
" NanoVNA.\n\n"
825827
"Press Ok when you are ready to continue."
826828
),
827-
QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel,
829+
QtWidgets.QMessageBox.StandardButton.Ok |
830+
QtWidgets.QMessageBox.StandardButton.Cancel,
828831
)
829832

830833
response = load_step.exec()
@@ -884,7 +887,8 @@ def automaticCalibrationStep(self):
884887
" port 0.\n\n"
885888
"Press Ok when you are ready to continue."
886889
),
887-
QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel,
890+
QtWidgets.QMessageBox.StandardButton.Ok |
891+
QtWidgets.QMessageBox.StandardButton.Cancel,
888892
)
889893

890894
response = isolation_step.exec()
@@ -910,7 +914,8 @@ def automaticCalibrationStep(self):
910914
" port 0 and port 1 of the NanoVNA.\n\n"
911915
"Press Ok when you are ready to continue."
912916
),
913-
QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel,
917+
QtWidgets.QMessageBox.StandardButton.Ok |
918+
QtWidgets.QMessageBox.StandardButton.Cancel,
914919
)
915920

916921
response = through_step.exec()
@@ -935,7 +940,8 @@ def automaticCalibrationStep(self):
935940
"The calibration process is now complete. Press"
936941
' "Apply" to apply the calibration parameters.'
937942
),
938-
QtWidgets.QMessageBox.StandardButton.Apply | QtWidgets.QMessageBox.StandardButton.Cancel,
943+
QtWidgets.QMessageBox.StandardButton.Apply |
944+
QtWidgets.QMessageBox.StandardButton.Cancel,
939945
)
940946

941947
response = apply_step.exec()

src/NanoVNASaver/Windows/DeviceSettings.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
class DeviceSettingsWindow(QtWidgets.QWidget):
3131
custom_points_checkBox = QtWidgets.QCheckBox
3232
custom_points_Eidt = QtWidgets.QLineEdit
33+
3334
def __init__(self, app: QtWidgets.QWidget):
3435
super().__init__()
3536

@@ -99,7 +100,9 @@ def __init__(self, app: QtWidgets.QWidget):
99100
self.custom_points_checkBox = QtWidgets.QCheckBox("Custom points")
100101
self.custom_points_checkBox.stateChanged.connect(self.customPoint_check)
101102
self.custom_points_Eidt = QtWidgets.QLineEdit("101")
102-
self.custom_points_Eidt.setValidator(QIntValidator(self.app.vna.sweep_points_min,self.app.vna.sweep_points_max))
103+
self.custom_points_Eidt.setValidator(
104+
QIntValidator(self.app.vna.sweep_points_min,
105+
self.app.vna.sweep_points_max))
103106
self.custom_points_Eidt.textEdited.connect(self.updatecustomPoint)
104107
self.custom_points_Eidt.setDisabled(True)
105108

@@ -152,7 +155,9 @@ def updateFields(self):
152155

153156
if "Customizable data points" in features:
154157
self.datapoints.clear()
155-
self.custom_points_Eidt.setValidator(QIntValidator(self.app.vna.sweep_points_min,self.app.vna.sweep_points_max))
158+
self.custom_points_Eidt.setValidator(
159+
QIntValidator(self.app.vna.sweep_points_min,
160+
self.app.vna.sweep_points_max))
156161
cur_dps = self.app.vna.datapoints
157162
for d in sorted(self.app.vna.valid_datapoints):
158163
self.datapoints.addItem(str(d))
@@ -200,16 +205,16 @@ def updateBandwidth(self, i):
200205

201206
def customPoint_check(self, validate_data: bool):
202207
self.datapoints.setDisabled(validate_data)
203-
self.custom_points_Eidt.setDisabled(not(validate_data))
208+
self.custom_points_Eidt.setDisabled(not validate_data)
204209

205-
def updatecustomPoint(self,points_str: str):
210+
def updatecustomPoint(self, points_str: str):
206211
if self.custom_points_checkBox.isChecked():
207-
#points_str = self.custom_points_Eidt.text()
212+
# points_str = self.custom_points_Eidt.text()
208213
if len(points_str) == 0:
209214
return
210215
points = int(points_str)
211216
if points < self.app.vna.sweep_points_min:
212-
return
217+
return
213218
if points > self.app.vna.sweep_points_max:
214219
points = int(self.app.vna.sweep_points_max)
215220

src/NanoVNASaver/Windows/DisplaySettings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def setColor(self):
551551
logger.info("Invalid color")
552552
return
553553

554-
setattr( Chart.color, attr, color ) # update trace color immediately
554+
setattr(Chart.color, attr, color) # update trace color immediately
555555
palette = sender.palette()
556556
palette.setColor(QPalette.ColorRole.ButtonText, color)
557557
sender.setPalette(palette)

0 commit comments

Comments
 (0)