survey are now lazy loaded
This commit is contained in:
parent
9e5567a99e
commit
27cb041fde
4 changed files with 95 additions and 88 deletions
|
@ -51,6 +51,7 @@ class WebMission(BaseSurvey):
|
||||||
self._layout.addWidget(self.browser)
|
self._layout.addWidget(self.browser)
|
||||||
self.browser.web.focusProxy().installEventFilter(self) # capture the event in eventFilter
|
self.browser.web.focusProxy().installEventFilter(self) # capture the event in eventFilter
|
||||||
self.browser.web.urlChanged.connect(self._on_url_changed) # NOQA: connect exist
|
self.browser.web.urlChanged.connect(self._on_url_changed) # NOQA: connect exist
|
||||||
|
self.browser.web.setUrl(QUrl(self.default_url))
|
||||||
|
|
||||||
self.browser.web.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
self.browser.web.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||||
|
|
||||||
|
@ -75,6 +76,21 @@ class WebMission(BaseSurvey):
|
||||||
self.navigation = widget.SurveyNavigation(signals=signals)
|
self.navigation = widget.SurveyNavigation(signals=signals)
|
||||||
self._layout.addWidget(self.navigation)
|
self._layout.addWidget(self.navigation)
|
||||||
|
|
||||||
|
# initialize the start time
|
||||||
|
self.start_time = time.time()
|
||||||
|
|
||||||
|
# check timer
|
||||||
|
if self.timer_check is not None:
|
||||||
|
# enable the timer
|
||||||
|
self.timer_check.start()
|
||||||
|
else:
|
||||||
|
self._success() # call directly the success method
|
||||||
|
|
||||||
|
# skip timer
|
||||||
|
if self.timer_skip is not None:
|
||||||
|
# enable the timer for skipping the question
|
||||||
|
self.timer_skip.start()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "WebMission":
|
def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "WebMission":
|
||||||
return cls(
|
return cls(
|
||||||
|
@ -168,42 +184,6 @@ class WebMission(BaseSurvey):
|
||||||
|
|
||||||
return super().eventFilter(obj, event)
|
return super().eventFilter(obj, event)
|
||||||
|
|
||||||
def on_show(self) -> None:
|
|
||||||
# TODO: remove ?
|
|
||||||
|
|
||||||
# initialize the start time
|
|
||||||
self.start_time = time.time()
|
|
||||||
|
|
||||||
# set the web view to the default url
|
|
||||||
self.browser.web.setUrl(QUrl(self.default_url))
|
|
||||||
|
|
||||||
# enable the full screen mode
|
|
||||||
self.window().showFullScreen()
|
|
||||||
|
|
||||||
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:
|
|
||||||
# TODO: remove ?
|
|
||||||
|
|
||||||
# disable full screen mode
|
|
||||||
self.window().showNormal()
|
|
||||||
|
|
||||||
# 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):
|
def _success(self):
|
||||||
if self._finished:
|
if self._finished:
|
||||||
return
|
return
|
||||||
|
@ -265,3 +245,13 @@ class WebMission(BaseSurvey):
|
||||||
return {
|
return {
|
||||||
"event": self._collected_events,
|
"event": self._collected_events,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# survey events
|
||||||
|
|
||||||
|
def on_ready(self) -> None:
|
||||||
|
# enable the maximized mode
|
||||||
|
self.window().showMaximized()
|
||||||
|
|
||||||
|
def on_finalize(self) -> None:
|
||||||
|
# disable the maximized mode
|
||||||
|
self.window().showNormal()
|
||||||
|
|
|
@ -10,6 +10,8 @@ class BaseSurvey(QWidget):
|
||||||
A type of survey survey that can be in the user interface
|
A type of survey survey that can be in the user interface
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# initialisation
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "BaseSurvey":
|
def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "BaseSurvey":
|
||||||
|
@ -18,16 +20,7 @@ class BaseSurvey(QWidget):
|
||||||
:return: the instance
|
:return: the instance
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def on_show(self) -> None:
|
# data collection
|
||||||
"""
|
|
||||||
Called when the survey is shown
|
|
||||||
"""
|
|
||||||
|
|
||||||
def on_hide(self) -> None:
|
|
||||||
"""
|
|
||||||
Called when the survey is hidden
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get_collected_data(self) -> Optional[dict]:
|
def get_collected_data(self) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
|
@ -36,3 +29,15 @@ class BaseSurvey(QWidget):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# survey events
|
||||||
|
|
||||||
|
def on_ready(self) -> None:
|
||||||
|
"""
|
||||||
|
Called once the survey screen is ready to be used
|
||||||
|
"""
|
||||||
|
|
||||||
|
def on_finalize(self) -> None:
|
||||||
|
"""
|
||||||
|
Called once the survey screen is about to be finished
|
||||||
|
"""
|
||||||
|
|
|
@ -28,44 +28,28 @@ class SurveyEngine(QWidget):
|
||||||
def __init__(self, surveys_data: dict, discord_webhook_result_url: Optional[str] = None):
|
def __init__(self, surveys_data: dict, discord_webhook_result_url: Optional[str] = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
# signals
|
self.surveys_data = surveys_data
|
||||||
self.signal_abandon.connect(self._on_signal_abandon) # NOQA: connect exist
|
self.discord_webhook_result_url = discord_webhook_result_url
|
||||||
self.signal_skip.connect(self._on_signal_skip) # NOQA: connect exist
|
self._current_survey_index = 0
|
||||||
self.signal_success.connect(self._on_signal_success) # NOQA: connect exist
|
|
||||||
|
|
||||||
# prepare the survey collected data
|
|
||||||
self.collected_datas: dict[str, dict] = {
|
self.collected_datas: dict[str, dict] = {
|
||||||
"time": time.time(), # get the time of the start of the survey
|
"time": time.time(), # get the time of the start of the survey
|
||||||
"language": translate.get_language(), # get the user language
|
"language": translate.get_language(), # get the user language
|
||||||
"surveys": {} # prepare the individual surveys data
|
"surveys": {} # prepare the individual surveys data
|
||||||
}
|
}
|
||||||
self.discord_webhook_result_url = discord_webhook_result_url
|
|
||||||
self.current_survey_index = 0
|
|
||||||
|
|
||||||
# load the survey screens
|
# signals
|
||||||
# TODO: create dynamically
|
self.signal_abandon.connect(self._on_signal_abandon) # NOQA: connect exist
|
||||||
self.survey_screens = [
|
self.signal_skip.connect(self._on_signal_skip) # NOQA: connect exist
|
||||||
(
|
self.signal_success.connect(self._on_signal_success) # NOQA: connect exist
|
||||||
survey_id,
|
|
||||||
survey_get(
|
|
||||||
survey_data,
|
|
||||||
signals={
|
|
||||||
"abandon": self.signal_abandon,
|
|
||||||
"skip": self.signal_skip,
|
|
||||||
"success": self.signal_success,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for survey_id, survey_data in surveys_data.items()
|
|
||||||
]
|
|
||||||
|
|
||||||
# set the layout
|
# set the layout
|
||||||
self._layout = QVBoxLayout()
|
self._layout = QVBoxLayout()
|
||||||
self.setLayout(self._layout)
|
self.setLayout(self._layout)
|
||||||
|
|
||||||
# prepare the frame for the survey elements
|
# prepare the frame for the survey elements
|
||||||
self.frame_survey: BaseSurvey = Empty()
|
self.survey: BaseSurvey = Empty()
|
||||||
self._layout.addWidget(self.frame_survey)
|
self._layout.addWidget(self.survey)
|
||||||
|
|
||||||
# progress bar
|
# progress bar
|
||||||
self.progress = QProgressBar()
|
self.progress = QProgressBar()
|
||||||
|
@ -92,6 +76,21 @@ class SurveyEngine(QWidget):
|
||||||
|
|
||||||
return cls.from_dict(data)
|
return cls.from_dict(data)
|
||||||
|
|
||||||
|
# property
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_survey_index(self):
|
||||||
|
return self._current_survey_index
|
||||||
|
|
||||||
|
@current_survey_index.setter
|
||||||
|
def current_survey_index(self, value: int):
|
||||||
|
self._current_survey_index = value
|
||||||
|
self.progress.setValue(self.current_survey_index)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_survey_id(self) -> str:
|
||||||
|
return list(self.surveys_data.keys())[self.current_survey_index]
|
||||||
|
|
||||||
# events
|
# events
|
||||||
|
|
||||||
def _on_signal_abandon(self):
|
def _on_signal_abandon(self):
|
||||||
|
@ -108,38 +107,49 @@ class SurveyEngine(QWidget):
|
||||||
|
|
||||||
def next_survey(self):
|
def next_survey(self):
|
||||||
# get the collected data from the survey
|
# get the collected data from the survey
|
||||||
collected_data = self.frame_survey.get_collected_data()
|
collected_data = self.survey.get_collected_data()
|
||||||
if collected_data is not None:
|
if collected_data is not None:
|
||||||
# if there is data, get the current survey id
|
|
||||||
survey_id, survey = self.survey_screens[self.current_survey_index]
|
|
||||||
# save the response in the data
|
# save the response in the data
|
||||||
self.collected_datas["surveys"][survey_id] = collected_data
|
self.collected_datas["surveys"][self.current_survey_id] = collected_data
|
||||||
|
|
||||||
|
# go to the next survey
|
||||||
self.current_survey_index += 1
|
self.current_survey_index += 1
|
||||||
self.progress.setValue(self.current_survey_index)
|
|
||||||
|
|
||||||
if self.current_survey_index < len(self.survey_screens):
|
if self.current_survey_index < len(self.surveys_data):
|
||||||
|
# if there are still survey to do, show it
|
||||||
self.update_survey()
|
self.update_survey()
|
||||||
else:
|
else:
|
||||||
|
# otherwise end the survey
|
||||||
self.finish_survey()
|
self.finish_survey()
|
||||||
|
|
||||||
def update_survey(self):
|
def update_survey(self):
|
||||||
|
|
||||||
# mark the actual survey as the old one
|
# mark the actual survey as the old one
|
||||||
old_frame_survey = self.frame_survey
|
old_survey = self.survey
|
||||||
# call the old survey event
|
|
||||||
old_frame_survey.on_hide()
|
# finalize the old_survey
|
||||||
|
old_survey.on_finalize()
|
||||||
|
|
||||||
# get the currently selected survey
|
# get the currently selected survey
|
||||||
survey_id, survey = self.survey_screens[self.current_survey_index]
|
new_survey = survey_get(
|
||||||
|
self.surveys_data[self.current_survey_id],
|
||||||
|
signals={
|
||||||
|
"abandon": self.signal_abandon,
|
||||||
|
"skip": self.signal_skip,
|
||||||
|
"success": self.signal_success,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# update it to the new one
|
# update it to the new one
|
||||||
self.frame_survey = survey
|
self.survey = new_survey
|
||||||
# change the widget on the layout
|
# change the widget on the layout
|
||||||
self._layout.replaceWidget(old_frame_survey, self.frame_survey)
|
self._layout.replaceWidget(old_survey, self.survey)
|
||||||
# adjust the size of the widgets
|
|
||||||
self.window().adjustSize()
|
|
||||||
# call the new survey event
|
|
||||||
survey.on_show()
|
|
||||||
# delete the old frame
|
# delete the old frame
|
||||||
old_frame_survey.deleteLater()
|
old_survey.deleteLater()
|
||||||
|
|
||||||
|
# mark the new survey as ready
|
||||||
|
self.survey.on_ready()
|
||||||
|
|
||||||
def finish_survey(self):
|
def finish_survey(self):
|
||||||
# TODO: page with indication and progress bar for upload
|
# TODO: page with indication and progress bar for upload
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
|
"discord_webhook_result_url": "https://ptb.discord.com/api/webhooks/1190377876583878757/OudOJGxhNu0QeiVreF7uVl1U5_GD6XcCat6pKFeA57eLdfbd5Y9YCVEiFhbC4y5-HS93",
|
||||||
|
|
||||||
"surveys": {
|
"surveys": {
|
||||||
|
|
||||||
"text-welcome": {
|
"text-welcome": {
|
||||||
|
|
Loading…
Reference in a new issue