kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Cleanup
rodzic
71dc547080
commit
c1e57c581d
|
@ -19,11 +19,8 @@ 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_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, space_str=" ")
|
||||
FMT_REACT = SITools.Format(max_nr_digits=5, space_str=" ", allow_strip=True)
|
||||
|
||||
|
|
|
@ -20,29 +20,27 @@ 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:
|
||||
# TODO: Fix wrong type here
|
||||
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.setText(str(self.nextFrequency))
|
||||
self.textEdited.emit(self.text())
|
||||
return
|
||||
if a0.key() == QtCore.Qt.Key_Down and \
|
||||
self.previousFrequency != -1:
|
||||
if a0.key() == QtCore.Qt.Key_Down and self.previousFrequency != -1:
|
||||
a0.accept()
|
||||
self.setText(self.previousFrequency)
|
||||
self.setText(str(self.previousFrequency))
|
||||
self.textEdited.emit(self.text())
|
||||
return
|
||||
super().keyPressEvent(a0)
|
||||
|
|
|
@ -21,13 +21,10 @@ from PyQt5 import QtGui, QtWidgets, QtCore
|
|||
from PyQt5.QtCore import pyqtSignal
|
||||
|
||||
from NanoVNASaver import RFTools
|
||||
from NanoVNASaver.Formatting import \
|
||||
format_frequency, format_capacitance, format_inductance, \
|
||||
format_complex_imp, format_resistance, format_vswr, format_phase, \
|
||||
format_q_factor, format_gain, format_group_delay
|
||||
from NanoVNASaver.Formatting import format_frequency, format_capacitance, format_inductance, format_complex_imp, \
|
||||
format_resistance, format_vswr, format_phase, format_q_factor, format_gain, format_group_delay
|
||||
|
||||
from NanoVNASaver.Inputs import MarkerFrequencyInputWidget as \
|
||||
FrequencyInput
|
||||
from NanoVNASaver.Inputs import MarkerFrequencyInputWidget as FrequencyInput
|
||||
|
||||
|
||||
class Marker(QtCore.QObject):
|
||||
|
@ -53,9 +50,9 @@ class Marker(QtCore.QObject):
|
|||
self.frequencyInput.setAlignment(QtCore.Qt.AlignRight)
|
||||
self.frequencyInput.textEdited.connect(self.setFrequency)
|
||||
|
||||
###############################################################
|
||||
# Data display label
|
||||
###############################################################
|
||||
################################################################################################################
|
||||
# Data display labels
|
||||
################################################################################################################
|
||||
|
||||
self.frequency_label = QtWidgets.QLabel("")
|
||||
self.frequency_label.setMinimumWidth(100)
|
||||
|
@ -118,9 +115,9 @@ class Marker(QtCore.QObject):
|
|||
self.layout.addWidget(self.btnColorPicker)
|
||||
self.layout.addWidget(self.isMouseControlledRadioButton)
|
||||
|
||||
###############################################################
|
||||
################################################################################################################
|
||||
# Data display layout
|
||||
###############################################################
|
||||
################################################################################################################
|
||||
|
||||
self.group_box = QtWidgets.QGroupBox(self.name)
|
||||
self.group_box.setMaximumWidth(340)
|
||||
|
@ -242,8 +239,7 @@ class Marker(QtCore.QObject):
|
|||
upper_stepsize = data[-1].freq - data[-2].freq
|
||||
|
||||
# We are outside the bounds of the data, so we can't put in a marker
|
||||
if (self.frequency + lower_stepsize/2 < min_freq or
|
||||
self.frequency - upper_stepsize/2 > max_freq):
|
||||
if self.frequency + lower_stepsize/2 < min_freq or self.frequency - upper_stepsize/2 > max_freq:
|
||||
return
|
||||
|
||||
min_distance = max_freq
|
||||
|
@ -294,16 +290,12 @@ class Marker(QtCore.QObject):
|
|||
s11 = s11data[self.location]
|
||||
|
||||
imp = s11.impedance()
|
||||
cap_str = format_capacitance(
|
||||
RFTools.impedance_to_capacitance(imp, s11.freq))
|
||||
ind_str = format_inductance(
|
||||
RFTools.impedance_to_inductance(imp, s11.freq))
|
||||
cap_str = format_capacitance(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_capacitance(imp_p, s11.freq))
|
||||
ind_p_str = format_inductance(
|
||||
RFTools.impedance_to_inductance(imp_p, s11.freq))
|
||||
cap_p_str = format_capacitance(RFTools.impedance_to_capacitance(imp_p, s11.freq))
|
||||
ind_p_str = format_inductance(RFTools.impedance_to_inductance(imp_p, s11.freq))
|
||||
|
||||
if imp.imag < 0:
|
||||
x_str = cap_str
|
||||
|
@ -331,14 +323,10 @@ class Marker(QtCore.QObject):
|
|||
|
||||
self.vswr_label.setText(format_vswr(s11.vswr))
|
||||
self.s11_phase_label.setText(format_phase(s11.phase))
|
||||
self.quality_factor_label.setText(
|
||||
format_q_factor(s11.qFactor()))
|
||||
self.quality_factor_label.setText(format_q_factor(s11.qFactor()))
|
||||
|
||||
self.returnloss_label.setText(
|
||||
format_gain(s11.gain, self.returnloss_is_positive))
|
||||
self.s11_group_delay_label.setText(
|
||||
format_group_delay(RFTools.groupDelay(s11data, self.location))
|
||||
)
|
||||
self.returnloss_label.setText(format_gain(s11.gain, self.returnloss_is_positive))
|
||||
self.s11_group_delay_label.setText(format_group_delay(RFTools.groupDelay(s11data, self.location)))
|
||||
|
||||
# skip if no valid s21 data
|
||||
if len(s21data) != len(s11data):
|
||||
|
@ -348,6 +336,4 @@ class Marker(QtCore.QObject):
|
|||
|
||||
self.s21_phase_label.setText(format_phase(s21.phase))
|
||||
self.gain_label.setText(format_gain(s21.gain))
|
||||
self.s21_group_delay_label.setText(
|
||||
format_group_delay(RFTools.groupDelay(s21data, self.location) / 2)
|
||||
)
|
||||
self.s21_group_delay_label.setText(format_group_delay(RFTools.groupDelay(s21data, self.location) / 2))
|
||||
|
|
|
@ -123,12 +123,10 @@ class Datapoint(NamedTuple):
|
|||
return abs(imp.imag / imp.real)
|
||||
|
||||
def capacitiveEquivalent(self, ref_impedance: float = 50) -> float:
|
||||
return impedance_to_capacitance(
|
||||
self.impedance(ref_impedance), self.freq)
|
||||
return impedance_to_capacitance(self.impedance(ref_impedance), self.freq)
|
||||
|
||||
def inductiveEquivalent(self, ref_impedance: float = 50) -> float:
|
||||
return impedance_to_inductance(
|
||||
self.impedance(ref_impedance), self.freq)
|
||||
return impedance_to_inductance(self.impedance(ref_impedance), self.freq)
|
||||
|
||||
|
||||
def groupDelay(data: List[Datapoint], index: int) -> float:
|
||||
|
|
|
@ -77,10 +77,8 @@ class Value:
|
|||
|
||||
def __str__(self) -> str:
|
||||
fmt = self.fmt
|
||||
if fmt.assume_infinity and \
|
||||
abs(self._value) >= 10 ** ((fmt.max_offset + 1) * 3):
|
||||
return (("-" if self._value < 0 else "") +
|
||||
"\N{INFINITY}" + fmt.space_str + self._unit)
|
||||
if fmt.assume_infinity and abs(self._value) >= 10 ** ((fmt.max_offset + 1) * 3):
|
||||
return ("-" if self._value < 0 else "") + "\N{INFINITY}" + fmt.space_str + self._unit
|
||||
if self._value < fmt.printable_min:
|
||||
return fmt.unprintable_under + self._unit
|
||||
if self._value > fmt.printable_max:
|
||||
|
@ -89,10 +87,7 @@ class Value:
|
|||
if self._value == 0:
|
||||
offset = 0
|
||||
else:
|
||||
offset = clamp_value(
|
||||
int(math.log10(abs(self._value)) // 3),
|
||||
fmt.min_offset,
|
||||
fmt.max_offset)
|
||||
offset = clamp_value(int(math.log10(abs(self._value)) // 3), fmt.min_offset, fmt.max_offset)
|
||||
|
||||
real = float(self._value) / (10 ** (offset * 3))
|
||||
|
||||
|
@ -156,13 +151,10 @@ class Value:
|
|||
self._value = -math.inf
|
||||
else:
|
||||
try:
|
||||
self._value = (decimal.Decimal(value, context=Value.CTX) *
|
||||
decimal.Decimal(factor, context=Value.CTX))
|
||||
self._value = (decimal.Decimal(value, context=Value.CTX) * decimal.Decimal(factor, context=Value.CTX))
|
||||
except decimal.InvalidOperation:
|
||||
raise ValueError
|
||||
self._value = clamp_value(self._value,
|
||||
self.fmt.parse_clamp_min,
|
||||
self.fmt.parse_clamp_max)
|
||||
self._value = clamp_value(self._value, self.fmt.parse_clamp_min, self.fmt.parse_clamp_max)
|
||||
return self
|
||||
|
||||
@property
|
||||
|
|
Ładowanie…
Reference in New Issue