class ProfileFormWidget(QWidget): ''' classdocs ''' def __init__(self): ''' Constructor ''' QWidget.__init__(self) self._initGUI() def _initGUI(self): self.layout = QVBoxLayout() self.form = QFormLayout() self.name = QLineEdit() self.surname = QLineEdit() self.birthdate = QCalendarWidget() self.birthdate.setGridVisible(True) self.birthdate.setMinimumDate(QDate(1850, 1, 1)) self.birthdate.setMaximumDate(QDate.currentDate()) self.male = QRadioButton("Male") self.male.setChecked(True) self.female = QRadioButton("Female") self.height = QDoubleSpinBox() self.height.setMaximum(250) self.height.setMinimum(50) self.height.setValue(165) self.height.setSuffix(" cm") self.mass = QDoubleSpinBox() self.mass.setMaximum(300) self.mass.setMinimum(20) self.mass.setValue(60) self.mass.setSuffix(" Kg") btnLayout = QVBoxLayout() self.form.addRow("Name", self.name) self.form.addRow("Surname", self.surname) self.form.addRow("Birth date", self.birthdate) sexLayout = QHBoxLayout() sexLayout.addWidget(self.male) sexLayout.addWidget(self.female) self.form.addRow("Sex", sexLayout) self.form.addRow("Height", self.height) self.form.addRow("Mass", self.mass) self.layout.addLayout(self.form) self.layout.addLayout(btnLayout) self.setLayout(self.layout) def getLayout(self): return self.layout def getWidget(self): widget = QWidget() widget.setLayout(self.layout) return widget def setProfile(self, athlete): self.name.setText(athlete._name) self.surname.setText(athlete._surname) self.birthdate.setSelectedDate(athlete._birthDate) if athlete._sex == "Male": self.male.setChecked(True) else: self.female.setChecked(True) self.height.setValue(athlete._height) self.mass.setValue(athlete._mass) def getProfile(self): qDate = self.birthdate.selectedDate() birthDate = self.qDate_to_date(qDate) athleteProfile = Athlete(self.name.text(), self.surname.text(), self._getSex(), birthDate, self.height.value(), self.mass.value()) return athleteProfile def qDate_to_date(self, qDate): return date(qDate.year(), qDate.month(), qDate.day()) def _getSex(self): if (self.male.isChecked()): return "Male" elif (self.female.isChecked()): return "Female" else: print "Error: No sex selected" return False
class PushupForm(QDialog): ''' classdocs ''' pushupCreated = Signal(Pushup_Model) def __init__(self, athlete): ''' Constructor ''' QDialog.__init__(self) self.setWindowTitle("Pushup form") self.athlete = athlete self.pushupForm = QFormLayout() self.createGUI() def createGUI(self): self.series = QSpinBox() self.series.setMinimum(1) self.repetitions = QSpinBox() self.repetitions.setMaximum(512) self.avgHeartRateToggle = QCheckBox() self.avgHeartRateToggle.toggled.connect(self._toggleHeartRateSpinBox) self.avgHeartRate = QSpinBox() self.avgHeartRate.setMinimum(30) self.avgHeartRate.setMaximum(250) self.avgHeartRate.setValue(120) self.avgHeartRate.setDisabled(True) self.dateSelector_widget = QCalendarWidget() self.dateSelector_widget.setMaximumDate(QDate.currentDate()) self.addButton = QPushButton("Add pushup") self.addButton.setMaximumWidth(90) self.addButton.clicked.connect(self._createPushup) self.cancelButton = QPushButton("Cancel") self.cancelButton.setMaximumWidth(90) self.cancelButton.clicked.connect(self.reject) self.pushupForm.addRow("Series", self.series) self.pushupForm.addRow("Repetitions", self.repetitions) self.pushupForm.addRow("Store average heart rate ? ", self.avgHeartRateToggle) self.pushupForm.addRow("Average Heart Rate", self.avgHeartRate) self.pushupForm.addRow("Exercise Date", self.dateSelector_widget) btnsLayout = QVBoxLayout() btnsLayout.addWidget(self.addButton) btnsLayout.addWidget(self.cancelButton) btnsLayout.setAlignment(Qt.AlignRight) layoutWrapper = QVBoxLayout() layoutWrapper.addLayout(self.pushupForm) layoutWrapper.addLayout(btnsLayout) self.setLayout(layoutWrapper) def _createPushup(self): exerciseDate = self.dateSelector_widget.selectedDate() exerciseDate = self.qDate_to_date(exerciseDate) if self.avgHeartRateToggle.isChecked(): heartRate = self.avgHeartRate.value() else: heartRate = None pushup = Pushup_Model(self.athlete._name, exerciseDate, heartRate, self.series.value(), self.repetitions.value()) self.pushupCreated.emit(pushup) self.accept() def _toggleHeartRateSpinBox(self): if self.avgHeartRateToggle.isChecked(): self.avgHeartRate.setDisabled(False) else: self.avgHeartRate.setDisabled(True) def qDate_to_date(self, qDate): return date(qDate.year(), qDate.month(),qDate.day())
class ProfileFormWidget(QWidget): ''' classdocs ''' def __init__(self): ''' Constructor ''' QWidget.__init__(self) self._initGUI() def _initGUI(self): self.layout = QVBoxLayout() self.form = QFormLayout() self.name = QLineEdit() self.surname = QLineEdit() self.birthdate = QCalendarWidget() self.birthdate.setGridVisible(True) self.birthdate.setMinimumDate(QDate(1850,1,1)) self.birthdate.setMaximumDate(QDate.currentDate()) self.male = QRadioButton("Male") self.male.setChecked(True) self.female = QRadioButton("Female") self.height = QDoubleSpinBox() self.height.setMaximum(250) self.height.setMinimum(50) self.height.setValue(165) self.height.setSuffix(" cm") self.mass = QDoubleSpinBox() self.mass.setMaximum(300) self.mass.setMinimum(20) self.mass.setValue(60) self.mass.setSuffix(" Kg") btnLayout = QVBoxLayout() self.form.addRow("Name", self.name) self.form.addRow("Surname", self.surname) self.form.addRow("Birth date",self.birthdate) sexLayout = QHBoxLayout() sexLayout.addWidget(self.male) sexLayout.addWidget(self.female) self.form.addRow("Sex", sexLayout) self.form.addRow("Height", self.height) self.form.addRow("Mass", self.mass) self.layout.addLayout(self.form) self.layout.addLayout(btnLayout) self.setLayout(self.layout) def getLayout(self): return self.layout def getWidget(self): widget = QWidget() widget.setLayout(self.layout) return widget def setProfile(self, athlete): self.name.setText(athlete._name) self.surname.setText(athlete._surname) self.birthdate.setSelectedDate(athlete._birthDate) if athlete._sex=="Male": self.male.setChecked(True) else: self.female.setChecked(True) self.height.setValue(athlete._height) self.mass.setValue(athlete._mass) def getProfile(self): qDate = self.birthdate.selectedDate() birthDate = self.qDate_to_date(qDate) athleteProfile = Athlete(self.name.text(), self.surname.text(), self._getSex(), birthDate, self.height.value(), self.mass.value()) return athleteProfile def qDate_to_date(self, qDate): return date(qDate.year(), qDate.month(),qDate.day()) def _getSex(self): if (self.male.isChecked()): return "Male" elif (self.female.isChecked()): return "Female" else : print "Error: No sex selected" return False
class PushupForm(QDialog): ''' classdocs ''' pushupCreated = Signal(Pushup_Model) def __init__(self, athlete): ''' Constructor ''' QDialog.__init__(self) self.setWindowTitle("Pushup form") self.athlete = athlete self.pushupForm = QFormLayout() self.createGUI() def createGUI(self): self.series = QSpinBox() self.series.setMinimum(1) self.repetitions = QSpinBox() self.repetitions.setMaximum(512) self.avgHeartRateToggle = QCheckBox() self.avgHeartRateToggle.toggled.connect(self._toggleHeartRateSpinBox) self.avgHeartRate = QSpinBox() self.avgHeartRate.setMinimum(30) self.avgHeartRate.setMaximum(250) self.avgHeartRate.setValue(120) self.avgHeartRate.setDisabled(True) self.dateSelector_widget = QCalendarWidget() self.dateSelector_widget.setMaximumDate(QDate.currentDate()) self.addButton = QPushButton("Add pushup") self.addButton.setMaximumWidth(90) self.addButton.clicked.connect(self._createPushup) self.cancelButton = QPushButton("Cancel") self.cancelButton.setMaximumWidth(90) self.cancelButton.clicked.connect(self.reject) self.pushupForm.addRow("Series", self.series) self.pushupForm.addRow("Repetitions", self.repetitions) self.pushupForm.addRow("Store average heart rate ? ", self.avgHeartRateToggle) self.pushupForm.addRow("Average Heart Rate", self.avgHeartRate) self.pushupForm.addRow("Exercise Date", self.dateSelector_widget) btnsLayout = QVBoxLayout() btnsLayout.addWidget(self.addButton) btnsLayout.addWidget(self.cancelButton) btnsLayout.setAlignment(Qt.AlignRight) layoutWrapper = QVBoxLayout() layoutWrapper.addLayout(self.pushupForm) layoutWrapper.addLayout(btnsLayout) self.setLayout(layoutWrapper) def _createPushup(self): exerciseDate = self.dateSelector_widget.selectedDate() exerciseDate = self.qDate_to_date(exerciseDate) if self.avgHeartRateToggle.isChecked(): heartRate = self.avgHeartRate.value() else: heartRate = None pushup = Pushup_Model(self.athlete._name, exerciseDate, heartRate, self.series.value(), self.repetitions.value()) self.pushupCreated.emit(pushup) self.accept() def _toggleHeartRateSpinBox(self): if self.avgHeartRateToggle.isChecked(): self.avgHeartRate.setDisabled(False) else: self.avgHeartRate.setDisabled(True) def qDate_to_date(self, qDate): return date(qDate.year(), qDate.month(), qDate.day())