nanovna-saver/src/NanoVNASaver/__main__.py

116 wiersze
3.2 KiB
Python
Czysty Zwykły widok Historia

#! /bin/env python
#
# NanoVNASaver
#
# A python program to view and export Touchstone data from a NanoVNA
2020-06-25 17:52:30 +00:00
# Copyright (C) 2019, 2020 Rune B. Broberg
2021-06-30 05:21:14 +00:00
# Copyright (C) 2020,2021 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/>.
"""
NanoVNASaver
A multiplatform tool to save Touchstone files from the
NanoVNA, sweep frequency spans in segments to gain more
data points, and generally display and analyze the
resulting data.
"""
import argparse
2019-09-16 13:47:37 +00:00
import logging
import sys
2019-08-28 13:43:02 +00:00
2023-03-12 07:02:58 +00:00
from PyQt6 import QtWidgets
2019-08-27 14:00:56 +00:00
from NanoVNASaver.About import version, INFO
from NanoVNASaver.NanoVNASaver import NanoVNASaver
from NanoVNASaver.Touchstone import Touchstone
2019-08-28 12:18:56 +00:00
def main():
parser = argparse.ArgumentParser(
description=__doc__,
2023-03-08 08:40:39 +00:00
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"-d", "--debug", action="store_true", help="Set loglevel to debug"
)
parser.add_argument(
"-D", "--debug-file", help="File to write debug logging output to"
)
parser.add_argument(
"-f",
"--file",
help="Touchstone file to load as sweep for off" " device usage",
)
parser.add_argument(
"-r",
"--ref-file",
help="Touchstone file to load as reference for off" " device usage",
)
parser.add_argument(
"--version", action="version", version=f"NanoVNASaver {version}"
2023-03-08 08:40:39 +00:00
)
args = parser.parse_args()
console_log_level = logging.WARNING
file_log_level = logging.DEBUG
print(INFO)
2019-09-16 13:47:37 +00:00
if args.debug:
2019-10-01 12:53:01 +00:00
console_log_level = logging.DEBUG
2019-09-16 13:47:37 +00:00
logger = logging.getLogger("NanoVNASaver")
2019-09-16 19:41:01 +00:00
logger.setLevel(logging.DEBUG)
2019-09-16 13:47:37 +00:00
ch = logging.StreamHandler()
ch.setLevel(console_log_level)
formatter = logging.Formatter(
2023-03-08 08:40:39 +00:00
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
2019-09-16 13:47:37 +00:00
ch.setFormatter(formatter)
logger.addHandler(ch)
if args.debug_file:
fh = logging.FileHandler(args.debug_file)
fh.setLevel(file_log_level)
fh.setFormatter(formatter)
logger.addHandler(fh)
2019-09-16 13:47:37 +00:00
logger.info("Startup...")
app = QtWidgets.QApplication(sys.argv)
2019-08-27 14:00:56 +00:00
window = NanoVNASaver()
window.show()
if args.file:
t = Touchstone(args.file)
t.load()
window.saveData(t.s11, t.s21, args.file)
window.dataUpdated()
if args.ref_file:
t = Touchstone(args.ref_file)
t.load()
window.setReference(t.s11, t.s21, args.ref_file)
window.dataUpdated()
2020-07-11 12:00:05 +00:00
try:
2023-03-12 07:02:58 +00:00
app.exec()
2020-07-11 12:00:05 +00:00
except BaseException as exc:
logger.exception("%s", exc)
2021-07-05 09:37:48 +00:00
raise exc
2022-05-27 07:03:37 +00:00
2023-03-08 08:40:39 +00:00
if __name__ == "__main__":
main()