diff --git a/assets/web/common.css b/assets/web/common.css new file mode 100644 index 0000000..9478ebc --- /dev/null +++ b/assets/web/common.css @@ -0,0 +1,22 @@ +.notification { + /* center the div */ + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + + /* set the size to shrink to the text */ + width: fit-content; + + /* set the text */ + text-align: center; + font-size: 150%; + font-family: "Century Gothic", sans-serif; /* TODO: other font */ + font-weight: bold; + + /* set the border */ + border: 4px solid black; + border-radius: 2vh; + + padding: 20px; +} diff --git a/assets/web/success.html b/assets/web/success.html new file mode 100644 index 0000000..4865807 --- /dev/null +++ b/assets/web/success.html @@ -0,0 +1,18 @@ + + + + + + Succès + + +
+
+

+ Vous avez réussi cette étape.
+ Vous pouvez à présent passer à la suivante. +

+
+
+ + \ No newline at end of file diff --git a/source/__init__.py b/source/__init__.py index e69de29..a42ad09 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -0,0 +1,3 @@ +from pathlib import Path + +assets_path = Path("./assets/") diff --git a/source/survey/WebMission.py b/source/survey/WebMission.py index e355bc9..84695ba 100644 --- a/source/survey/WebMission.py +++ b/source/survey/WebMission.py @@ -1,14 +1,19 @@ import time +from pathlib import Path from typing import Optional, Any from PyQt6.QtCore import Qt, QTimer, pyqtSignal, QUrl, QEvent, QObject from PyQt6.QtGui import QFont, QMouseEvent, QResizeEvent, QKeyEvent from PyQt6.QtWidgets import QLabel, QVBoxLayout, QSizePolicy +from source import assets_path from source.survey.base import BaseSurvey from source.widget import Browser +page_success_path: Path = assets_path / "web/success.html" + + class WebMission(BaseSurvey): def __init__(self, title: str, url: str, signals: dict[str, pyqtSignal], check_condition: Optional[str] = None): super().__init__() @@ -17,6 +22,8 @@ class WebMission(BaseSurvey): self.default_url = url self.signals = signals if signals is not None else {} + self._finished = False + # set layout self._layout = QVBoxLayout() self.setLayout(self._layout) @@ -63,7 +70,7 @@ class WebMission(BaseSurvey): # events def eventFilter(self, obj: QObject, event: QEvent) -> bool: - if obj is self.browser.web.focusProxy(): + if obj is self.browser.web.focusProxy() and not self._finished: # if the object is the content of the web engine widget match event.type(): case QEvent.Type.MouseMove: @@ -163,14 +170,19 @@ class WebMission(BaseSurvey): self.timer_check.stop() def _success(self): - # TODO: animation or notification to clearly mark mission as succeeded + if not self._finished: + # mark the success in the events + self._save_event(type="check") - # mark the success in the events - self._save_event(type="check") + # emit on the success signal + if "success" in self.signals: + self.signals["success"].emit() # NOQA: emit exist - # emit on the success signal - if "success" in self.signals: - self.signals["success"].emit() # NOQA: emit exist + # change the content of the page to the success message + self.browser.web.load(QUrl.fromLocalFile(str(page_success_path.absolute()))) + + # mark the mission as finished + self._finished = True # condition diff --git a/source/widget/Browser.py b/source/widget/Browser.py index 228b266..af7ef0b 100644 --- a/source/widget/Browser.py +++ b/source/widget/Browser.py @@ -1,7 +1,6 @@ from typing import Optional -from PyQt6.QtCore import QUrl, QObject, QEvent -from PyQt6.QtGui import QMouseEvent +from PyQt6.QtCore import QUrl from PyQt6.QtWebEngineWidgets import QWebEngineView from PyQt6.QtWidgets import QVBoxLayout, QWidget, QProgressBar, QStyle, QToolBar