nanovna-saver/NanoVNASaver/Controls/MarkerControl.py

106 wiersze
3.8 KiB
Python
Czysty Zwykły widok Historia

2020-07-17 19:57:03 +00:00
# NanoVNASaver
#
# A python program to view and export Touchstone data from a NanoVNA
# Copyright (C) 2019, 2020 Rune B. Broberg
2021-06-30 05:21:14 +00:00
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
2020-07-17 19:57:03 +00:00
#
# 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 logging
from PyQt5 import QtWidgets, QtCore
2020-07-19 14:38:03 +00:00
from PyQt5.QtWidgets import QCheckBox
2020-07-17 19:57:03 +00:00
from NanoVNASaver import Defaults
2020-07-17 19:57:03 +00:00
from NanoVNASaver.Marker import Marker
2021-07-05 15:32:37 +00:00
from NanoVNASaver.Controls.Control import Control
2020-07-17 19:57:03 +00:00
logger = logging.getLogger(__name__)
class ShowButton(QtWidgets.QPushButton):
def setText(self, text: str=''):
if not text:
text = ("Show data"
if Defaults.cfg.gui.markers_hidden else "Hide data")
super().setText(text)
self.setToolTip("Toggle visibility of marker readings area")
2021-07-05 15:32:37 +00:00
class MarkerControl(Control):
2020-07-17 19:57:03 +00:00
2021-07-05 15:32:37 +00:00
def __init__(self, app: QtWidgets.QWidget):
super().__init__(app, "Markers")
2020-07-17 19:57:03 +00:00
for i in range(Defaults.cfg.chart.marker_count):
2020-07-17 19:57:03 +00:00
marker = Marker("", self.app.settings)
# marker.setFixedHeight(20)
2020-07-17 19:57:03 +00:00
marker.updated.connect(self.app.markerUpdated)
label, layout = marker.getRow()
2020-07-19 14:38:03 +00:00
self.layout.addRow(label, layout)
2020-07-17 19:57:03 +00:00
self.app.markers.append(marker)
if i == 0:
marker.isMouseControlledRadioButton.setChecked(True)
2020-07-19 14:38:03 +00:00
self.check_delta = QCheckBox("Enable Delta Marker")
self.check_delta.toggled.connect(self.toggle_delta)
2022-05-06 13:17:22 +00:00
self.check_delta_reference = QCheckBox("reference")
self.check_delta_reference.toggled.connect(self.toggle_delta_reference)
2022-05-06 13:17:22 +00:00
layout2 = QtWidgets.QHBoxLayout()
layout2.addWidget(self.check_delta)
layout2.addWidget(self.check_delta_reference)
self.layout.addRow(layout2)
self.showMarkerButton = ShowButton()
self.showMarkerButton.setFixedHeight(20)
self.showMarkerButton.setText()
2020-07-17 19:57:03 +00:00
self.showMarkerButton.clicked.connect(self.toggle_frame)
lock_radiobutton = QtWidgets.QRadioButton("Locked")
lock_radiobutton.setLayoutDirection(QtCore.Qt.RightToLeft)
lock_radiobutton.setSizePolicy(
QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
hbox = QtWidgets.QHBoxLayout()
hbox.addWidget(self.showMarkerButton)
hbox.addWidget(lock_radiobutton)
2020-07-19 14:38:03 +00:00
self.layout.addRow(hbox)
2020-07-17 19:57:03 +00:00
def toggle_frame(self):
2021-07-05 15:32:37 +00:00
def settings(hidden: bool):
Defaults.cfg.gui.markers_hidden = not hidden
self.app.marker_frame.setHidden(
Defaults.cfg.gui.markers_hidden)
self.showMarkerButton.setText()
self.showMarkerButton.repaint()
2021-07-05 15:32:37 +00:00
settings(self.app.marker_frame.isHidden())
2020-07-19 14:38:03 +00:00
def toggle_delta(self):
self.app.delta_marker_layout.setVisible(self.check_delta.isChecked())
def toggle_delta_reference(self):
self.app.marker_ref = bool(self.check_delta_reference.isChecked())
if self.app.marker_ref:
new_name = "Delta Reference - Marker 1"
else:
new_name = "Delta Marker 2 - Marker 1"
# FIXME: reset
self.app.delta_marker.group_box.setTitle(new_name)
self.app.delta_marker.resetLabels()