Split menu setup method per menu

This commit is contained in:
atse 2023-07-31 16:19:07 +08:00
parent 7a727cb011
commit 0443778456
1 changed files with 22 additions and 14 deletions

View File

@ -146,7 +146,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.max_samples = self.DEFAULT_MAX_SAMPLES self.max_samples = self.DEFAULT_MAX_SAMPLES
self._set_up_context_menu() self._set_up_connection_menu()
self._set_up_thermostat_menu()
self._set_up_plot_menu()
self.fan_power_slider.valueChanged.connect(self.fan_set) self.fan_power_slider.valueChanged.connect(self.fan_set)
self.fan_auto_box.stateChanged.connect(self.fan_auto_set) self.fan_auto_box.stateChanged.connect(self.fan_auto_set)
@ -194,7 +196,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.port_set_spin.setValue(int(args.PORT)) self.port_set_spin.setValue(int(args.PORT))
self.connect_btn.click() self.connect_btn.click()
def _set_up_context_menu(self): def _set_up_connection_menu(self):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
self.connection_menu = QtWidgets.QMenu() self.connection_menu = QtWidgets.QMenu()
@ -239,8 +241,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.connect_btn.setMenu(self.connection_menu) self.connect_btn.setMenu(self.connection_menu)
self.menu = QtWidgets.QMenu() def _set_up_thermostat_menu(self):
self.menu.setTitle('Thermostat settings') _translate = QtCore.QCoreApplication.translate
self.thermostat_menu = QtWidgets.QMenu()
self.thermostat_menu.setTitle('Thermostat settings')
self.fan_group = QtWidgets.QWidget() self.fan_group = QtWidgets.QWidget()
self.fan_group.setEnabled(False) self.fan_group.setEnabled(False)
@ -299,10 +304,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.fan_lbl.setText(_translate("MainWindow", "Fan:")) self.fan_lbl.setText(_translate("MainWindow", "Fan:"))
self.fan_auto_box.setText(_translate("MainWindow", "Auto")) self.fan_auto_box.setText(_translate("MainWindow", "Auto"))
fan = QtWidgets.QWidgetAction(self.menu) fan = QtWidgets.QWidgetAction(self.thermostat_menu)
fan.setDefaultWidget(self.fan_group) fan.setDefaultWidget(self.fan_group)
self.menu.addAction(fan) self.thermostat_menu.addAction(fan)
self.menu.fan = fan self.thermostat_menu.fan = fan
@asyncSlot(bool) @asyncSlot(bool)
async def reset_thermostat(_): async def reset_thermostat(_):
@ -313,12 +318,12 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.connect_btn.click() # Reconnect self.connect_btn.click() # Reconnect
self.actionReset.triggered.connect(reset_thermostat) self.actionReset.triggered.connect(reset_thermostat)
self.menu.addAction(self.actionReset) self.thermostat_menu.addAction(self.actionReset)
self.menu.addAction(self.actionEnter_DFU_Mode) self.thermostat_menu.addAction(self.actionEnter_DFU_Mode)
self.menu.addAction(self.actionNetwork_Settings) self.thermostat_menu.addAction(self.actionNetwork_Settings)
self.menu.addAction(self.actionLoad_all_configs) self.thermostat_menu.addAction(self.actionLoad_all_configs)
self.menu.addAction(self.actionSave_all_configs) self.thermostat_menu.addAction(self.actionSave_all_configs)
def about_thermostat(): def about_thermostat():
QtWidgets.QMessageBox.about( QtWidgets.QMessageBox.about(
@ -347,9 +352,12 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
) )
self.actionAbout_Thermostat.triggered.connect(about_thermostat) self.actionAbout_Thermostat.triggered.connect(about_thermostat)
self.menu.addAction(self.actionAbout_Thermostat) self.thermostat_menu.addAction(self.actionAbout_Thermostat)
self.thermostat_settings.setMenu(self.menu) self.thermostat_settings.setMenu(self.thermostat_menu)
def _set_up_plot_menu(self):
_translate = QtCore.QCoreApplication.translate
self.plot_menu = QtWidgets.QMenu() self.plot_menu = QtWidgets.QMenu()
self.plot_menu.setTitle("Plot Settings") self.plot_menu.setTitle("Plot Settings")