added message on success on a web mission
This commit is contained in:
parent
65d75af51a
commit
a114c70e53
5 changed files with 63 additions and 9 deletions
22
assets/web/common.css
Normal file
22
assets/web/common.css
Normal 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
18
assets/web/success.html
Normal 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>
|
|
@ -0,0 +1,3 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
assets_path = Path("./assets/")
|
|
@ -1,14 +1,19 @@
|
||||||
import time
|
import time
|
||||||
|
from pathlib import Path
|
||||||
from typing import Optional, Any
|
from typing import Optional, Any
|
||||||
|
|
||||||
from PyQt6.QtCore import Qt, QTimer, pyqtSignal, QUrl, QEvent, QObject
|
from PyQt6.QtCore import Qt, QTimer, pyqtSignal, QUrl, QEvent, QObject
|
||||||
from PyQt6.QtGui import QFont, QMouseEvent, QResizeEvent, QKeyEvent
|
from PyQt6.QtGui import QFont, QMouseEvent, QResizeEvent, QKeyEvent
|
||||||
from PyQt6.QtWidgets import QLabel, QVBoxLayout, QSizePolicy
|
from PyQt6.QtWidgets import QLabel, QVBoxLayout, QSizePolicy
|
||||||
|
|
||||||
|
from source import assets_path
|
||||||
from source.survey.base import BaseSurvey
|
from source.survey.base import BaseSurvey
|
||||||
from source.widget import Browser
|
from source.widget import Browser
|
||||||
|
|
||||||
|
|
||||||
|
page_success_path: Path = assets_path / "web/success.html"
|
||||||
|
|
||||||
|
|
||||||
class WebMission(BaseSurvey):
|
class WebMission(BaseSurvey):
|
||||||
def __init__(self, title: str, url: str, signals: dict[str, pyqtSignal], check_condition: Optional[str] = None):
|
def __init__(self, title: str, url: str, signals: dict[str, pyqtSignal], check_condition: Optional[str] = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -17,6 +22,8 @@ class WebMission(BaseSurvey):
|
||||||
self.default_url = url
|
self.default_url = url
|
||||||
self.signals = signals if signals is not None else {}
|
self.signals = signals if signals is not None else {}
|
||||||
|
|
||||||
|
self._finished = False
|
||||||
|
|
||||||
# set layout
|
# set layout
|
||||||
self._layout = QVBoxLayout()
|
self._layout = QVBoxLayout()
|
||||||
self.setLayout(self._layout)
|
self.setLayout(self._layout)
|
||||||
|
@ -63,7 +70,7 @@ class WebMission(BaseSurvey):
|
||||||
# events
|
# events
|
||||||
|
|
||||||
def eventFilter(self, obj: QObject, event: QEvent) -> bool:
|
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
|
# if the object is the content of the web engine widget
|
||||||
match event.type():
|
match event.type():
|
||||||
case QEvent.Type.MouseMove:
|
case QEvent.Type.MouseMove:
|
||||||
|
@ -163,8 +170,7 @@ class WebMission(BaseSurvey):
|
||||||
self.timer_check.stop()
|
self.timer_check.stop()
|
||||||
|
|
||||||
def _success(self):
|
def _success(self):
|
||||||
# TODO: animation or notification to clearly mark mission as succeeded
|
if not self._finished:
|
||||||
|
|
||||||
# mark the success in the events
|
# mark the success in the events
|
||||||
self._save_event(type="check")
|
self._save_event(type="check")
|
||||||
|
|
||||||
|
@ -172,6 +178,12 @@ class WebMission(BaseSurvey):
|
||||||
if "success" in self.signals:
|
if "success" in self.signals:
|
||||||
self.signals["success"].emit() # NOQA: emit exist
|
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
|
# condition
|
||||||
|
|
||||||
def check(self) -> None:
|
def check(self) -> None:
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from PyQt6.QtCore import QUrl, QObject, QEvent
|
from PyQt6.QtCore import QUrl
|
||||||
from PyQt6.QtGui import QMouseEvent
|
|
||||||
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
||||||
from PyQt6.QtWidgets import QVBoxLayout, QWidget, QProgressBar, QStyle, QToolBar
|
from PyQt6.QtWidgets import QVBoxLayout, QWidget, QProgressBar, QStyle, QToolBar
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue