added message on success on a web mission

This commit is contained in:
Faraphel 2023-12-23 11:16:07 +01:00
parent 65d75af51a
commit a114c70e53
5 changed files with 63 additions and 9 deletions

22
assets/web/common.css Normal file
View file

@ -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;
}

18
assets/web/success.html Normal file
View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="common.css" />
<title>Succès</title>
</head>
<body>
<div class="notification-container">
<div class="notification">
<p>
Vous avez réussi cette étape.<br/>
Vous pouvez à présent passer à la suivante.
</p>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,3 @@
from pathlib import Path
assets_path = Path("./assets/")

View file

@ -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

View file

@ -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