web mission can now timeout after a certain time
This commit is contained in:
parent
1742f7d19c
commit
233bb067bc
4 changed files with 60 additions and 16 deletions
|
@ -47,7 +47,7 @@ class Text(BaseSurvey):
|
|||
return cls(
|
||||
title=data["title"],
|
||||
description=data.get("description"),
|
||||
abandonable=data.get("abandonable", False),
|
||||
abandonable=data.get("abandonable"),
|
||||
|
||||
signals=signals
|
||||
)
|
||||
|
|
|
@ -14,12 +14,19 @@ 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):
|
||||
# TODO: timeout
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
url: str,
|
||||
check_condition: Optional[str] = None,
|
||||
skip_time: Optional[float] = None,
|
||||
signals: dict[str, pyqtSignal] = None
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.check_condition = check_condition
|
||||
self.default_url = url
|
||||
self.skip_time = skip_time
|
||||
self.signals = signals if signals is not None else {}
|
||||
|
||||
self._finished = False
|
||||
|
@ -52,17 +59,26 @@ class WebMission(BaseSurvey):
|
|||
self.browser.web.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
|
||||
# setup the timer for the check
|
||||
self.timer_check = None
|
||||
if self.check_condition is not None:
|
||||
self.timer_check = QTimer()
|
||||
self.timer_check.setInterval(100)
|
||||
self.timer_check.timeout.connect(self.check) # NOQA: connect exist
|
||||
|
||||
# setup the timer for skipping the mission
|
||||
self.timer_skip = None
|
||||
if self.skip_time is not None:
|
||||
self.timer_skip = QTimer()
|
||||
self.timer_skip.setInterval(self.skip_time * 1000)
|
||||
self.timer_skip.timeout.connect(self._on_time_skip) # NOQA: connect exist
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "WebMission":
|
||||
return cls(
|
||||
title=data["title"],
|
||||
url=data.get("url"),
|
||||
check_condition=data.get("check"),
|
||||
skip_time=data.get("skip_time"),
|
||||
|
||||
signals=signals
|
||||
)
|
||||
|
@ -157,20 +173,28 @@ class WebMission(BaseSurvey):
|
|||
# enable the full screen mode
|
||||
self.window().showFullScreen()
|
||||
|
||||
if self.check_condition is not None:
|
||||
if self.timer_check is not None:
|
||||
# enable the timer
|
||||
self.timer_check.start()
|
||||
|
||||
else:
|
||||
self._success() # call directly the success method
|
||||
|
||||
if self.timer_skip is not None:
|
||||
# enable the timer for skipping the question
|
||||
self.timer_skip.start()
|
||||
|
||||
def on_hide(self) -> None:
|
||||
# disable full screen mode
|
||||
self.window().showNormal()
|
||||
|
||||
# stop the checking loop
|
||||
# stop the checking loop timer
|
||||
if self.timer_check is not None:
|
||||
self.timer_check.stop()
|
||||
|
||||
# stop the timer skip
|
||||
if self.timer_skip is not None:
|
||||
self.timer_skip.stop()
|
||||
|
||||
def _success(self):
|
||||
if self._finished:
|
||||
return
|
||||
|
@ -188,6 +212,11 @@ class WebMission(BaseSurvey):
|
|||
# change the content of the page to the success message
|
||||
self.browser.web.load(QUrl.fromLocalFile(str(page_success_path.absolute())))
|
||||
|
||||
def _on_time_skip(self):
|
||||
# when the timer to allow skip have run out
|
||||
if "skip" in self.signals:
|
||||
self.signals["skip"].emit() # NOQA: emit exist
|
||||
|
||||
# condition
|
||||
|
||||
def check(self) -> None:
|
||||
|
|
|
@ -9,16 +9,18 @@ from source.survey import Empty, survey_get
|
|||
|
||||
|
||||
class FrameSurvey(QFrame):
|
||||
signal_success = pyqtSignal()
|
||||
signal_abandon = pyqtSignal()
|
||||
signal_skip = pyqtSignal()
|
||||
signal_success = pyqtSignal()
|
||||
|
||||
def __init__(self, survey_path: Path | str):
|
||||
# TODO: translation support
|
||||
super().__init__()
|
||||
|
||||
# signals
|
||||
self.signal_success.connect(self._on_signal_success) # NOQA: connect exist
|
||||
self.signal_abandon.connect(self._on_signal_abandon) # NOQA: connect exist
|
||||
self.signal_skip.connect(self._on_signal_skip) # NOQA: connect exist
|
||||
self.signal_success.connect(self._on_signal_success) # NOQA: connect exist
|
||||
|
||||
# prepare the survey screen data
|
||||
self.survey_screens: list[tuple[str, BaseSurvey]] = []
|
||||
|
@ -50,6 +52,11 @@ class FrameSurvey(QFrame):
|
|||
self.button_abandon.setStyleSheet("QPushButton { color : red; }")
|
||||
self.button_abandon.clicked.connect(self.quit) # NOQA: connect exist
|
||||
|
||||
self.button_skip = QPushButton()
|
||||
self._layout_navigation.addWidget(self.button_skip)
|
||||
self.button_skip.setText("Passer")
|
||||
self.button_skip.clicked.connect(self.next_survey) # NOQA: connect exist
|
||||
|
||||
self.button_forward = QPushButton()
|
||||
self._layout_navigation.addWidget(self.button_forward)
|
||||
self.button_forward.setText("Suivant")
|
||||
|
@ -61,14 +68,18 @@ class FrameSurvey(QFrame):
|
|||
# finalize the initialisation
|
||||
self.update_survey()
|
||||
|
||||
def _on_signal_success(self):
|
||||
# on success, show the button to go forward
|
||||
self.button_forward.show()
|
||||
|
||||
def _on_signal_abandon(self):
|
||||
# on success, show the button to give up
|
||||
self.button_abandon.show()
|
||||
|
||||
def _on_signal_skip(self):
|
||||
# on success, show the button to skip
|
||||
self.button_skip.show()
|
||||
|
||||
def _on_signal_success(self):
|
||||
# on success, show the button to go forward
|
||||
self.button_forward.show()
|
||||
|
||||
def load_file(self, survey_path: Path | str):
|
||||
# load the surveys screens
|
||||
with open(survey_path, encoding="utf-8") as file:
|
||||
|
@ -80,8 +91,9 @@ class FrameSurvey(QFrame):
|
|||
survey_get(
|
||||
survey_data,
|
||||
signals={
|
||||
"success": self.signal_success,
|
||||
"abandon": self.signal_abandon,
|
||||
"skip": self.signal_skip,
|
||||
"success": self.signal_success,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
@ -108,6 +120,7 @@ class FrameSurvey(QFrame):
|
|||
def update_survey(self):
|
||||
# disable the buttons
|
||||
self.button_abandon.hide()
|
||||
self.button_skip.hide()
|
||||
self.button_forward.hide()
|
||||
|
||||
# mark the actual survey as the old one
|
||||
|
|
|
@ -22,14 +22,16 @@
|
|||
"type": "mission-web",
|
||||
"title": "Changer la langue en français.",
|
||||
"url": "https://steampowered.com/",
|
||||
"check": "document.getElementsByTagName('html')[0].lang == 'fr'"
|
||||
"check": "document.getElementsByTagName('html')[0].lang == 'fr'",
|
||||
"skip_time": 60
|
||||
},
|
||||
|
||||
"web-point-shop": {
|
||||
"type": "mission-web",
|
||||
"title": "Rendez-vous sur la boutique des points.",
|
||||
"url": "https://steampowered.com/",
|
||||
"check": "true"
|
||||
"check": "true",
|
||||
"skip_time": 90
|
||||
},
|
||||
|
||||
"question-experience": {
|
||||
|
|
Loading…
Reference in a new issue