Move plot_options_menu stuff into menu

This commit is contained in:
atse 2024-08-27 15:40:59 +08:00
parent 87ca0694cd
commit 89e9da4499
2 changed files with 9 additions and 12 deletions

View File

@ -2,18 +2,22 @@ from PyQt6 import QtWidgets, QtGui
class PlotOptionsMenu(QtWidgets.QMenu):
def __init__(self, max_samples=1000):
def __init__(self, channel_graphs, max_samples=1000):
super().__init__()
self.channel_graphs = channel_graphs
self.setTitle("Plot Settings")
clear = QtGui.QAction("Clear graphs", self)
self.addAction(clear)
self.clear = clear
self.clear.triggered.connect(self.channel_graphs.clear_graphs)
self.samples_spinbox = QtWidgets.QSpinBox()
self.samples_spinbox.setRange(2, 100000)
self.samples_spinbox.setSuffix(" samples")
self.samples_spinbox.setValue(max_samples)
self.samples_spinbox.valueChanged.connect(self.channel_graphs.set_max_samples)
limit_samples = QtWidgets.QWidgetAction(self)
limit_samples.setDefaultWidget(self.samples_spinbox)

View File

@ -124,11 +124,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.thermostat.report_update.connect(self.channel_graphs.update_report)
self.thermostat.pid_update.connect(self.channel_graphs.update_pid)
self.plot_options_menu = PlotOptionsMenu()
self.plot_options_menu.clear.triggered.connect(self.clear_graphs)
self.plot_options_menu.samples_spinbox.valueChanged.connect(
self.channel_graphs.set_max_samples
)
self.plot_options_menu = PlotOptionsMenu(self.channel_graphs)
self.plot_settings.setMenu(self.plot_options_menu)
self.conn_menu = ConnMenu()
@ -141,9 +137,6 @@ class MainWindow(QtWidgets.QMainWindow):
self.loading_spinner.hide()
def clear_graphs(self):
self.channel_graphs.clear_graphs()
@asyncSlot(ThermostatConnectionState)
async def _on_connection_changed(self, result):
match result:
@ -177,7 +170,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.loading_spinner.stop()
self.thermostat_ctrl_menu.fan_pwm_warning.setPixmap(QtGui.QPixmap())
self.thermostat_ctrl_menu.fan_pwm_warning.setToolTip("")
self.clear_graphs()
self.channel_graphs.clear_graphs()
self.report_box.setChecked(False)
for ch in range(self.NUM_CHANNELS):
if self.autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF:
@ -317,9 +310,9 @@ async def coro_main():
if args.connect:
if args.HOST:
main_window.host_set_line.setText(args.HOST)
main_window.conn_menu.host_set_line.setText(args.HOST)
if args.PORT:
main_window.port_set_spin.setValue(int(args.PORT))
main_window.conn_menu.port_set_spin.setValue(int(args.PORT))
main_window.connect_btn.click()
await app_quit_event.wait()