Use FrequencyInputWidget for sweep

pull/116/head
Holger Mueller 2019-12-14 14:01:37 +01:00
rodzic 20a219dbe4
commit 18e9216a4b
4 zmienionych plików z 162 dodań i 50 usunięć

Wyświetl plik

@ -0,0 +1,90 @@
# NanoVNASaver
# A python program to view and export Touchstone data from a NanoVNA
# 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/>.
import math
from NanoVNASaver import SITools
FMT_FREQ = SITools.Format(space_str=" ")
FMT_FREQ_INPUTS = SITools.Format(max_nr_digits=10, allow_strip=True,
printable_min=0, unprintable_under="- ")
FMT_Q_FACTOR = SITools.Format(max_nr_digits=4, assume_infinity=False,
min_offset=0, max_offset=0, allow_strip=True)
FMT_GROUP_DELAY = SITools.Format(max_nr_digits=5)
FMT_REACT = SITools.Format(max_nr_digits=5, space_str=" ", allow_strip=True)
def format_frequency(freq: float, fmt=FMT_FREQ) -> str:
return str(SITools.Value(freq, "Hz", fmt))
def format_frequency_inputs(freq: float) -> str:
return str(SITools.Value(freq, "Hz", FMT_FREQ_INPUTS))
def format_gain(val: float, invert: bool = False) -> str:
if invert:
val = -val
return f"{val:.3f}dB"
def format_q_factor(val: float) -> str:
if val < 0 or val > 10000.0:
return "\N{INFINITY}"
return str(SITools.Value(val, fmt=FMT_Q_FACTOR))
def format_vswr(val: float) -> str:
return f"{val:.3f}"
def format_resistance(val: float) -> str:
if val < 0:
return "- \N{OHM SIGN}"
return str(SITools.Value(val, "\N{OHM SIGN}", FMT_REACT))
def format_capacity(val: float, allow_negative: bool = True) -> str:
if not allow_negative and val < 0:
return "- pF"
return str(SITools.Value(val, "F", FMT_REACT))
def format_inductance(val: float, allow_negative: bool = True) -> str:
if not allow_negative and val < 0:
return "- nH"
return str(SITools.Value(val, "H", FMT_REACT))
def format_group_delay(val: float) -> str:
return str(SITools.Value(val, "s", fmt=FMT_GROUP_DELAY))
def format_phase(val: float) -> str:
return f"{math.degrees(val):.2f}\N{DEGREE SIGN}"
def format_complex_imp(z: complex) -> str:
if z.real > 0:
s = f"{z.real:.4g}"
else:
s = "- "
if z.imag < 0:
s += "-j"
else:
s += "+j"
return s + f"{abs(z.imag):.4g}\N{OHM SIGN}"

Wyświetl plik

@ -0,0 +1,48 @@
# NanoVNASaver
# A python program to view and export Touchstone data from a NanoVNA
# 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/>.
from PyQt5 import QtGui, QtWidgets, QtCore
from NanoVNASaver.Formatting import format_frequency_inputs
class FrequencyInputWidget(QtWidgets.QLineEdit):
def __init__(self, text=""):
super().__init__(text)
self.nextFrequency = -1
self.previousFrequency = -1
def setText(self, text: str) -> None:
super().setText(format_frequency_inputs(text))
class MarkerFrequencyInputWidget(FrequencyInputWidget):
def keyPressEvent(self, a0: QtGui.QKeyEvent) -> None:
if a0.type() == QtCore.QEvent.KeyPress:
if a0.key() == QtCore.Qt.Key_Up and self.nextFrequency != -1:
a0.accept()
self.setText(self.nextFrequency)
self.textEdited.emit(self.text())
return
if a0.key() == QtCore.Qt.Key_Down and \
self.previousFrequency != -1:
a0.accept()
self.setText(self.previousFrequency)
self.textEdited.emit(self.text())
return
super().keyPressEvent(a0)

Wyświetl plik

@ -22,6 +22,8 @@ from PyQt5.QtCore import pyqtSignal
from NanoVNASaver import SITools
from NanoVNASaver import RFTools
from NanoVNASaver.Inputs import MarkerFrequencyInputWidget as \
FrequencyInput
FMT_FREQ = SITools.Format(space_str=" ")
FMT_FREQ_INPUT = SITools.Format(max_nr_digits=10, allow_strip=True,
@ -101,32 +103,6 @@ def format_complex_imp(z: complex) -> str:
return s + " \N{OHM SIGN}"
class FrequencyInput(QtWidgets.QLineEdit):
def __init__(self, text=""):
super().__init__(text)
self.nextFrequency = -1
self.previousFrequency = -1
def setText(self, text: str) -> None:
super().setText(format_frequency(text, FMT_FREQ_INPUT))
def keyPressEvent(self, a0: QtGui.QKeyEvent) -> None:
if a0.type() == QtCore.QEvent.KeyPress:
if a0.key() == QtCore.Qt.Key_Up and self.nextFrequency != -1:
a0.accept()
self.setText(self.nextFrequency)
self.textEdited.emit(self.text())
return
if a0.key() == QtCore.Qt.Key_Down and \
self.previousFrequency != -1:
a0.accept()
self.setText(self.previousFrequency)
self.textEdited.emit(self.text())
return
super().keyPressEvent(a0)
class Marker(QtCore.QObject):
name = "Marker"
frequency = 0
@ -412,13 +388,13 @@ class Marker(QtCore.QObject):
imp = s11.impedance()
cap_str = format_capacitance(
RFTools.impedance_to_capacity(imp, s11.freq))
RFTools.impedance_to_capacitance(imp, s11.freq))
ind_str = format_inductance(
RFTools.impedance_to_inductance(imp, s11.freq))
imp_p = RFTools.serial_to_parallel(imp)
cap_p_str = format_capacitance(
RFTools.impedance_to_capacity(imp_p, s11.freq))
RFTools.impedance_to_capacitance(imp_p, s11.freq))
ind_p_str = format_inductance(
RFTools.impedance_to_inductance(imp_p, s11.freq))

