diff --git a/.gitignore b/.gitignore index d2c55d6..59a5b77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /venv/ .idea +/build/ +/dist/ +/nanovna-saver.spec diff --git a/LogMagChart.py b/LogMagChart.py index 218cd1d..1d91f79 100644 --- a/LogMagChart.py +++ b/LogMagChart.py @@ -58,6 +58,8 @@ class LogMagChart(QtWidgets.QWidget): self.marker1Color = QtGui.QColor(255, 0, 20) self.marker2Color = QtGui.QColor(20, 0, 255) + self.sweepColor = QtGui.QColor(220, 200, 30, 128) + def resizeEvent(self, a0: QtGui.QResizeEvent) -> None: self.chartWidth = a0.size().width()-20-self.leftMargin @@ -80,7 +82,7 @@ class LogMagChart(QtWidgets.QWidget): def drawValues(self, qp: QtGui.QPainter): if len(self.data) == 0: return - pen = QtGui.QPen(QtGui.QColor(220, 200, 30, 128)) + pen = QtGui.QPen(self.sweepColor) pen.setWidth(2) highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255)) highlighter.setWidth(3) @@ -169,4 +171,8 @@ class LogMagChart(QtWidgets.QWidget): return frequency if frequency < 5000000: return str(round(frequency / 1000)) + "k" - return str(round(frequency / 1000000, 1)) + "M" \ No newline at end of file + return str(round(frequency / 1000000, 1)) + "M" + + def setSweepColor(self, color : QtGui.QColor): + self.sweepColor = color + self.update() \ No newline at end of file diff --git a/Marker.py b/Marker.py index 6609a00..e3db05c 100644 --- a/Marker.py +++ b/Marker.py @@ -43,7 +43,7 @@ class Marker(QtCore.QObject): self.btnColorPicker = QtWidgets.QPushButton("█") self.btnColorPicker.setFixedWidth(20) self.setColor(initialColor) - self.btnColorPicker.clicked.connect(lambda: self.setColor(QtWidgets.QColorDialog.getColor())) + self.btnColorPicker.clicked.connect(lambda: self.setColor(QtWidgets.QColorDialog.getColor(self.color, options=QtWidgets.QColorDialog.ShowAlphaChannel))) self.layout = QtWidgets.QHBoxLayout() self.layout.addWidget(self.frequencyInput) @@ -58,10 +58,11 @@ class Marker(QtCore.QObject): return def setColor(self, color): - self.color = color - p = self.btnColorPicker.palette() - p.setColor(QtGui.QPalette.ButtonText, self.color) - self.btnColorPicker.setPalette(p) + if color.isValid(): + self.color = color + p = self.btnColorPicker.palette() + p.setColor(QtGui.QPalette.ButtonText, self.color) + self.btnColorPicker.setPalette(p) def getRow(self): return (QtWidgets.QLabel(self.name), self.layout) diff --git a/NanoVNASaver.py b/NanoVNASaver.py index 11225d0..acf6fec 100644 --- a/NanoVNASaver.py +++ b/NanoVNASaver.py @@ -54,12 +54,16 @@ class NanoVNASaver(QtWidgets.QWidget): self.serialPort = "COM11" # self.serialSpeed = "115200" + self.color = QtGui.QColor(160, 140, 20, 128) + self.setWindowTitle("NanoVNA Saver") layout = QtWidgets.QGridLayout() self.setLayout(layout) self.smithChart = SmithChart("S11") self.s21SmithChart = SmithChart("S21") + self.s11LogMag = LogMagChart("S11 Return Loss") + self.s21LogMag = LogMagChart("S21 Gain") left_column = QtWidgets.QVBoxLayout() right_column = QtWidgets.QVBoxLayout() @@ -92,6 +96,13 @@ class NanoVNASaver(QtWidgets.QWidget): sweep_control_layout.addRow(QtWidgets.QLabel("Sweep count"), self.sweepCountInput) + self.btnColorPicker = QtWidgets.QPushButton("█") + self.btnColorPicker.setFixedWidth(20) + self.setSweepColor(self.color) + self.btnColorPicker.clicked.connect(lambda: self.setSweepColor(QtWidgets.QColorDialog.getColor(self.color, options=QtWidgets.QColorDialog.ShowAlphaChannel))) + + sweep_control_layout.addRow("Sweep color", self.btnColorPicker) + self.sweepProgressBar = QtWidgets.QProgressBar() self.sweepProgressBar.setMaximum(100) self.sweepProgressBar.setValue(0) @@ -260,8 +271,6 @@ class NanoVNASaver(QtWidgets.QWidget): self.lister = QtWidgets.QPlainTextEdit() self.lister.setFixedHeight(100) - self.s11LogMag = LogMagChart("S11 Return Loss") - self.s21LogMag = LogMagChart("S21 Gain") charts = QtWidgets.QGridLayout() charts.addWidget(self.smithChart, 0, 0) charts.addWidget(self.s21SmithChart, 1, 0) @@ -542,4 +551,16 @@ class NanoVNASaver(QtWidgets.QWidget): peak = np.max(td) # We should check that this is an actual *peak*, and not just a vague maximum index_peak = np.argmax(td) - self.tdr_result_label.setText(str(round(distance_axis[index_peak]/2, 3)) + " m") \ No newline at end of file + self.tdr_result_label.setText(str(round(distance_axis[index_peak]/2, 3)) + " m") + + def setSweepColor(self, color : QtGui.QColor): + if color.isValid(): + self.color = color + p = self.btnColorPicker.palette() + p.setColor(QtGui.QPalette.ButtonText, color) + self.btnColorPicker.setPalette(p) + + self.smithChart.setSweepColor(color) + self.s21SmithChart.setSweepColor(color) + self.s11LogMag.setSweepColor(color) + self.s21LogMag.setSweepColor(color) \ No newline at end of file diff --git a/SmithChart.py b/SmithChart.py index 53bc601..54d2109 100644 --- a/SmithChart.py +++ b/SmithChart.py @@ -46,6 +46,7 @@ class SmithChart(QtWidgets.QWidget): self.marker1Color = QtGui.QColor(255, 0, 20) self.marker2Color = QtGui.QColor(20, 0, 255) + self.sweepColor = QtGui.QColor(220, 200, 30, 128) def resizeEvent(self, a0: QtGui.QResizeEvent) -> None: self.chartWidth = min(a0.size().width()-40, a0.size().height()-40) @@ -87,7 +88,7 @@ class SmithChart(QtWidgets.QWidget): qp.drawArc(centerX - self.chartWidth*2, centerY, self.chartWidth*5, -self.chartHeight*5, int(-93.85 * 16), int(-18.85 * 16)) # Im(Z) = 0.2 def drawValues(self, qp: QtGui.QPainter): - pen = QtGui.QPen(QtGui.QColor(220, 200, 30, 128)) + pen = QtGui.QPen(self.sweepColor) pen.setWidth(2) highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255)) highlighter.setWidth(3) @@ -120,4 +121,8 @@ class SmithChart(QtWidgets.QWidget): self.markers = markers def heightForWidth(self, a0: int) -> int: - return a0 \ No newline at end of file + return a0 + + def setSweepColor(self, color : QtGui.QColor): + self.sweepColor = color + self.update() \ No newline at end of file