fix swwep update crash #668 (#669)

pull/671/head v0.6.2
Holger Müller 2023-08-01 12:42:38 +02:00 committed by GitHub
parent b4800102d8
commit 21e85bdb49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 64 additions and 59 deletions

1
.gitignore vendored
View File

@ -48,6 +48,7 @@ docs/_build/*
cover/*
MANIFEST
**/_version.py
.flatpak-builder/*
# Per-project virtualenvs
.venv*/

View File

@ -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()

View File

@ -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,
)

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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]

View File

@ -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:

View File

@ -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}")

View File

@ -22,16 +22,13 @@ import typing
logger = logging.getLogger(__name__)
_RXP = re.compile(
r"""^
\D*
(?P<major>\d+)\.
(?P<minor>\d+)\.?
(?P<revision>\d+)?
(?P<note>.*)
$""",
re.VERBOSE,
)
_RXP = re.compile(r"""^
\D*
(?P<major>\d+)\.
(?P<minor>\d+)\.?
(?P<revision>\d+)?
(?P<note>.*)
$""", re.VERBOSE)
class _Version(typing.NamedTuple):

View File

@ -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()

View File

@ -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()

View File

@ -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)

View File

@ -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)