Skip to content

Commit

Permalink
fix swwep update crash #668 (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
zarath authored Aug 1, 2023
1 parent b480010 commit 21e85bd
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ docs/_build/*
cover/*
MANIFEST
**/_version.py
.flatpak-builder/*

# Per-project virtualenvs
.venv*/
Expand Down
4 changes: 2 additions & 2 deletions nanovna-saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
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()
8 changes: 4 additions & 4 deletions src/NanoVNASaver/Controls/SweepControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ def update_step_size(self):

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,
)
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Hardware/JNCRadio_VNA_3G.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, iface: Interface):

def getScreenshot(self) -> QPixmap:
logger.debug("Capturing screenshot...")
self.serial.timeout=8
self.serial.timeout = 8
if not self.connected():
return QPixmap()
try:
Expand Down
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Hardware/SV4401A.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, iface: Interface):

def getScreenshot(self) -> QPixmap:
logger.debug("Capturing screenshot...")
self.serial.timeout=8
self.serial.timeout = 8
if not self.connected():
return QPixmap()
try:
Expand Down
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Hardware/SV6301A.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, iface: Interface):

def getScreenshot(self) -> QPixmap:
logger.debug("Capturing screenshot...")
self.serial.timeout=8
self.serial.timeout = 8
if not self.connected():
return QPixmap()
try:
Expand Down
4 changes: 2 additions & 2 deletions src/NanoVNASaver/Marker/Values.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ def store(self, index: int, s11: list[Datapoint], s21: list[Datapoint]):
]

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]
10 changes: 3 additions & 7 deletions src/NanoVNASaver/NanoVNASaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ def __init__(self):
self.marker_data_layout.addWidget(m.get_data_layout())

scroll2 = QtWidgets.QScrollArea()
# scroll2.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
scroll2.setWidgetResizable(True)
scroll2.setVisible(True)

Expand Down Expand Up @@ -468,7 +467,7 @@ def __init__(self):

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

Expand Down Expand Up @@ -512,11 +511,8 @@ def saveData(self, data, data21, source=None):
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:
Expand Down
30 changes: 15 additions & 15 deletions src/NanoVNASaver/Settings/Sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -112,10 +112,10 @@ def set_points(self, points: int) -> None:

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:
Expand All @@ -136,11 +136,11 @@ def set_logarithmic(self, logarithmic: bool) -> None:

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

Expand Down
17 changes: 7 additions & 10 deletions src/NanoVNASaver/Version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
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):
Expand Down
6 changes: 3 additions & 3 deletions src/NanoVNASaver/Windows/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, app: 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()
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(self, app: 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)
Expand All @@ -95,7 +95,7 @@ def __init__(self, app: 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()

Expand Down
18 changes: 12 additions & 6 deletions src/NanoVNASaver/Windows/CalibrationSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ def checkExpertUser(self):
"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,
)

Expand Down Expand Up @@ -798,7 +799,8 @@ def automaticCalibrationStep(self):
" 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()
Expand All @@ -824,7 +826,8 @@ def automaticCalibrationStep(self):
" 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()
Expand Down Expand Up @@ -884,7 +887,8 @@ def automaticCalibrationStep(self):
" 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()
Expand All @@ -910,7 +914,8 @@ def automaticCalibrationStep(self):
" 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()
Expand All @@ -935,7 +940,8 @@ def automaticCalibrationStep(self):
"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()
Expand Down
17 changes: 11 additions & 6 deletions src/NanoVNASaver/Windows/DeviceSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class DeviceSettingsWindow(QtWidgets.QWidget):
custom_points_checkBox = QtWidgets.QCheckBox
custom_points_Eidt = QtWidgets.QLineEdit

def __init__(self, app: QtWidgets.QWidget):
super().__init__()

Expand Down Expand Up @@ -99,7 +100,9 @@ def __init__(self, app: 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)

Expand Down Expand Up @@ -152,7 +155,9 @@ def updateFields(self):

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))
Expand Down Expand Up @@ -200,16 +205,16 @@ def updateBandwidth(self, i):

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)

Expand Down
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Windows/DisplaySettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def setColor(self):
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)
Expand Down

0 comments on commit 21e85bd

Please sign in to comment.