Skip to content

Commit

Permalink
@mbridak cleanup rtc responses
Browse files Browse the repository at this point in the history
  • Loading branch information
mbridak committed Dec 5, 2024
1 parent 04bb6fe commit 83f49b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions not1mm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2475,14 +2475,12 @@ def save_contact(self) -> None:

def update_rtc_xml(self):
"""Update RTC XML"""
print("update the xml")
if self.pref.get("send_rtc_scores", False):
if self.contest is None:
return
if hasattr(self.contest, "online_score_xml"):
if self.rtc_service is not None:
self.rtc_service.xml = self.contest.online_score_xml(self)
print(f"{self.rtc_service.xml=}")

def new_contest_dialog(self) -> None:
"""
Expand Down Expand Up @@ -2941,6 +2939,7 @@ def readpreferences(self) -> None:
self.rtc_thread.finished.connect(self.rtc_service.deleteLater)
# self.rtc_service.poll_callback.connect(self.rtc_result)
self.rtc_thread.start()
self.rtc_service.rtc_callback.connect(self.rtc_response)

try:
if self.radio_thread.isRunning():
Expand Down Expand Up @@ -3098,6 +3097,9 @@ def dark_mode_state_changed(self) -> None:
self.write_preference()
self.setDarkMode(self.actionDark_Mode_2.isChecked())

def rtc_response(self, response):
print(f"{response=}")

def cw_macros_state_changed(self) -> None:
"""
Menu item to show/hide macro buttons.
Expand Down
13 changes: 7 additions & 6 deletions not1mm/rtc_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class RTCService(QObject):
"""The RTC Service class."""

poll_callback = pyqtSignal(dict)
rtc_callback = pyqtSignal(dict)
delta = 2 # two minutes
poll_time = datetime.datetime.now() + datetime.timedelta(minutes=delta)
time_to_quit = False
Expand All @@ -44,6 +44,7 @@ def run(self) -> None:
while not self.time_to_quit:
# if self.pref.get("send_rtc_scores", False) is True:
if datetime.datetime.now() > self.poll_time:
response = ""
self.poll_time = datetime.datetime.now() + datetime.timedelta(
minutes=self.delta
)
Expand All @@ -60,15 +61,15 @@ def run(self) -> None:
),
timeout=30,
)
print(f"{self.xml=}\n{result=}\n{result.text}")
response = f"{result.status_code}|{result.reason}|{result.text}"
except requests.exceptions.Timeout:
print("RTC post timeout.")
response = "RTC post timeout."
except requests.exceptions.RequestException as e:
print(f"An RTC post error occurred: {e}")
response = f"An RTC post error occurred: {e}"
else:
print("No XML data")
response = "No XML data"
try:
self.poll_callback.emit({"success": True})
self.rtc_callback.emit({"result": response})
except QEventLoop:
...
QThread.msleep(1)
Expand Down

0 comments on commit 83f49b9

Please sign in to comment.