From f9953a3cbbca9010d238c5219ef2b709fdaa30cd Mon Sep 17 00:00:00 2001 From: Faraphel Date: Sat, 23 Dec 2023 18:54:37 +0100 Subject: [PATCH] made some graphical adjustment --- source/survey/IntegerQuestion.py | 27 ++++++++++++++++++++------- source/survey/SingleChoiceQuestion.py | 7 +++++-- source/widget/FrameSurvey.py | 2 ++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/source/survey/IntegerQuestion.py b/source/survey/IntegerQuestion.py index 2fff1b2..450c0ba 100644 --- a/source/survey/IntegerQuestion.py +++ b/source/survey/IntegerQuestion.py @@ -1,16 +1,26 @@ -from typing import Any +from typing import Any, Optional from PyQt6.QtCore import Qt, pyqtSignal -from PyQt6.QtGui import QFont, QIntValidator -from PyQt6.QtWidgets import QVBoxLayout, QLabel, QDoubleSpinBox, QSpinBox +from PyQt6.QtGui import QFont +from PyQt6.QtWidgets import QVBoxLayout, QLabel, QSpinBox from source.survey.base import BaseSurvey class IntegerQuestion(BaseSurvey): - def __init__(self, title: str, signals: dict[str, pyqtSignal] = None): + def __init__( + self, + title: str, + default: Optional[int] = None, + minimum: Optional[int] = None, + maximum: Optional[int] = None, + signals: dict[str, pyqtSignal] = None + ): super().__init__() + default = default if default is not None else 0 + minimum = minimum if minimum is not None else 0 + maximum = maximum if maximum is not None else 100 self.signals = signals if signals is not None else {} # set layout @@ -30,15 +40,18 @@ class IntegerQuestion(BaseSurvey): # response self.entry_response = QSpinBox() - self.entry_response.setMinimum(13) - self.entry_response.setMaximum(200) - self.entry_response.setValue(30) + self.entry_response.setMinimum(minimum) + self.entry_response.setMaximum(maximum) + self.entry_response.setValue(default) self._layout.addWidget(self.entry_response) @classmethod def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "IntegerQuestion": return cls( title=data["title"], + default=data.get("default"), + minimum=data.get("minimum"), + maximum=data.get("maximum"), signals=signals, ) diff --git a/source/survey/SingleChoiceQuestion.py b/source/survey/SingleChoiceQuestion.py index 3ce0cec..6ae9c7c 100644 --- a/source/survey/SingleChoiceQuestion.py +++ b/source/survey/SingleChoiceQuestion.py @@ -39,6 +39,8 @@ class SingleChoiceQuestion(BaseSurvey): # checking any button allow the user to go to the next step self.group_responses.buttonClicked.connect(signals["success"].emit) # NOQA: connect and emit exists + self.button_responses_id: dict[QRadioButton, str] = {} + for choice_id, choice_text in choices.items(): # create a radio button for that choice button = QRadioButton() @@ -48,7 +50,8 @@ class SingleChoiceQuestion(BaseSurvey): self._layout_responses.addWidget(button) # add the button to the group - self.group_responses.addButton(button, int(choice_id)) + self.group_responses.addButton(button) + self.button_responses_id[button] = choice_id @classmethod def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "SingleChoiceQuestion": @@ -61,5 +64,5 @@ class SingleChoiceQuestion(BaseSurvey): def get_collected_data(self) -> dict: return { - "choice": self.group_responses.checkedId() + "choice": self.button_responses_id[self.group_responses.checkedButton()] } diff --git a/source/widget/FrameSurvey.py b/source/widget/FrameSurvey.py index fcc0222..ee9f75c 100644 --- a/source/widget/FrameSurvey.py +++ b/source/widget/FrameSurvey.py @@ -137,6 +137,8 @@ class FrameSurvey(QFrame): self.frame_survey = survey # change the widget on the layout self._layout.replaceWidget(old_frame_survey, self.frame_survey) + # adjust the size of the widgets + self.window().adjustSize() # call the new survey event survey.on_show() # delete the old frame