Skip to content

Commit

Permalink
@mbridak Highlight ESM function keys based on state of input widgets.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbridak committed Oct 10, 2024
1 parent 150963c commit 3900cf6
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 19 deletions.
60 changes: 41 additions & 19 deletions not1mm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -178,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__")
Expand All @@ -196,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()
Expand Down Expand Up @@ -248,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.check_esm)
self.sent.returnPressed.connect(self.check_esm)
self.receive.returnPressed.connect(self.check_esm)
self.other_1.returnPressed.connect(self.check_esm)
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.check_esm)
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")
Expand Down Expand Up @@ -653,32 +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."""
pal = QPalette()
pal.isCopyOf(self.current_palette)
greenColor = QColor(0, 128, 0)
pal.setBrush(QPalette.ColorRole.Button, greenColor)
the_button.setPalette(pal)
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(self):
def check_esm_with_enter(self):
"""Check for ESM, otherwise save contact."""
print(f"{self.use_esm=}")
if self.use_esm:
print(f"{hasattr(self.contest, "process_esm")=}")
if hasattr(self.contest, "process_esm"):
print(f"{hasattr(self.contest, "process_esm")=}")
self.contest.process_esm(self)
self.contest.process_esm(self, with_enter=True)
else:
print("Save contact")
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(
Expand Down Expand Up @@ -1747,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()
Expand Down Expand Up @@ -2055,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
Expand Down
64 changes: 64 additions & 0 deletions not1mm/plugins/cq_ww_cw.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,67 @@ 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=}")

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)

if self.current_widget == "callsign":
if len(self.callsign.text()) < 3:
self.make_button_green(self.esm_dict["CQ"])
elif len(self.callsign.text()) > 2 and self.callsign.text().isalnum():
self.make_button_green(self.esm_dict["EXCH"])
self.make_button_green(self.esm_dict["HISCALL"])
if self.current_widget == "other_2":
if self.other_2.text() == "":
self.make_button_green(self.esm_dict["AGN"])
elif self.other_2.text().isnumeric():
self.make_button_green(self.esm_dict["QRZ"])
else:
self.make_button_green(self.esm_dict["AGN"])

0 comments on commit 3900cf6

Please sign in to comment.