An error occurred while loading the file. Please try again.
-
Pierre-Antoine Rouby authoredfa2454d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Window.py -- Pamhyr
# Copyright (C) 2023 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from Model.Study import Study
from View.Tools.PamhyrWindow import PamhyrDialog
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import (
QRadioButton, QLabel, QDateTimeEdit,
)
_translate = QCoreApplication.translate
class NewStudyWindow(PamhyrDialog):
_pamhyr_ui = "NewStudy"
_pamhyr_name = "Edit/New Study"
def __init__(self, study=None, config=None, parent=None):
if study is not None:
name = f"Edit study - {study.name}"
else:
name = "New study"
super(NewStudyWindow, self).__init__(
title=name,
study=study,
config=config,
options=[],
parent=parent
)
if not self._study is None:
self.set_line_edit_text("lineEdit_name", self._study.name)
self.set_text_edit_text(
"textEdit_description", self._study.description)
self.set_datetime_edit("dateTimeEdit_date", self._study.date)
self.find(QLabel, "label_creation_date_data").setText(
self._study.creation_date.isoformat(sep=" ")
)
self.find(QLabel, "label_last_modification_data").setText(
self._study.last_save_date.isoformat(sep=" ")
)
if self._study.time_system == "date":
self.set_radio_button("radioButton_date", True)
self.find(QLabel, "label_date").setEnabled(True)
self.find(QDateTimeEdit, "dateTimeEdit_date").setEnabled(True)
self.connection()
def connection(self):
time = self.find(QRadioButton, "radioButton_time")
date = self.find(QRadioButton, "radioButton_date")
time.toggled.connect(self.set_time)
date.toggled.connect(self.set_date)
def set_time(self):
if self.get_radio_button("radioButton_time"):
self.find(QLabel, "label_date").setEnabled(False)
self.find(QDateTimeEdit, "dateTimeEdit_date").setEnabled(False)
def set_date(self):
if self.get_radio_button("radioButton_date"):
self.find(QLabel, "label_date").setEnabled(True)
self.find(QDateTimeEdit, "dateTimeEdit_date").setEnabled(True)
def accept(self):
name = self.get_line_edit_text("lineEdit_name")
description = self.get_text_edit_text("textEdit_description")
if self._study is None:
study = Study.new(name, description)
if self.get_radio_button("radioButton_date"):
date = self.get_datetime_edit("dateTimeEdit_date")
study.use_date(date)
self.parent.set_model(study)
else:
self._study.name = name
self._study.description = description
if self.get_radio_button("radioButton_date"):
date = self.get_datetime_edit("dateTimeEdit_date")
self._study.use_date(date)
else:
self._study.use_time()
self.done(True)