made some graphical adjustment
This commit is contained in:
parent
660669ea89
commit
f9953a3cbb
3 changed files with 27 additions and 9 deletions
|
@ -1,16 +1,26 @@
|
||||||
from typing import Any
|
from typing import Any, Optional
|
||||||
|
|
||||||
from PyQt6.QtCore import Qt, pyqtSignal
|
from PyQt6.QtCore import Qt, pyqtSignal
|
||||||
from PyQt6.QtGui import QFont, QIntValidator
|
from PyQt6.QtGui import QFont
|
||||||
from PyQt6.QtWidgets import QVBoxLayout, QLabel, QDoubleSpinBox, QSpinBox
|
from PyQt6.QtWidgets import QVBoxLayout, QLabel, QSpinBox
|
||||||
|
|
||||||
from source.survey.base import BaseSurvey
|
from source.survey.base import BaseSurvey
|
||||||
|
|
||||||
|
|
||||||
class IntegerQuestion(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__()
|
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 {}
|
self.signals = signals if signals is not None else {}
|
||||||
|
|
||||||
# set layout
|
# set layout
|
||||||
|
@ -30,15 +40,18 @@ class IntegerQuestion(BaseSurvey):
|
||||||
|
|
||||||
# response
|
# response
|
||||||
self.entry_response = QSpinBox()
|
self.entry_response = QSpinBox()
|
||||||
self.entry_response.setMinimum(13)
|
self.entry_response.setMinimum(minimum)
|
||||||
self.entry_response.setMaximum(200)
|
self.entry_response.setMaximum(maximum)
|
||||||
self.entry_response.setValue(30)
|
self.entry_response.setValue(default)
|
||||||
self._layout.addWidget(self.entry_response)
|
self._layout.addWidget(self.entry_response)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "IntegerQuestion":
|
def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "IntegerQuestion":
|
||||||
return cls(
|
return cls(
|
||||||
title=data["title"],
|
title=data["title"],
|
||||||
|
default=data.get("default"),
|
||||||
|
minimum=data.get("minimum"),
|
||||||
|
maximum=data.get("maximum"),
|
||||||
signals=signals,
|
signals=signals,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ class SingleChoiceQuestion(BaseSurvey):
|
||||||
# checking any button allow the user to go to the next step
|
# 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.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():
|
for choice_id, choice_text in choices.items():
|
||||||
# create a radio button for that choice
|
# create a radio button for that choice
|
||||||
button = QRadioButton()
|
button = QRadioButton()
|
||||||
|
@ -48,7 +50,8 @@ class SingleChoiceQuestion(BaseSurvey):
|
||||||
self._layout_responses.addWidget(button)
|
self._layout_responses.addWidget(button)
|
||||||
|
|
||||||
# add the button to the group
|
# 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
|
@classmethod
|
||||||
def from_dict(cls, data: dict[str, Any], signals: dict[str, pyqtSignal]) -> "SingleChoiceQuestion":
|
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:
|
def get_collected_data(self) -> dict:
|
||||||
return {
|
return {
|
||||||
"choice": self.group_responses.checkedId()
|
"choice": self.button_responses_id[self.group_responses.checkedButton()]
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,8 @@ class FrameSurvey(QFrame):
|
||||||
self.frame_survey = survey
|
self.frame_survey = 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_frame_survey, self.frame_survey)
|
||||||
|
# adjust the size of the widgets
|
||||||
|
self.window().adjustSize()
|
||||||
# call the new survey event
|
# call the new survey event
|
||||||
survey.on_show()
|
survey.on_show()
|
||||||
# delete the old frame
|
# delete the old frame
|
||||||
|
|
Loading…
Reference in a new issue