diff --git a/not1mm/__main__.py b/not1mm/__main__.py index 8037f71..87be050 100644 --- a/not1mm/__main__.py +++ b/not1mm/__main__.py @@ -37,7 +37,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets, uic from PyQt6.QtCore import QDir, Qt, QThread, QSettings, QCoreApplication from PyQt6.QtGui import QFontDatabase, QColorConstants, QPalette, QColor, QPixmap -from PyQt6.QtWidgets import QFileDialog, QSplashScreen +from PyQt6.QtWidgets import QFileDialog, QSplashScreen, QApplication from not1mm.lib.about import About from not1mm.lib.cwinterface import CW @@ -162,6 +162,8 @@ class MainWindow(QtWidgets.QMainWindow): oldtext = "" text_color = QColorConstants.Black current_palette = None + use_esm = False + esm_dict = {} radio_thread = QThread() voice_thread = QThread() @@ -176,6 +178,8 @@ class MainWindow(QtWidgets.QMainWindow): lookup_service = None fldigi_util = None + current_widget = None + def __init__(self, splash): super().__init__() logger.info("MainWindow: __init__") @@ -194,6 +198,7 @@ def __init__(self, splash): self.setCorner(Qt.Corner.TopLeftCorner, Qt.DockWidgetArea.LeftDockWidgetArea) self.setCorner(Qt.Corner.BottomLeftCorner, Qt.DockWidgetArea.LeftDockWidgetArea) uic.loadUi(fsutils.APP_DATA_PATH / "main.ui", self) + QApplication.instance().focusObjectChanged.connect(self.on_focus_changed) self.cw_entry.hide() self.leftdot.hide() self.rightdot.hide() @@ -246,13 +251,18 @@ def __init__(self, splash): self.radioButton_sp.clicked.connect(self.run_sp_buttons_clicked) self.score.setText("0") self.callsign.textEdited.connect(self.callsign_changed) - self.callsign.returnPressed.connect(self.save_contact) - self.sent.returnPressed.connect(self.save_contact) - self.receive.returnPressed.connect(self.save_contact) - self.other_1.returnPressed.connect(self.save_contact) + self.callsign.returnPressed.connect(self.check_esm_with_enter) + self.callsign.cursorPositionChanged.connect(self.check_esm) + self.sent.returnPressed.connect(self.check_esm_with_enter) + self.sent.cursorPositionChanged.connect(self.check_esm) + self.receive.returnPressed.connect(self.check_esm_with_enter) + self.receive.cursorPositionChanged.connect(self.check_esm) + self.other_1.returnPressed.connect(self.check_esm_with_enter) self.other_1.textEdited.connect(self.other_1_changed) - self.other_2.returnPressed.connect(self.save_contact) + self.other_1.cursorPositionChanged.connect(self.check_esm) + self.other_2.returnPressed.connect(self.check_esm_with_enter) self.other_2.textEdited.connect(self.other_2_changed) + self.other_2.cursorPositionChanged.connect(self.check_esm) self.sent.setText("59") self.receive.setText("59") @@ -651,6 +661,47 @@ def __init__(self, splash): "You can udate to the current version by using:\npip install -U not1mm" ) + def on_focus_changed(self, new): + """""" + if self.use_esm: + if hasattr(self.contest, "process_esm"): + self.contest.process_esm(self, new_focused_widget=new) + + def make_button_green(self, the_button: QtWidgets.QPushButton) -> None: + """Turn the_button green.""" + if the_button is not None: + pal = QPalette() + pal.isCopyOf(self.current_palette) + greenColor = QColor(0, 128, 0) + pal.setBrush(QPalette.ColorRole.Button, greenColor) + the_button.setPalette(pal) + + def restore_button_color(self, the_button: QtWidgets.QPushButton) -> None: + """Restores the color of the button""" + the_button.setPalette(self.current_palette) + + def check_esm_with_enter(self): + """Check for ESM, otherwise save contact.""" + if self.use_esm: + if hasattr(self.contest, "process_esm"): + self.contest.process_esm(self, with_enter=True) + else: + self.save_contact() + else: + self.save_contact() + + def check_esm(self): + """Check for ESM, otherwise save contact.""" + if self.use_esm: + if hasattr(self.contest, "process_esm"): + self.contest.process_esm(self) + else: + ... + # self.save_contact() + else: + ... + # self.save_contact() + def show_splash_msg(self, msg: str) -> None: """Show text message in the splash window.""" self.splash.showMessage( @@ -1719,7 +1770,6 @@ def keyPressEvent(self, event) -> None: # pylint: disable=invalid-name ------- None """ - modifier = event.modifiers() if event.key() == Qt.Key.Key_K: self.toggle_cw_entry() @@ -2027,7 +2077,7 @@ def save_contact(self) -> None: logger.debug("saving contact") if self.contest is None: - self.show_message_box("You have no contest defined.") + self.show_message_box("You have no contest defined...") return if len(self.callsign.text()) < 3: return @@ -2666,7 +2716,33 @@ def readpreferences(self) -> None: for band_to_show in self.pref.get("bands", []): if band_to_show in _indicator: _indicator[band_to_show].show() - # self.show_band_mode() + + fkey_dict = { + "F1": self.F1, + "F2": self.F2, + "F3": self.F3, + "F4": self.F4, + "F5": self.F5, + "F6": self.F6, + "F7": self.F7, + "F8": self.F8, + "F9": self.F9, + "F10": self.F10, + "F11": self.F11, + "F12": self.F12, + "DISABLED": None, + } + + self.use_esm = self.pref.get("use_esm", False) + self.esm_dict["CQ"] = fkey_dict.get(self.pref.get("esm_cq", "DISABLED")) + self.esm_dict["EXCH"] = fkey_dict.get(self.pref.get("esm_exch", "DISABLED")) + self.esm_dict["QRZ"] = fkey_dict.get(self.pref.get("esm_qrz", "DISABLED")) + self.esm_dict["AGN"] = fkey_dict.get(self.pref.get("esm_agn", "DISABLED")) + self.esm_dict["HISCALL"] = fkey_dict.get( + self.pref.get("esm_hiscall", "DISABLED") + ) + self.esm_dict["MYCALL"] = fkey_dict.get(self.pref.get("esm_mycall", "DISABLED")) + self.esm_dict["QSOB4"] = fkey_dict.get(self.pref.get("esm_qsob4", "DISABLED")) def watch_udp(self) -> None: """ diff --git a/not1mm/data/configuration.ui b/not1mm/data/configuration.ui index 81684b6..2dacb35 100644 --- a/not1mm/data/configuration.ui +++ b/not1mm/data/configuration.ui @@ -1620,6 +1620,591 @@ + + + Options + + + + + + + F1 + + + + + F2 + + + + + F3 + + + + + F4 + + + + + F5 + + + + + F6 + + + + + F7 + + + + + F8 + + + + + F9 + + + + + F10 + + + + + F11 + + + + + F12 + + + + + DISABLED + + + + + + + + Enable ESM + + + + + + + AGN + + + + + + + + F1 + + + + + F2 + + + + + F3 + + + + + F4 + + + + + F5 + + + + + F6 + + + + + F7 + + + + + F8 + + + + + F9 + + + + + F10 + + + + + F11 + + + + + F12 + + + + + DISABLED + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + F1 + + + + + F2 + + + + + F3 + + + + + F4 + + + + + F5 + + + + + F6 + + + + + F7 + + + + + F8 + + + + + F9 + + + + + F10 + + + + + F11 + + + + + F12 + + + + + DISABLED + + + + + + + + QRZ + + + + + + + + F1 + + + + + F2 + + + + + F3 + + + + + F4 + + + + + F5 + + + + + F6 + + + + + F7 + + + + + F8 + + + + + F9 + + + + + F10 + + + + + F11 + + + + + F12 + + + + + DISABLED + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Exchange + + + + + + + His Call + + + + + + + + F1 + + + + + F2 + + + + + F3 + + + + + F4 + + + + + F5 + + + + + F6 + + + + + F7 + + + + + F8 + + + + + F9 + + + + + F10 + + + + + F11 + + + + + F12 + + + + + DISABLED + + + + + + + + CQ + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + F1 + + + + + F2 + + + + + F3 + + + + + F4 + + + + + F5 + + + + + F6 + + + + + F7 + + + + + F8 + + + + + F9 + + + + + F10 + + + + + F11 + + + + + F12 + + + + + DISABLED + + + + + + + + My Call + + + + + + + QSO B4 + + + + + + + + F1 + + + + + F2 + + + + + F3 + + + + + F4 + + + + + F5 + + + + + F6 + + + + + F7 + + + + + F8 + + + + + F9 + + + + + F10 + + + + + F11 + + + + + F12 + + + + + DISABLED + + + + + + diff --git a/not1mm/lib/settings.py b/not1mm/lib/settings.py index 067f1d1..5bf005c 100644 --- a/not1mm/lib/settings.py +++ b/not1mm/lib/settings.py @@ -38,6 +38,44 @@ def __init__(self, app_data_path, pref, parent=None): def setup(self): """setup dialog""" + + self.use_esm.setChecked(bool(self.preference.get("use_esm"))) + + value = self.preference.get("esm_agn", "DISABLED") + index = self.esm_agn.findText(value) + if index != -1: + self.esm_agn.setCurrentIndex(index) + + value = self.preference.get("esm_cq", "DISABLED") + index = self.esm_cq.findText(value) + if index != -1: + self.esm_cq.setCurrentIndex(index) + + value = self.preference.get("esm_exch", "DISABLED") + index = self.esm_exch.findText(value) + if index != -1: + self.esm_exch.setCurrentIndex(index) + + value = self.preference.get("esm_hiscall", "DISABLED") + index = self.esm_hiscall.findText(value) + if index != -1: + self.esm_hiscall.setCurrentIndex(index) + + value = self.preference.get("esm_mycall", "DISABLED") + index = self.esm_mycall.findText(value) + if index != -1: + self.esm_mycall.setCurrentIndex(index) + + value = self.preference.get("esm_qrz", "DISABLED") + index = self.esm_qrz.findText(value) + if index != -1: + self.esm_qrz.setCurrentIndex(index) + + value = self.preference.get("esm_qsob4", "DISABLED") + index = self.esm_qsob4.findText(value) + if index != -1: + self.esm_qsob4.setCurrentIndex(index) + for device in self.devices: if device.get("max_output_channels"): self.sounddevice.addItem(device.get("name")) @@ -150,6 +188,15 @@ def save_changes(self): """ Write preferences to json file. """ + self.preference["use_esm"] = self.use_esm.isChecked() + self.preference["esm_cq"] = self.esm_cq.currentText() + self.preference["esm_agn"] = self.esm_agn.currentText() + self.preference["esm_exch"] = self.esm_exch.currentText() + self.preference["esm_hiscall"] = self.esm_hiscall.currentText() + self.preference["esm_mycall"] = self.esm_mycall.currentText() + self.preference["esm_qrz"] = self.esm_qrz.currentText() + self.preference["esm_qsob4"] = self.esm_qsob4.currentText() + self.preference["sounddevice"] = self.sounddevice.currentText() self.preference["useqrz"] = self.useqrz_radioButton.isChecked() # self.preference["usehamdb"] = self.usehamdb_radioButton.isChecked() diff --git a/not1mm/plugins/cq_ww_cw.py b/not1mm/plugins/cq_ww_cw.py index e79447f..c5194bc 100644 --- a/not1mm/plugins/cq_ww_cw.py +++ b/not1mm/plugins/cq_ww_cw.py @@ -380,3 +380,111 @@ def cabrillo(self): def recalculate_mults(self): """Recalculates multipliers after change in logged qso.""" + + +def process_esm(self, new_focused_widget=None, with_enter=False): + """ESM State Machine""" + + # self.pref["run_state"] + + # -----===== Assigned F-Keys =====----- + # self.esm_dict["CQ"] + # self.esm_dict["EXCH"] + # self.esm_dict["QRZ"] + # self.esm_dict["AGN"] + # self.esm_dict["HISCALL"] + # self.esm_dict["MYCALL"] + # self.esm_dict["QSOB4"] + + # ----==== text fields ====---- + # self.callsign + # self.sent + # self.receive + # self.other_1 + # self.other_2 + + inputs = { + self.callsign: "callsign", + self.sent: "sent", + self.receive: "receive", + self.other_1: "other_1", + self.other_2: "other_2", + } + if new_focused_widget is not None: + self.current_widget = inputs.get(new_focused_widget) + + # print(f"checking esm {self.current_widget=} {with_enter=} {self.pref.get("run_state")=}") + + for a_button in [ + self.F1, + self.F2, + self.F3, + self.F4, + self.F5, + self.F6, + self.F7, + self.F8, + self.F9, + self.F10, + self.F11, + self.F12, + ]: + self.restore_button_color(a_button) + + buttons_to_send = [] + + if self.pref.get("run_state"): + if self.current_widget == "callsign": + if len(self.callsign.text()) < 3: + self.make_button_green(self.esm_dict["CQ"]) + buttons_to_send.append(self.esm_dict["CQ"]) + elif len(self.callsign.text()) > 2 and self.callsign.text().isalnum(): + self.make_button_green(self.esm_dict["HISCALL"]) + self.make_button_green(self.esm_dict["EXCH"]) + buttons_to_send.append(self.esm_dict["HISCALL"]) + buttons_to_send.append(self.esm_dict["EXCH"]) + + if self.current_widget == "other_2": + if self.other_2.text() == "": + self.make_button_green(self.esm_dict["AGN"]) + buttons_to_send.append(self.esm_dict["AGN"]) + elif self.other_2.text().isnumeric(): + self.make_button_green(self.esm_dict["QRZ"]) + buttons_to_send.append(self.esm_dict["QRZ"]) + buttons_to_send.append("LOGIT") + else: + self.make_button_green(self.esm_dict["AGN"]) + buttons_to_send.append(self.esm_dict["AGN"]) + + if with_enter is True and bool(len(buttons_to_send)): + for button in buttons_to_send: + if button: + if button == "LOGIT": + self.save_contact() + continue + self.process_function_key(button) + else: + if self.current_widget == "callsign": + if len(self.callsign.text()) > 2 and self.callsign.text().isalnum(): + self.make_button_green(self.esm_dict["MYCALL"]) + buttons_to_send.append(self.esm_dict["MYCALL"]) + + if self.current_widget == "other_2": + if self.other_2.text() == "": + self.make_button_green(self.esm_dict["AGN"]) + buttons_to_send.append(self.esm_dict["AGN"]) + elif self.other_2.text().isnumeric(): + self.make_button_green(self.esm_dict["EXCH"]) + buttons_to_send.append(self.esm_dict["EXCH"]) + buttons_to_send.append("LOGIT") + else: + self.make_button_green(self.esm_dict["AGN"]) + buttons_to_send.append(self.esm_dict["AGN"]) + + if with_enter is True and bool(len(buttons_to_send)): + for button in buttons_to_send: + if button: + if button == "LOGIT": + self.save_contact() + continue + self.process_function_key(button)