kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Initial work on a mouse-controlled marker.
rodzic
c736a49159
commit
35b8c18666
|
@ -45,6 +45,9 @@ class LogMagChart(Chart):
|
|||
self.chartWidth = 360
|
||||
self.chartHeight = 360
|
||||
self.name = name
|
||||
self.fstart = 0
|
||||
self.fstop = 0
|
||||
self.mouselocation = 0
|
||||
|
||||
self.setMinimumSize(self.chartWidth + 20 + self.leftMargin, self.chartHeight + 40)
|
||||
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
|
||||
|
@ -87,6 +90,8 @@ class LogMagChart(Chart):
|
|||
else:
|
||||
fstart = self.reference[0].freq
|
||||
fstop = self.reference[len(self.reference) - 1].freq
|
||||
self.fstart = fstart
|
||||
self.fstop = fstop
|
||||
fspan = fstop-fstart
|
||||
# Find scaling
|
||||
min = 100
|
||||
|
@ -123,6 +128,7 @@ class LogMagChart(Chart):
|
|||
span = max-min
|
||||
for i in range(min, max, 10):
|
||||
y = 30 + round((i-min)/span*(self.chartHeight-10))
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
|
||||
qp.setPen(QtCore.Qt.black)
|
||||
qp.drawText(3, 35, str(-min))
|
||||
|
@ -137,6 +143,11 @@ class LogMagChart(Chart):
|
|||
qp.setPen(QtCore.Qt.black)
|
||||
qp.drawText(x-20, 20+self.chartHeight+15, LogMagChart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
|
||||
|
||||
if self.mouselocation != 0:
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor(224,224,224)))
|
||||
x = self.leftMargin + 1 + round(self.chartWidth * (self.mouselocation - fstart) / fspan)
|
||||
qp.drawLine(x, 20, x, 20 + self.chartHeight +5)
|
||||
|
||||
qp.setPen(pen)
|
||||
for i in range(len(self.data)):
|
||||
re = self.data[i].re
|
||||
|
@ -188,4 +199,25 @@ class LogMagChart(Chart):
|
|||
return frequency
|
||||
if frequency < 5000000:
|
||||
return str(round(frequency / 1000)) + "k"
|
||||
return str(round(frequency / 1000000, 1)) + "M"
|
||||
return str(round(frequency / 1000000, 1)) + "M"
|
||||
|
||||
def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
|
||||
self.mouseMoveEvent(a0)
|
||||
|
||||
def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None:
|
||||
x = a0.x()
|
||||
absx = x - self.leftMargin
|
||||
if absx < 0 or absx > self.chartWidth:
|
||||
self.mouselocation = 0
|
||||
a0.ignore()
|
||||
return
|
||||
a0.accept()
|
||||
if self.fstop - self.fstart > 0:
|
||||
span = self.fstop - self.fstart
|
||||
step = span/self.chartWidth
|
||||
f = absx * step
|
||||
# self.mouselocation = f
|
||||
self.markers[0].setFrequency(str(round(f)))
|
||||
else:
|
||||
self.mouselocation = 0
|
||||
return
|
||||
|
|
|
@ -36,6 +36,7 @@ Datapoint = collections.namedtuple('Datapoint', 'freq re im')
|
|||
VID = 1155
|
||||
PID = 22336
|
||||
|
||||
|
||||
class NanoVNASaver(QtWidgets.QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -70,7 +71,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
outer.addWidget(scrollarea)
|
||||
self.setLayout(outer)
|
||||
scrollarea.setWidgetResizable(True)
|
||||
self.resize(1100, 950)
|
||||
self.resize(1150, 950)
|
||||
scrollarea.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
|
||||
self.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
|
||||
widget = QtWidgets.QWidget()
|
||||
|
@ -146,6 +147,10 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
marker_control_box.setMaximumWidth(400)
|
||||
marker_control_layout = QtWidgets.QFormLayout(marker_control_box)
|
||||
|
||||
mouse_marker = Marker("Mouse marker", QtGui.QColor(20, 255, 20))
|
||||
mouse_marker.updated.connect(self.dataUpdated)
|
||||
self.markers.append(mouse_marker)
|
||||
|
||||
marker1 = Marker("Marker 1", QtGui.QColor(255, 0, 20))
|
||||
marker1.updated.connect(self.dataUpdated)
|
||||
label, layout = marker1.getRow()
|
||||
|
@ -161,11 +166,15 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
self.s11SmithChart.setMarkers(self.markers)
|
||||
self.s21SmithChart.setMarkers(self.markers)
|
||||
|
||||
self.mousemarkerlabel = QtWidgets.QLabel("")
|
||||
self.mousemarkerlabel.setMinimumWidth(160)
|
||||
marker_control_layout.addRow(QtWidgets.QLabel("Mouse marker:"), self.mousemarkerlabel)
|
||||
|
||||
self.marker1label = QtWidgets.QLabel("")
|
||||
marker_control_layout.addRow(QtWidgets.QLabel("Marker 1: "), self.marker1label)
|
||||
marker_control_layout.addRow(QtWidgets.QLabel("Marker 1:"), self.marker1label)
|
||||
|
||||
self.marker2label = QtWidgets.QLabel("")
|
||||
marker_control_layout.addRow(QtWidgets.QLabel("Marker 2: "), self.marker2label)
|
||||
marker_control_layout.addRow(QtWidgets.QLabel("Marker 2:"), self.marker2label)
|
||||
|
||||
left_column.addWidget(marker_control_box)
|
||||
|
||||
|
@ -177,6 +186,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
s11_control_box.setTitle("S11")
|
||||
s11_control_layout = QtWidgets.QFormLayout()
|
||||
s11_control_box.setLayout(s11_control_layout)
|
||||
s11_control_box.setMaximumWidth(400)
|
||||
|
||||
self.s11_min_swr_label = QtWidgets.QLabel()
|
||||
s11_control_layout.addRow("Min VSWR:", self.s11_min_swr_label)
|
||||
|
@ -189,6 +199,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
s21_control_box.setTitle("S21")
|
||||
s21_control_layout = QtWidgets.QFormLayout()
|
||||
s21_control_box.setLayout(s21_control_layout)
|
||||
s21_control_box.setMaximumWidth(400)
|
||||
|
||||
self.s21_min_gain_label = QtWidgets.QLabel()
|
||||
s21_control_layout.addRow("Min gain:", self.s21_min_gain_label)
|
||||
|
@ -202,6 +213,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
tdr_control_box.setTitle("TDR")
|
||||
tdr_control_layout = QtWidgets.QFormLayout()
|
||||
tdr_control_box.setLayout(tdr_control_layout)
|
||||
tdr_control_box.setMaximumWidth(400)
|
||||
|
||||
self.tdr_velocity_dropdown = QtWidgets.QComboBox()
|
||||
self.tdr_velocity_dropdown.addItem("Jelly filled (0.64)", 0.64)
|
||||
|
@ -495,6 +507,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
|
||||
self.sweepProgressBar.setValue(0)
|
||||
self.btnSweep.setDisabled(True)
|
||||
self.mousemarkerlabel.setText("")
|
||||
self.marker1label.setText("")
|
||||
self.marker2label.setText("")
|
||||
self.s11_min_rl_label.setText("")
|
||||
|
@ -545,10 +558,17 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
im50str = "- j" + str(round(-1*im50, 3))
|
||||
else:
|
||||
im50str = "+ j" + str(round(im50, 3))
|
||||
self.marker1label.setText(str(round(re50, 3)) + im50str + " VSWR: 1:" + str(round(vswr, 3)))
|
||||
|
||||
self.mousemarkerlabel.setText(str(round(re50, 3)) + im50str + " VSWR: 1:" + str(round(vswr, 3)))
|
||||
if self.markers[1].location != -1:
|
||||
im50, re50, vswr = self.vswr(self.data[self.markers[1].location])
|
||||
if (im50 < 0):
|
||||
im50str = "- j" + str(round(-1*im50, 3))
|
||||
else:
|
||||
im50str = "+ j" + str(round(im50, 3))
|
||||
self.marker1label.setText(str(round(re50, 3)) + im50str + " VSWR: 1:" + str(round(vswr, 3)))
|
||||
|
||||
if self.markers[2].location != -1:
|
||||
im50, re50, vswr = self.vswr(self.data[self.markers[2].location])
|
||||
if (im50 < 0):
|
||||
im50str = "- j" + str(round(im50, 3))
|
||||
else:
|
||||
|
|
Ładowanie…
Reference in New Issue