2019-08-29 13:10:35 +00:00
|
|
|
# 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/>.
|
2019-08-29 13:04:40 +00:00
|
|
|
import collections
|
|
|
|
from typing import List
|
2019-08-29 10:19:58 +00:00
|
|
|
|
|
|
|
from PyQt5 import QtGui, QtWidgets, QtCore
|
2019-08-29 13:42:35 +00:00
|
|
|
from PyQt5.QtCore import pyqtSignal
|
|
|
|
|
2019-08-29 13:04:40 +00:00
|
|
|
Datapoint = collections.namedtuple('Datapoint', 'freq re im')
|
2019-08-29 10:19:58 +00:00
|
|
|
|
|
|
|
|
2019-08-29 13:42:35 +00:00
|
|
|
class Marker(QtCore.QObject):
|
2019-08-29 10:19:58 +00:00
|
|
|
name = "Marker"
|
2019-08-29 13:04:40 +00:00
|
|
|
frequency = 0
|
2019-08-29 10:19:58 +00:00
|
|
|
color = QtGui.QColor()
|
2019-08-29 13:04:40 +00:00
|
|
|
location = -1
|
2019-08-29 10:19:58 +00:00
|
|
|
|
2019-08-29 13:42:35 +00:00
|
|
|
updated = pyqtSignal()
|
|
|
|
|
2019-08-29 10:19:58 +00:00
|
|
|
def __init__(self, name, initialColor, frequency=""):
|
|
|
|
super().__init__()
|
|
|
|
self.name = name
|
2019-08-29 13:04:40 +00:00
|
|
|
|
|
|
|
if frequency.isnumeric():
|
|
|
|
self.frequency = int(frequency)
|
2019-08-29 10:19:58 +00:00
|
|
|
self.frequencyInput = QtWidgets.QLineEdit(frequency)
|
|
|
|
self.frequencyInput.setAlignment(QtCore.Qt.AlignRight)
|
|
|
|
self.frequencyInput.returnPressed.connect(lambda: self.setFrequency(self.frequencyInput.text()))
|
|
|
|
|
|
|
|
self.btnColorPicker = QtWidgets.QPushButton("█")
|
|
|
|
self.btnColorPicker.setFixedWidth(20)
|
2019-08-29 13:04:40 +00:00
|
|
|
self.setColor(initialColor)
|
2019-08-29 10:19:58 +00:00
|
|
|
self.btnColorPicker.clicked.connect(lambda: self.setColor(QtWidgets.QColorDialog.getColor()))
|
|
|
|
|
|
|
|
self.layout = QtWidgets.QHBoxLayout()
|
|
|
|
self.layout.addWidget(self.frequencyInput)
|
|
|
|
self.layout.addWidget(self.btnColorPicker)
|
|
|
|
|
|
|
|
def setFrequency(self, frequency):
|
2019-08-29 13:42:35 +00:00
|
|
|
if frequency.isnumeric():
|
|
|
|
self.frequency = int(frequency)
|
|
|
|
self.updated.emit()
|
|
|
|
else:
|
|
|
|
self.frequency = 0
|
|
|
|
return
|
2019-08-29 10:19:58 +00:00
|
|
|
|
|
|
|
def setColor(self, color):
|
|
|
|
self.color = color
|
2019-08-29 13:04:40 +00:00
|
|
|
p = self.btnColorPicker.palette()
|
|
|
|
p.setColor(QtGui.QPalette.ButtonText, self.color)
|
|
|
|
self.btnColorPicker.setPalette(p)
|
2019-08-29 10:19:58 +00:00
|
|
|
|
|
|
|
def getRow(self):
|
2019-08-29 13:04:40 +00:00
|
|
|
return (QtWidgets.QLabel(self.name), self.layout)
|
|
|
|
|
|
|
|
def findLocation(self, data: List[Datapoint]):
|
|
|
|
self.location = -1
|
2019-08-29 13:42:35 +00:00
|
|
|
if self.frequency == 0:
|
|
|
|
# No frequency set for this marker
|
|
|
|
return
|
2019-08-29 20:56:21 +00:00
|
|
|
if len(data) == 0:
|
|
|
|
# Set the frequency before loading any data
|
|
|
|
return
|
2019-08-29 13:42:35 +00:00
|
|
|
|
2019-08-29 13:04:40 +00:00
|
|
|
stepsize = data[1].freq-data[0].freq
|
|
|
|
for i in range(len(data)):
|
|
|
|
if abs(data[i].freq-self.frequency) <= (stepsize/2):
|
|
|
|
self.location = i
|
|
|
|
return
|