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

Fix dialog window not auto closing after 60s #181

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/dialog_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,21 @@ def close_thread(event: Event, box: CustomDialog, close_time: int):
title = self.__choose_language("box_title")
fill_string = "-" * 70
fancy_message = f"{fill_string}\n{message}\n{fill_string}"
self.message_box = CustomDialog(fancy_message, title, use_ok)
event = Event()
self.message_box = CustomDialog(fancy_message, title, use_ok, event.set)
# If there is a close time, start auto close
if close_time is not None:
auto_closer = Thread(target=close_thread, args=(event, self.message_box, close_time), daemon=True)
auto_closer = Thread(
target=close_thread,
args=(
event,
self.message_box,
close_time,
),
daemon=True,
)
auto_closer.start()
# Need to set event, in case thread is still waiting
event.set()

def user_okay(self, text: str):
"""Prompts the user for the given message and asks for confirmation.
Expand Down
9 changes: 8 additions & 1 deletion src/ui/setup_custom_dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import annotations

from typing import Callable

from PyQt5.QtWidgets import QMainWindow

from src.dialog_handler import UI_LANGUAGE
Expand All @@ -8,18 +12,21 @@
class CustomDialog(QMainWindow, Ui_CustomDialog):
"""Class for the Team selection Screen."""

def __init__(self, message: str, title: str = "Information", use_ok=False):
def __init__(self, message: str, title: str = "Information", use_ok=False, close_callback: Callable | None = None):
super().__init__()
self.setupUi(self)
DP_CONTROLLER.initialize_window_object(self)
self.informationLabel.setText(message)
self.setWindowTitle(title)
self.closeButton.clicked.connect(self.close_clicked)
self.close_callback = close_callback

# self.closeButton.setText(close_text)
UI_LANGUAGE.adjust_custom_dialog(self, use_ok)
self.showFullScreen()
DP_CONTROLLER.set_display_settings(self)

def close_clicked(self):
if self.close_callback is not None:
self.close_callback()
self.close()