2020-06-09 15:56:53 +00:00
|
|
|
# NanoVNASaver
|
2020-06-25 17:48:03 +00:00
|
|
|
#
|
2020-06-09 15:56:53 +00:00
|
|
|
# A python program to view and export Touchstone data from a NanoVNA
|
2020-06-25 17:48:03 +00:00
|
|
|
# Copyright (C) 2019, 2020 Rune B. Broberg
|
|
|
|
# Copyright (C) 2020 NanoVNA-Saver Authors
|
2019-08-29 13:10:35 +00:00
|
|
|
#
|
|
|
|
# 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
|
2020-06-09 15:56:53 +00:00
|
|
|
from time import strftime, localtime
|
|
|
|
from urllib import request, error
|
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-25 17:48:03 +00:00
|
|
|
from NanoVNASaver.About import VERSION_URL, INFO_URL
|
|
|
|
from NanoVNASaver.Settings import Version
|
2019-08-28 18:20:07 +00:00
|
|
|
|
2019-09-16 13:47:37 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-06-21 18:54:23 +00:00
|
|
|
|
2019-10-09 12:08:48 +00:00
|
|
|
class AboutWindow(QtWidgets.QWidget):
|
2020-06-09 15:56:53 +00:00
|
|
|
def __init__(self, app: QtWidgets.QWidget):
|
2019-10-09 12:08:48 +00:00
|
|
|
super().__init__()
|
|
|
|
self.app = app
|
2019-10-11 17:13:46 +00:00
|
|
|
|
2019-10-09 12:08:48 +00:00
|
|
|
self.setWindowTitle("About NanoVNASaver")
|
|
|
|
self.setWindowIcon(self.app.icon)
|
|
|
|
top_layout = QtWidgets.QHBoxLayout()
|
|
|
|
self.setLayout(top_layout)
|
2020-06-09 15:56:53 +00:00
|
|
|
QtWidgets.QShortcut(QtCore.Qt.Key_Escape, self, self.hide)
|
2019-10-09 12:08:48 +00:00
|
|
|
|
|
|
|
icon_layout = QtWidgets.QVBoxLayout()
|
|
|
|
top_layout.addLayout(icon_layout)
|
|
|
|
icon = QtWidgets.QLabel()
|
|
|
|
icon.setPixmap(self.app.icon.pixmap(128, 128))
|
|
|
|
icon_layout.addWidget(icon)
|
|
|
|
icon_layout.addStretch()
|
|
|
|
|
|
|
|
layout = QtWidgets.QVBoxLayout()
|
|
|
|
top_layout.addLayout(layout)
|
|
|
|
|
2020-06-09 15:56:53 +00:00
|
|
|
layout.addWidget(QtWidgets.QLabel(
|
|
|
|
f"NanoVNASaver version {self.app.version}"))
|
2019-10-09 12:08:48 +00:00
|
|
|
layout.addWidget(QtWidgets.QLabel(""))
|
2020-06-09 15:56:53 +00:00
|
|
|
layout.addWidget(QtWidgets.QLabel(
|
2020-07-04 11:16:49 +00:00
|
|
|
"\N{COPYRIGHT SIGN} Copyright 2019, 2020 Rune B. Broberg\n"
|
2020-06-25 17:48:03 +00:00
|
|
|
"\N{COPYRIGHT SIGN} Copyright 2020 NanoVNA-Saver Authors"
|
|
|
|
))
|
2020-06-09 15:56:53 +00:00
|
|
|
layout.addWidget(QtWidgets.QLabel(
|
|
|
|
"This program comes with ABSOLUTELY NO WARRANTY"))
|
|
|
|
layout.addWidget(QtWidgets.QLabel(
|
2020-06-25 17:48:03 +00:00
|
|
|
"This program is licensed under the"
|
|
|
|
" GNU General Public License version 3"))
|
2019-10-09 12:08:48 +00:00
|
|
|
layout.addWidget(QtWidgets.QLabel(""))
|
2020-06-09 15:56:53 +00:00
|
|
|
link_label = QtWidgets.QLabel(
|
2020-06-25 17:48:03 +00:00
|
|
|
f'For further details, see: <a href="{INFO_URL}">'
|
|
|
|
f"{INFO_URL}")
|
2019-10-09 12:08:48 +00:00
|
|
|
link_label.setOpenExternalLinks(True)
|
|
|
|
layout.addWidget(link_label)
|
|
|
|
layout.addWidget(QtWidgets.QLabel(""))
|
|
|
|
|
2020-06-25 17:48:03 +00:00
|
|
|
self.versionLabel = QtWidgets.QLabel(
|
|
|
|
"NanoVNA Firmware Version: Not connected.")
|
2019-10-09 12:08:48 +00:00
|
|
|
layout.addWidget(self.versionLabel)
|
|
|
|
|
|
|
|
layout.addStretch()
|
|
|
|
|
2019-10-09 16:35:36 +00:00
|
|
|
btn_check_version = QtWidgets.QPushButton("Check for updates")
|
|
|
|
btn_check_version.clicked.connect(self.findUpdates)
|
|
|
|
|
|
|
|
self.updateLabel = QtWidgets.QLabel("Last checked: ")
|
2020-06-25 17:48:03 +00:00
|
|
|
self.updateCheckBox = QtWidgets.QCheckBox(
|
|
|
|
"Check for updates on startup")
|
2019-10-09 16:35:36 +00:00
|
|
|
|
|
|
|
self.updateCheckBox.toggled.connect(self.updateSettings)
|
|
|
|
|
2020-06-25 17:48:03 +00:00
|
|
|
check_for_updates = self.app.settings.value(
|
|
|
|
"CheckForUpdates", "Ask")
|
2019-10-09 16:35:36 +00:00
|
|
|
if check_for_updates == "Yes":
|
|
|
|
self.updateCheckBox.setChecked(True)
|
2019-10-13 15:35:32 +00:00
|
|
|
self.findUpdates(automatic=True)
|
2019-10-09 16:35:36 +00:00
|
|
|
elif check_for_updates == "No":
|
|
|
|
self.updateCheckBox.setChecked(False)
|
|
|
|
else:
|
|
|
|
logger.debug("Starting timer")
|
|
|
|
QtCore.QTimer.singleShot(2000, self.askAboutUpdates)
|
|
|
|
|
|
|
|
update_hbox = QtWidgets.QHBoxLayout()
|
|
|
|
update_hbox.addWidget(btn_check_version)
|
|
|
|
update_form = QtWidgets.QFormLayout()
|
|
|
|
update_hbox.addLayout(update_form)
|
|
|
|
update_hbox.addStretch()
|
|
|
|
update_form.addRow(self.updateLabel)
|
|
|
|
update_form.addRow(self.updateCheckBox)
|
|
|
|
layout.addLayout(update_hbox)
|
|
|
|
|
|
|
|
layout.addStretch()
|
|
|
|
|
2019-10-09 12:08:48 +00:00
|
|
|
btn_ok = QtWidgets.QPushButton("Ok")
|
2020-06-09 15:56:53 +00:00
|
|
|
btn_ok.clicked.connect(lambda: self.close()) # noqa
|
2019-10-09 12:08:48 +00:00
|
|
|
layout.addWidget(btn_ok)
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
super().show()
|
|
|
|
self.updateLabels()
|
|
|
|
|
|
|
|
def updateLabels(self):
|
2020-07-04 12:26:20 +00:00
|
|
|
if self.app.interface.is_open:
|
2020-06-09 15:56:53 +00:00
|
|
|
self.versionLabel.setText(
|
2020-07-04 12:26:20 +00:00
|
|
|
f"NanoVNA Firmware Version: {self.app.vna.name} "
|
|
|
|
f"v{self.app.vna.version}")
|
2019-10-09 12:08:48 +00:00
|
|
|
|
2019-10-09 16:35:36 +00:00
|
|
|
def updateSettings(self):
|
|
|
|
if self.updateCheckBox.isChecked():
|
|
|
|
self.app.settings.setValue("CheckForUpdates", "Yes")
|
|
|
|
else:
|
|
|
|
self.app.settings.setValue("CheckForUpdates", "No")
|
|
|
|
|
|
|
|
def askAboutUpdates(self):
|
|
|
|
logger.debug("Asking about automatic update checks")
|
2020-06-09 15:56:53 +00:00
|
|
|
selection = QtWidgets.QMessageBox.question(
|
|
|
|
self.app,
|
|
|
|
"Enable checking for updates?",
|
2020-06-25 17:48:03 +00:00
|
|
|
"Would you like NanoVNA-Saver to"
|
|
|
|
" check for updates automatically?")
|
2019-10-09 16:35:36 +00:00
|
|
|
if selection == QtWidgets.QMessageBox.Yes:
|
|
|
|
self.updateCheckBox.setChecked(True)
|
|
|
|
self.app.settings.setValue("CheckForUpdates", "Yes")
|
|
|
|
self.findUpdates()
|
|
|
|
elif selection == QtWidgets.QMessageBox.No:
|
|
|
|
self.updateCheckBox.setChecked(False)
|
|
|
|
self.app.settings.setValue("CheckForUpdates", "No")
|
2020-06-09 15:56:53 +00:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self.app,
|
|
|
|
"Checking for updates disabled",
|
2020-06-25 17:48:03 +00:00
|
|
|
'You can check for updates using the "About" window.')
|
2019-10-09 16:35:36 +00:00
|
|
|
else:
|
|
|
|
self.app.settings.setValue("CheckForUpdates", "Ask")
|
|
|
|
|
2019-10-11 12:16:51 +00:00
|
|
|
def findUpdates(self, automatic=False):
|
2020-07-04 12:26:20 +00:00
|
|
|
latest_version = Version()
|
2020-06-25 17:48:03 +00:00
|
|
|
latest_url = ""
|
2019-10-09 16:35:36 +00:00
|
|
|
try:
|
2020-06-25 17:48:03 +00:00
|
|
|
req = request.Request(VERSION_URL)
|
2019-10-12 18:48:19 +00:00
|
|
|
req.add_header('User-Agent', "NanoVNA-Saver/" + self.app.version)
|
2020-06-25 17:48:03 +00:00
|
|
|
for line in request.urlopen(req, timeout=3):
|
|
|
|
line = line.decode("utf-8")
|
|
|
|
if line.startswith("VERSION ="):
|
|
|
|
latest_version = Version(line[8:].strip(" \"'"))
|
|
|
|
if line.startswith("RELEASE_URL ="):
|
|
|
|
latest_url = line[13:].strip(" \"'")
|
2019-10-09 16:35:36 +00:00
|
|
|
except error.HTTPError as e:
|
|
|
|
logger.exception("Checking for updates produced an HTTP exception: %s", e)
|
2019-10-20 10:29:41 +00:00
|
|
|
self.updateLabel.setText("Connection error.")
|
2019-10-09 16:35:36 +00:00
|
|
|
return
|
2020-06-25 17:48:03 +00:00
|
|
|
except TypeError as e:
|
2019-10-09 16:35:36 +00:00
|
|
|
logger.exception("Checking for updates provided an unparseable file: %s", e)
|
2019-10-20 10:29:41 +00:00
|
|
|
self.updateLabel.setText("Data error reading versions.")
|
2019-10-09 16:35:36 +00:00
|
|
|
return
|
2019-10-19 22:03:22 +00:00
|
|
|
except error.URLError as e:
|
|
|
|
logger.exception("Checking for updates produced a URL exception: %s", e)
|
2019-10-20 10:29:41 +00:00
|
|
|
self.updateLabel.setText("Connection error.")
|
2019-10-19 22:03:22 +00:00
|
|
|
return
|
2019-10-09 16:35:36 +00:00
|
|
|
|
2020-07-04 12:26:20 +00:00
|
|
|
logger.info("Latest version is %s", latest_version)
|
2020-06-09 15:56:53 +00:00
|
|
|
this_version = Version(self.app.version)
|
|
|
|
logger.info("This is %s", this_version)
|
2019-10-09 16:35:36 +00:00
|
|
|
if latest_version > this_version:
|
|
|
|
logger.info("New update available: %s!", latest_version)
|
|
|
|
if automatic:
|
2020-06-09 15:56:53 +00:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self,
|
|
|
|
"Updates available",
|
2020-07-04 12:26:20 +00:00
|
|
|
f"There is a new update for NanoVNA-Saver available!\n"
|
|
|
|
f"Version {latest_version}\n\n"
|
|
|
|
f'Press "About" to find the update.')
|
2019-10-09 16:35:36 +00:00
|
|
|
else:
|
2020-06-09 15:56:53 +00:00
|
|
|
QtWidgets.QMessageBox.information(
|
|
|
|
self, "Updates available",
|
|
|
|
"There is a new update for NanoVNA-Saver available!")
|
|
|
|
self.updateLabel.setText(
|
|
|
|
f'<a href="{latest_url}">New version available</a>.')
|
2019-10-09 16:35:36 +00:00
|
|
|
self.updateLabel.setOpenExternalLinks(True)
|
|
|
|
else:
|
|
|
|
# Probably don't show a message box, just update the screen?
|
2019-10-11 12:16:51 +00:00
|
|
|
# Maybe consider showing it if not an automatic update.
|
2019-10-09 16:35:36 +00:00
|
|
|
#
|
2020-06-09 15:56:53 +00:00
|
|
|
self.updateLabel.setText(
|
2020-06-25 17:48:03 +00:00
|
|
|
f"Last checked: "
|
|
|
|
f"{strftime('%Y-%m-%d %H:%M:%S', localtime())}")
|
2019-10-09 16:35:36 +00:00
|
|
|
return
|