an "abandon" button have been added
This commit is contained in:
parent
e7d75267ae
commit
1742f7d19c
6 changed files with 49 additions and 13 deletions
|
@ -8,10 +8,17 @@ from source.survey.base import BaseSurvey
|
||||||
|
|
||||||
|
|
||||||
class Text(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__()
|
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
|
# set the layout
|
||||||
self._layout = QVBoxLayout()
|
self._layout = QVBoxLayout()
|
||||||
|
@ -40,6 +47,7 @@ class Text(BaseSurvey):
|
||||||
return cls(
|
return cls(
|
||||||
title=data["title"],
|
title=data["title"],
|
||||||
description=data.get("description"),
|
description=data.get("description"),
|
||||||
|
abandonable=data.get("abandonable", False),
|
||||||
|
|
||||||
signals=signals
|
signals=signals
|
||||||
)
|
)
|
||||||
|
@ -49,4 +57,6 @@ class Text(BaseSurvey):
|
||||||
# the user can skip a text whenever he wants to, directly signal a success
|
# the user can skip a text whenever he wants to, directly signal a success
|
||||||
self.signals["success"].emit() # NOQA: emit exist
|
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
|
||||||
|
|
|
@ -2,16 +2,16 @@ from typing import Any
|
||||||
|
|
||||||
from PyQt6.QtCore import Qt, pyqtSignal
|
from PyQt6.QtCore import Qt, pyqtSignal
|
||||||
from PyQt6.QtGui import QFont
|
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
|
from source.survey.base import BaseSurvey
|
||||||
|
|
||||||
|
|
||||||
class TextQuestion(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__()
|
super().__init__()
|
||||||
|
|
||||||
self.signals = signals
|
self.signals = signals if signals is not None else {}
|
||||||
|
|
||||||
# set layout
|
# set layout
|
||||||
self._layout = QVBoxLayout()
|
self._layout = QVBoxLayout()
|
||||||
|
|
|
@ -15,6 +15,7 @@ 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):
|
||||||
|
# TODO: timeout
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.check_condition = check_condition
|
self.check_condition = check_condition
|
||||||
|
@ -53,7 +54,7 @@ class WebMission(BaseSurvey):
|
||||||
# setup the timer for the check
|
# setup the timer for the check
|
||||||
if self.check_condition is not None:
|
if self.check_condition is not None:
|
||||||
self.timer_check = QTimer()
|
self.timer_check = QTimer()
|
||||||
self.timer_check.setInterval(1000)
|
self.timer_check.setInterval(100)
|
||||||
self.timer_check.timeout.connect(self.check) # NOQA: connect exist
|
self.timer_check.timeout.connect(self.check) # NOQA: connect exist
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -72,6 +73,8 @@ class WebMission(BaseSurvey):
|
||||||
if obj is self.browser.web.focusProxy() and not self._finished:
|
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():
|
||||||
|
# TODO: record back and forward and reload
|
||||||
|
|
||||||
case QEvent.Type.MouseMove:
|
case QEvent.Type.MouseMove:
|
||||||
# if this is a mouse movement
|
# if this is a mouse movement
|
||||||
event: QMouseEvent
|
event: QMouseEvent
|
||||||
|
|
|
@ -10,12 +10,15 @@ from source.survey import Empty, survey_get
|
||||||
|
|
||||||
class FrameSurvey(QFrame):
|
class FrameSurvey(QFrame):
|
||||||
signal_success = pyqtSignal()
|
signal_success = pyqtSignal()
|
||||||
|
signal_abandon = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, survey_path: Path | str):
|
def __init__(self, survey_path: Path | str):
|
||||||
|
# TODO: translation support
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
# signals
|
# signals
|
||||||
self.signal_success.connect(self._on_signal_success) # NOQA: connect exist
|
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
|
# prepare the survey screen data
|
||||||
self.survey_screens: list[tuple[str, BaseSurvey]] = []
|
self.survey_screens: list[tuple[str, BaseSurvey]] = []
|
||||||
|
@ -39,7 +42,13 @@ class FrameSurvey(QFrame):
|
||||||
self._layout_navigation = QHBoxLayout()
|
self._layout_navigation = QHBoxLayout()
|
||||||
self.frame_navigation.setLayout(self._layout_navigation)
|
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.button_forward = QPushButton()
|
||||||
self._layout_navigation.addWidget(self.button_forward)
|
self._layout_navigation.addWidget(self.button_forward)
|
||||||
|
@ -56,6 +65,10 @@ class FrameSurvey(QFrame):
|
||||||
# on success, show the button to go forward
|
# on success, show the button to go forward
|
||||||
self.button_forward.show()
|
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):
|
def load_file(self, survey_path: Path | str):
|
||||||
# load the surveys screens
|
# load the surveys screens
|
||||||
with open(survey_path, encoding="utf-8") as file:
|
with open(survey_path, encoding="utf-8") as file:
|
||||||
|
@ -66,7 +79,10 @@ class FrameSurvey(QFrame):
|
||||||
survey_id,
|
survey_id,
|
||||||
survey_get(
|
survey_get(
|
||||||
survey_data,
|
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()
|
for survey_id, survey_data in surveys_data.items()
|
||||||
|
@ -82,8 +98,6 @@ class FrameSurvey(QFrame):
|
||||||
# save the response in the data
|
# save the response in the data
|
||||||
self.collected_datas[survey_id] = collected_data
|
self.collected_datas[survey_id] = collected_data
|
||||||
|
|
||||||
print(collected_data)
|
|
||||||
|
|
||||||
self.current_survey_index += 1
|
self.current_survey_index += 1
|
||||||
|
|
||||||
if self.current_survey_index < len(self.survey_screens):
|
if self.current_survey_index < len(self.survey_screens):
|
||||||
|
@ -92,7 +106,8 @@ class FrameSurvey(QFrame):
|
||||||
self.finish_survey()
|
self.finish_survey()
|
||||||
|
|
||||||
def update_survey(self):
|
def update_survey(self):
|
||||||
# disable the forward button
|
# disable the buttons
|
||||||
|
self.button_abandon.hide()
|
||||||
self.button_forward.hide()
|
self.button_forward.hide()
|
||||||
|
|
||||||
# mark the actual survey as the old one
|
# mark the actual survey as the old one
|
||||||
|
@ -115,3 +130,8 @@ class FrameSurvey(QFrame):
|
||||||
print(self.collected_datas)
|
print(self.collected_datas)
|
||||||
|
|
||||||
self.window().close()
|
self.window().close()
|
||||||
|
|
||||||
|
def quit(self):
|
||||||
|
# quit the application by closing and deleting the window
|
||||||
|
self.window().close()
|
||||||
|
self.window().deleteLater()
|
||||||
|
|
|
@ -12,4 +12,6 @@ class MyMainWindow(QMainWindow):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.setWindowIcon(QIcon(str(icon_path.resolve())))
|
self.setWindowIcon(QIcon(str(icon_path.resolve())))
|
||||||
|
self.setWindowTitle("Sondage - Steam")
|
||||||
|
|
||||||
self.setCentralWidget(widget.FrameSurvey("./surveys.json"))
|
self.setCentralWidget(widget.FrameSurvey("./surveys.json"))
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
"text-welcome": {
|
"text-welcome": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"title": "Bienvenue !",
|
"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": {
|
"question-usage": {
|
||||||
|
|
Loading…
Reference in a new issue