2020-06-09 15:56:53 +00:00
|
|
|
# NanoVNASaver
|
|
|
|
# A python program to view and export Touchstone data from a NanoVNA
|
2019-08-29 13:10:35 +00:00
|
|
|
# Copyright (C) 2019. Rune B. Broberg
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-09-16 13:47:37 +00:00
|
|
|
import logging
|
2019-08-28 18:20:07 +00:00
|
|
|
|
2020-06-09 15:56:53 +00:00
|
|
|
from PyQt5 import QtWidgets, QtCore
|
2019-08-28 18:20:07 +00:00
|
|
|
|
2020-06-09 15:56:53 +00:00
|
|
|
from NanoVNASaver.Windows.Screenshot import ScreenshotWindow
|
2019-08-28 18:20:07 +00:00
|
|
|
|
2019-09-16 13:47:37 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2019-12-07 23:07:55 +00:00
|
|
|
class DeviceSettingsWindow(QtWidgets.QWidget):
|
2020-06-09 15:56:53 +00:00
|
|
|
def __init__(self, app: QtWidgets.QWidget):
|
2019-12-07 23:07:55 +00:00
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
self.app = app
|
|
|
|
self.setWindowTitle("Device settings")
|
|
|
|
self.setWindowIcon(self.app.icon)
|
|
|
|
|
2020-06-09 15:56:53 +00:00
|
|
|
QtWidgets.QShortcut(QtCore.Qt.Key_Escape, self, self.hide)
|
2019-12-07 23:07:55 +00:00
|
|
|
|
|
|
|
layout = QtWidgets.QVBoxLayout()
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
status_box = QtWidgets.QGroupBox("Status")
|
|
|
|
status_layout = QtWidgets.QFormLayout(status_box)
|
|
|
|
self.statusLabel = QtWidgets.QLabel("Not connected.")
|
|
|
|
status_layout.addRow("Status:", self.statusLabel)
|
|
|
|
|
2019-12-08 00:54:39 +00:00
|
|
|
self.calibrationStatusLabel = QtWidgets.QLabel("Not connected.")
|
|
|
|
status_layout.addRow("Calibration:", self.calibrationStatusLabel)
|
|
|
|
|
2019-12-07 23:07:55 +00:00
|
|
|
status_layout.addRow(QtWidgets.QLabel("Features:"))
|
|
|
|
self.featureList = QtWidgets.QListWidget()
|
|
|
|
status_layout.addRow(self.featureList)
|
|
|
|
|
|
|
|
settings_box = QtWidgets.QGroupBox("Settings")
|
|
|
|
settings_layout = QtWidgets.QFormLayout(settings_box)
|
|
|
|
|
|
|
|
self.chkValidateInputData = QtWidgets.QCheckBox("Validate received data")
|
2019-12-12 14:16:37 +00:00
|
|
|
validate_input = self.app.settings.value("SerialInputValidation", True, bool)
|
|
|
|
self.chkValidateInputData.setChecked(validate_input)
|
2019-12-07 23:07:55 +00:00
|
|
|
self.chkValidateInputData.stateChanged.connect(self.updateValidation)
|
|
|
|
settings_layout.addRow("Validation", self.chkValidateInputData)
|
|
|
|
|
|
|
|
control_layout = QtWidgets.QHBoxLayout()
|
|
|
|
self.btnRefresh = QtWidgets.QPushButton("Refresh")
|
|
|
|
self.btnRefresh.clicked.connect(self.updateFields)
|
|
|
|
control_layout.addWidget(self.btnRefresh)
|
|
|
|
|
2019-12-08 00:54:39 +00:00
|
|
|
self.screenshotWindow = ScreenshotWindow()
|
|
|
|
self.btnCaptureScreenshot = QtWidgets.QPushButton("Screenshot")
|
|
|
|
self.btnCaptureScreenshot.clicked.connect(self.captureScreenshot)
|
|
|
|
control_layout.addWidget(self.btnCaptureScreenshot)
|
|
|
|
|
2019-12-07 23:07:55 +00:00
|
|
|
layout.addWidget(status_box)
|
|
|
|
layout.addWidget(settings_box)
|
|
|
|
layout.addLayout(control_layout)
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
super().show()
|
|
|
|
self.updateFields()
|
|
|
|
|
|
|
|
def updateFields(self):
|
|
|
|
if self.app.vna.isValid():
|
|
|
|
self.statusLabel.setText("Connected to " + self.app.vna.name + ".")
|
2019-12-08 00:54:39 +00:00
|
|
|
if self.app.worker.running:
|
|
|
|
self.calibrationStatusLabel.setText("(Sweep running)")
|
|
|
|
else:
|
|
|
|
self.calibrationStatusLabel.setText(self.app.vna.getCalibration())
|
|
|
|
|
|
|
|
self.featureList.clear()
|
|
|
|
self.featureList.addItem(self.app.vna.name + " v" + str(self.app.vna.version))
|
2019-12-11 09:36:48 +00:00
|
|
|
features = self.app.vna.getFeatures()
|
|
|
|
for item in features:
|
2019-12-08 00:54:39 +00:00
|
|
|
self.featureList.addItem(item)
|
2019-12-11 09:36:48 +00:00
|
|
|
|
|
|
|
if "Screenshots" in features:
|
|
|
|
self.btnCaptureScreenshot.setDisabled(False)
|
|
|
|
else:
|
|
|
|
self.btnCaptureScreenshot.setDisabled(True)
|
2019-12-07 23:07:55 +00:00
|
|
|
else:
|
|
|
|
self.statusLabel.setText("Not connected.")
|
2019-12-08 00:54:39 +00:00
|
|
|
self.calibrationStatusLabel.setText("Not connected.")
|
2019-12-07 23:07:55 +00:00
|
|
|
self.featureList.clear()
|
|
|
|
self.featureList.addItem("Not connected.")
|
2019-12-11 09:36:48 +00:00
|
|
|
self.btnCaptureScreenshot.setDisabled(True)
|
2019-12-07 23:07:55 +00:00
|
|
|
|
|
|
|
def updateValidation(self, validate_data: bool):
|
|
|
|
self.app.vna.validateInput = validate_data
|
2019-12-12 14:16:37 +00:00
|
|
|
self.app.settings.setValue("SerialInputValidation", validate_data)
|
2019-12-08 00:54:39 +00:00
|
|
|
|
|
|
|
def captureScreenshot(self):
|
|
|
|
if not self.app.worker.running:
|
|
|
|
pixmap = self.app.vna.getScreenshot()
|
|
|
|
self.screenshotWindow.setScreenshot(pixmap)
|
|
|
|
self.screenshotWindow.show()
|
|
|
|
else:
|
|
|
|
# TODO: Tell the user no screenshots while sweep is running?
|
2020-06-09 15:56:53 +00:00
|
|
|
# TODO: Consider having a list of widgets that want to be
|
|
|
|
# disabled when a sweep is running?
|
2019-12-08 00:54:39 +00:00
|
|
|
pass
|