diff --git a/source/survey/Text.py b/source/survey/Text.py index 8096d02..a526cb0 100644 --- a/source/survey/Text.py +++ b/source/survey/Text.py @@ -8,10 +8,17 @@ from source.survey.base import BaseSurvey class Text(BaseSurvey): - def __init__(self, title: str, description: Optional[str], signals: dict[str, pyqtSignal]): + def __init__( + self, + title: str, + description: Optional[str], + abandonable: bool = None, + signals: dict[str, pyqtSignal] = None + ): super().__init__() - self.signals = signals + self.abandonable = abandonable if abandonable is not None else False + self.signals = signals if signals is not None else {} # set the layout self._layout = QVBoxLayout() @@ -40,6 +47,7 @@ class Text(BaseSurvey): return cls( title=data["title"], description=data.get("description"), + abandonable=data.get("abandonable", False), signals=signals ) @@ -49,4 +57,6 @@ class Text(BaseSurvey): # the user can skip a text whenever he wants to, directly signal a success self.signals["success"].emit() # NOQA: emit exist - + # if abandon is enabled, emit on the corresponding signal + if self.abandonable and "abandon" in self.signals: + self.signals["abandon"].emit() # NOQA: emit exist diff --git a/source/survey/TextQuestion.py b/source/survey/TextQuestion.py index 0631d49..5212ed8 100644 --- a/source/survey/TextQuestion.py +++ b/source/survey/TextQuestion.py @@ -2,16 +2,16 @@ from typing import Any from PyQt6.QtCore import Qt, pyqtSignal from PyQt6.QtGui import QFont -from PyQt6.QtWidgets import QFrame, QVBoxLayout, QLabel, QRadioButton, QButtonGroup, QTextEdit +from PyQt6.QtWidgets import QVBoxLayout, QLabel, QTextEdit from source.survey.base import BaseSurvey class TextQuestion(BaseSurvey): - def __init__(self, title: str, signals: dict[str, pyqtSignal]): + def __init__(self, title: str, signals: dict[str, pyqtSignal] = None): super().__init__() - self.signals = signals + self.signals = signals if signals is not None else {} # set layout self._layout = QVBoxLayout() diff --git a/source/survey/WebMission.py b/source/survey/WebMission.py index 4382268..6b652a7 100644 --- a/source/survey/WebMission.py +++ b/source/survey/WebMission.py @@ -15,6 +15,7 @@ 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 super().__init__() self.check_condition = check_condition @@ -53,7 +54,7 @@ class WebMission(BaseSurvey): # setup the timer for the check if self.check_condition is not None: self.timer_check = QTimer() - self.timer_check.setInterval(1000) + self.timer_check.setInterval(100) self.timer_check.timeout.connect(self.check) # NOQA: connect exist @classmethod @@ -72,6 +73,8 @@ class WebMission(BaseSurvey): 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(): + # TODO: record back and forward and reload + case QEvent.Type.MouseMove: # if this is a mouse movement event: QMouseEvent diff --git a/source/widget/FrameSurvey.py b/source/widget/FrameSurvey.py index c44e011..c1dba1c 100644 --- a/source/widget/FrameSurvey.py +++ b/source/widget/FrameSurvey.py @@ -10,12 +10,15 @@ from source.survey import Empty, survey_get class FrameSurvey(QFrame): signal_success = pyqtSignal() + signal_abandon = 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 # prepare the survey screen data self.survey_screens: list[tuple[str, BaseSurvey]] = [] @@ -39,7 +42,13 @@ class FrameSurvey(QFrame): self._layout_navigation = QHBoxLayout() self.frame_navigation.setLayout(self._layout_navigation) - self._layout_navigation.addStretch(0) + self._layout_navigation.addStretch(0) # add a stretch to put the buttons on the right + + self.button_abandon = QPushButton() + self._layout_navigation.addWidget(self.button_abandon) + self.button_abandon.setText("Abandonner") + self.button_abandon.setStyleSheet("QPushButton { color : red; }") + self.button_abandon.clicked.connect(self.quit) # NOQA: connect exist self.button_forward = QPushButton() self._layout_navigation.addWidget(self.button_forward) @@ -56,6 +65,10 @@ class FrameSurvey(QFrame): # 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 load_file(self, survey_path: Path | str): # load the surveys screens with open(survey_path, encoding="utf-8") as file: @@ -66,7 +79,10 @@ class FrameSurvey(QFrame): survey_id, survey_get( survey_data, - signals={"success": self.signal_success} + signals={ + "success": self.signal_success, + "abandon": self.signal_abandon, + } ) ) for survey_id, survey_data in surveys_data.items() @@ -82,8 +98,6 @@ class FrameSurvey(QFrame): # save the response in the data self.collected_datas[survey_id] = collected_data - print(collected_data) - self.current_survey_index += 1 if self.current_survey_index < len(self.survey_screens): @@ -92,7 +106,8 @@ class FrameSurvey(QFrame): self.finish_survey() def update_survey(self): - # disable the forward button + # disable the buttons + self.button_abandon.hide() self.button_forward.hide() # mark the actual survey as the old one @@ -115,3 +130,8 @@ class FrameSurvey(QFrame): print(self.collected_datas) self.window().close() + + def quit(self): + # quit the application by closing and deleting the window + self.window().close() + self.window().deleteLater() diff --git a/source/widget/MyMainWindow.py b/source/widget/MyMainWindow.py index c123363..36a9e84 100644 --- a/source/widget/MyMainWindow.py +++ b/source/widget/MyMainWindow.py @@ -12,4 +12,6 @@ class MyMainWindow(QMainWindow): super().__init__() self.setWindowIcon(QIcon(str(icon_path.resolve()))) + self.setWindowTitle("Sondage - Steam") + self.setCentralWidget(widget.FrameSurvey("./surveys.json")) diff --git a/surveys.json b/surveys.json index 6f992a5..e74e30a 100644 --- a/surveys.json +++ b/surveys.json @@ -2,7 +2,8 @@ "text-welcome": { "type": "text", "title": "Bienvenue !", - "description": "Nous réalisons une étude sur le logiciel Steam afin de déterminer son ergonomie.\nVous serez invité à naviguer sur la plateforme Steam d'une page à l'autre." + "description": "Nous réalisons une étude sur le logiciel Steam afin de déterminer son ergonomie.\nVous serez invité à naviguer sur la plateforme Steam d'une page à l'autre.", + "abandonable": true }, "question-usage": {