Wyświetl plik

@ -34,7 +34,8 @@ from .Chart import Chart, PhaseChart, VSWRChart, PolarChart, SmithChart, LogMagC
RealImaginaryChart, MagnitudeChart, MagnitudeZChart, CombinedLogMagChart, SParameterChart, PermeabilityChart, \
GroupDelayChart, CapacitanceChart, InductanceChart
from .Calibration import CalibrationWindow, Calibration
from .Marker import Marker, FrequencyInput
from .Inputs import FrequencyInputWidget
from .Marker import Marker
from .SweepWorker import SweepWorker
from .Touchstone import Touchstone
from .Analysis import Analysis, LowPassAnalysis, HighPassAnalysis, BandPassAnalysis, BandStopAnalysis, \
@ -204,9 +205,9 @@ class NanoVNASaver(QtWidgets.QWidget):
layout.addWidget(self.marker_frame, 0, 1)
layout.addLayout(right_column, 0, 2)
################################################################################################################
#######################################################################
# Sweep control
################################################################################################################
#######################################################################
sweep_control_box = QtWidgets.QGroupBox()
sweep_control_box.setMaximumWidth(250)
@ -216,42 +217,39 @@ class NanoVNASaver(QtWidgets.QWidget):
line = QtWidgets.QFrame()
line.setFrameShape(QtWidgets.QFrame.VLine)
# sweep_input_layout = QtWidgets.QHBoxLayout()
sweep_input_layout = QtWidgets.QFormLayout()
# sweep_input_left_layout = QtWidgets.QFormLayout()
# sweep_input_right_layout = QtWidgets.QFormLayout()
# sweep_input_layout.addLayout(sweep_input_left_layout)
# sweep_input_layout.addWidget(line)
# sweep_input_layout.addLayout(sweep_input_right_layout)
sweep_input_layout = QtWidgets.QHBoxLayout()
sweep_input_left_layout = QtWidgets.QFormLayout()
sweep_input_right_layout = QtWidgets.QFormLayout()
sweep_input_layout.addLayout(sweep_input_left_layout)
sweep_input_layout.addWidget(line)
sweep_input_layout.addLayout(sweep_input_right_layout)
sweep_control_layout.addRow(sweep_input_layout)
self.sweepStartInput = FrequencyInput()
self.sweepStartInput = FrequencyInputWidget()
self.sweepStartInput.setMinimumWidth(60)
self.sweepStartInput.setAlignment(QtCore.Qt.AlignRight)
self.sweepStartInput.textEdited.connect(self.updateCenterSpan)
self.sweepStartInput.textChanged.connect(self.updateStepSize)
# sweep_input_left_layout.addRow(QtWidgets.QLabel("Start"), self.sweepStartInput)
sweep_input_layout.addRow(QtWidgets.QLabel("Start"), self.sweepStartInput)
sweep_input_left_layout.addRow(QtWidgets.QLabel("Start"), self.sweepStartInput)
self.sweepEndInput = FrequencyInput()
self.sweepEndInput = FrequencyInputWidget()
self.sweepEndInput.setAlignment(QtCore.Qt.AlignRight)
self.sweepEndInput.textEdited.connect(self.updateCenterSpan)
self.sweepEndInput.textChanged.connect(self.updateStepSize)
# sweep_input_left_layout.addRow(QtWidgets.QLabel("Stop"), self.sweepEndInput)
sweep_input_layout.addRow(QtWidgets.QLabel("Stop"), self.sweepEndInput)
sweep_input_left_layout.addRow(QtWidgets.QLabel("Stop"), self.sweepEndInput)
self.sweepCenterInput = FrequencyInput()
self.sweepCenterInput = FrequencyInputWidget()
self.sweepCenterInput.setMinimumWidth(60)
self.sweepCenterInput.setAlignment(QtCore.Qt.AlignRight)
self.sweepCenterInput.textEdited.connect(self.updateStartEnd)
# sweep_input_right_layout.addRow(QtWidgets.QLabel("Center"), self.sweepCenterInput)
sweep_input_layout.addRow(QtWidgets.QLabel("Center"), self.sweepCenterInput)
self.sweepSpanInput = FrequencyInput()
sweep_input_right_layout.addRow(QtWidgets.QLabel("Center"), self.sweepCenterInput)
self.sweepSpanInput = FrequencyInputWidget()
self.sweepSpanInput.setAlignment(QtCore.Qt.AlignRight)
self.sweepSpanInput.textEdited.connect(self.updateStartEnd)
# sweep_input_right_layout.addRow(QtWidgets.QLabel("Span"), self.sweepSpanInput)
sweep_input_layout.addRow(QtWidgets.QLabel("Span"), self.sweepSpanInput)
sweep_input_right_layout.addRow(QtWidgets.QLabel("Span"), self.sweepSpanInput)
self.sweepCountInput = QtWidgets.QLineEdit(self.settings.value("Segments", "1"))
self.sweepCountInput.setAlignment(QtCore.Qt.AlignRight)