from PyQt6 import QtWidgets, QtCore class ConnMenu(QtWidgets.QMenu): def __init__(self): super().__init__() self.setTitle("Connection Settings") self.host_set_line = QtWidgets.QLineEdit() self.host_set_line.setMinimumSize(QtCore.QSize(160, 0)) self.host_set_line.setMaximumSize(QtCore.QSize(160, 16777215)) self.host_set_line.setMaxLength(15) self.host_set_line.setClearButtonEnabled(True) def connect_on_enter_press(): self.connect_btn.click() self.hide() self.host_set_line.returnPressed.connect(connect_on_enter_press) self.host_set_line.setText("192.168.1.26") self.host_set_line.setPlaceholderText("IP for the Thermostat") host = QtWidgets.QWidgetAction(self) host.setDefaultWidget(self.host_set_line) self.addAction(host) self.host = host self.port_set_spin = QtWidgets.QSpinBox() self.port_set_spin.setMinimumSize(QtCore.QSize(70, 0)) self.port_set_spin.setMaximumSize(QtCore.QSize(70, 16777215)) self.port_set_spin.setMaximum(65535) self.port_set_spin.setValue(23) def connect_only_if_enter_pressed(): if ( not self.port_set_spin.hasFocus() ): # Don't connect if the spinbox only lost focus return connect_on_enter_press() self.port_set_spin.editingFinished.connect(connect_only_if_enter_pressed) port = QtWidgets.QWidgetAction(self) port.setDefaultWidget(self.port_set_spin) self.addAction(port) self.port = port self.exit_button = QtWidgets.QPushButton() self.exit_button.setText("Exit GUI") self.exit_button.pressed.connect(QtWidgets.QApplication.instance().quit) exit_action = QtWidgets.QWidgetAction(self.exit_button) exit_action.setDefaultWidget(self.exit_button) self.addAction(exit_action) self.exit_action = exit_action