Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esm or redacted due to swear words #169

Merged
merged 9 commits into from
Oct 10, 2024
94 changes: 85 additions & 9 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 @@ -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()
Expand All @@ -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__")
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
Expand Down
Loading
Loading