-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathother_views.py
More file actions
335 lines (297 loc) · 11.8 KB
/
other_views.py
File metadata and controls
335 lines (297 loc) · 11.8 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
"""Collection of other views aside from the main ones."""
from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import (
QCheckBox,
QComboBox,
QDialog,
QFrame,
QHBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QTextBrowser,
QVBoxLayout,
)
class DoseTimeDialog(QDialog):
"""Pick dose and time (or steady state)."""
def __init__(
self, columns: list[str], dose_suggested: list[str], parent=None
):
super().__init__(parent)
self.setWindowTitle("Select Dose and Time")
order = [c for c in dose_suggested if c in columns] + [
c for c in columns if c not in dose_suggested
]
self._dose = QComboBox(self)
self._dose.addItems(order)
self._time = QLineEdit(self)
self._time.setPlaceholderText(
"Enter constant time (e.g. 0, 5, 12.5). Use 'inf' for steady state"
)
self._preeq_edit = QLineEdit(self)
self._preeq_edit.setPlaceholderText(
"Optional preequilibrationConditionId"
)
self._dose_lbl = QLabel("Dose column:", self)
self._time_lbl = QLabel("Time:", self)
self._preeq_lbl = QLabel(
"Preequilibration condition (optional):", self
)
ok = QPushButton("OK", self)
ok.clicked.connect(self.accept)
cancel = QPushButton("Cancel", self)
cancel.clicked.connect(self.reject)
lay = QVBoxLayout(self)
row1 = QHBoxLayout()
row1.addWidget(self._dose_lbl)
row1.addWidget(self._dose)
lay.addLayout(row1)
row2 = QHBoxLayout()
row2.addWidget(self._time_lbl)
row2.addWidget(self._time)
lay.addLayout(row2)
row3 = QHBoxLayout()
row3.addWidget(self._preeq_lbl)
row3.addWidget(self._preeq_edit)
lay.addLayout(row3)
btns = QHBoxLayout()
btns.addWidget(cancel)
btns.addWidget(ok)
lay.addLayout(btns)
def get_result(self) -> tuple[str | None, str | None, str]:
dose = self._dose.currentText() or None
time_text = (self._time.text() or "").strip() or None
preeq = (self._preeq_edit.text() or "").strip()
return dose, time_text, preeq
class NextStepsPanel(QDialog):
"""Non-modal panel showing possible next steps after saving."""
dont_show_again_changed = Signal(bool)
# Styling constants
MIN_WIDTH = 450
MAX_WIDTH = 600
MIN_HEIGHT = 360
FRAME_PADDING = 8
FRAME_BORDER_RADIUS = 4
LAYOUT_MARGIN = 12
LAYOUT_SPACING = 10
# Card background colors
COLOR_BENCHMARK = "rgba(255, 193, 7, 0.08)"
COLOR_PYPESTO = "rgba(100, 149, 237, 0.08)"
COLOR_COPASI = "rgba(169, 169, 169, 0.08)"
COLOR_OTHER_TOOLS = "rgba(144, 238, 144, 0.08)"
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Possible next steps")
self.setModal(False)
self.setMinimumWidth(self.MIN_WIDTH)
self.setMaximumWidth(self.MAX_WIDTH)
self.setMinimumHeight(self.MIN_HEIGHT)
# Main layout
main_layout = QVBoxLayout(self)
main_layout.setContentsMargins(
self.LAYOUT_MARGIN,
self.LAYOUT_MARGIN,
self.LAYOUT_MARGIN,
self.LAYOUT_MARGIN,
)
main_layout.setSpacing(self.LAYOUT_SPACING)
# Description
desc = QLabel(
"This parameter estimation problem can now be used in the following tools:"
)
desc.setWordWrap(True)
main_layout.addWidget(desc)
# Main suggestions
suggestions_layout = QVBoxLayout()
suggestions_layout.setSpacing(8)
# Benchmark Collection action
benchmark_frame = self._create_tool_card(
bg_color=self.COLOR_BENCHMARK,
html_content=(
'<p style="margin:0; line-height:1.3;">'
"<b>📚 Contribute to Benchmark Collection</b><br/>"
"Share your publsihed PEtab problem with the community to "
"validate it, enable reproducibility, and support "
"benchmarking<br/>"
'<a href="https://github.com/Benchmarking-Initiative/'
'Benchmark-Models-PEtab">Benchmark Collection</a></p>'
),
)
suggestions_layout.addWidget(benchmark_frame)
# pyPESTO action
pypesto_frame = self._create_tool_card(
bg_color=self.COLOR_PYPESTO,
html_content=(
'<p style="margin:0; line-height:1.3;">'
"<b>▶ Parameter Estimation with pyPESTO</b><br/>"
"Use pyPESTO for parameter estimation, uncertainty analysis, "
"and model selection<br/>"
'<a href="https://pypesto.readthedocs.io/en/latest/example/'
'petab_import.html">pyPESTO documentation</a></p>'
),
)
suggestions_layout.addWidget(pypesto_frame)
# COPASI action
copasi_frame = self._create_tool_card(
bg_color=self.COLOR_COPASI,
html_content=(
'<p style="margin:0; line-height:1.3;">'
"<b>⚙ Advanced Model Adaptation and Simulation</b><br/>"
"Use COPASI for further model adjustment and advanced "
"simulation with a graphical interface<br/>"
'<a href="https://copasi.org">COPASI website</a></p>'
),
)
suggestions_layout.addWidget(copasi_frame)
main_layout.addLayout(suggestions_layout)
# Collapsible section for other tools
self._other_tools_btn = QPushButton(
"📊 ▶ Other tools supporting PEtab"
)
self._other_tools_btn.setCheckable(True)
self._other_tools_btn.setFlat(True)
self._other_tools_btn.setStyleSheet(
"QPushButton { text-align: left; padding: 6px; "
"font-weight: normal; }"
"QPushButton:checked { font-weight: bold; }"
)
self._other_tools_btn.clicked.connect(self._toggle_other_tools)
main_layout.addWidget(self._other_tools_btn)
# Other tools frame (initially hidden)
self._other_tools_frame = QFrame()
self._other_tools_frame.setStyleSheet(
f"QFrame {{ background-color: {self.COLOR_OTHER_TOOLS}; "
f"border-radius: {self.FRAME_BORDER_RADIUS}px; "
f"padding: {self.FRAME_PADDING}px; }}"
)
self._other_tools_frame.setVisible(False)
other_tools_layout = QVBoxLayout(self._other_tools_frame)
other_tools_layout.setContentsMargins(
self.FRAME_PADDING,
self.FRAME_PADDING,
self.FRAME_PADDING,
self.FRAME_PADDING,
)
other_tools_layout.setSpacing(4)
# Framing text
framing_text = QLabel("Additional tools in the PEtab ecosystem:")
framing_text.setWordWrap(True)
other_tools_layout.addWidget(framing_text)
other_tools_text = QTextBrowser()
other_tools_text.setOpenExternalLinks(True)
other_tools_text.setMaximumHeight(120)
other_tools_text.setFrameStyle(QFrame.NoFrame)
other_tools_text.setStyleSheet(
"QTextBrowser { background: transparent; }"
)
other_tools_text.setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded
)
other_tools_text.setHtml(
'<ul style="margin:4px 0; padding-left: 20px; '
'line-height: 1.6;">'
'<li style="margin-bottom: 4px;">'
'<a href="https://amici.readthedocs.io/en/latest/examples/'
'example_petab/petab.html">AMICI</a> - '
"Efficient simulation and sensitivity analysis</li>"
'<li style="margin-bottom: 4px;">'
'<a href="https://sebapersson.github.io/PEtab.jl/stable/">'
"PEtab.jl</a> - "
"High-performance Julia parameter estimation</li>"
'<li style="margin-bottom: 4px;">'
'<a href="https://github.com/Data2Dynamics/d2d/wiki">'
"Data2Dynamics</a> - "
"MATLAB-based comprehensive modeling framework</li>"
'<li style="margin-bottom: 4px;">'
'<a href="https://petab.readthedocs.io/en/latest/v1/'
'software_support.html">PEtab documentation</a> - '
"Full list of supporting tools</li>"
"</ul>"
)
other_tools_layout.addWidget(other_tools_text)
main_layout.addWidget(self._other_tools_frame)
# Spacer
main_layout.addStretch()
# Reassurance text
reassurance = QLabel(
"<small><i>You can always access this dialog from the "
"Help menu.</i></small>"
)
reassurance.setWordWrap(True)
reassurance.setStyleSheet("QLabel { color: gray; padding: 0; }")
main_layout.addWidget(reassurance)
# Bottom section with checkbox and close button
bottom_layout = QHBoxLayout()
bottom_layout.setSpacing(8)
self._dont_show_checkbox = QCheckBox("Don't show after saving")
self._dont_show_checkbox.toggled.connect(
self.dont_show_again_changed.emit
)
bottom_layout.addWidget(self._dont_show_checkbox)
bottom_layout.addStretch()
close_btn = QPushButton("Close")
close_btn.clicked.connect(self.close)
close_btn.setDefault(True)
bottom_layout.addWidget(close_btn)
main_layout.addLayout(bottom_layout)
def _create_tool_card(
self, bg_color: str, html_content: str, scrollbar_policy=None
) -> QFrame:
"""Create a styled card for displaying tool information.
Args:
bg_color: Background color for the frame (rgba string)
html_content: HTML content to display in the text browser
scrollbar_policy: Optional scrollbar policy (defaults to AlwaysOff)
Returns:
Configured QFrame containing the tool information
"""
frame = QFrame()
frame.setStyleSheet(
f"QFrame {{ background-color: {bg_color}; "
f"border-radius: {self.FRAME_BORDER_RADIUS}px; "
f"padding: {self.FRAME_PADDING}px; }}"
)
layout = QVBoxLayout(frame)
layout.setContentsMargins(
self.FRAME_PADDING,
self.FRAME_PADDING,
self.FRAME_PADDING,
self.FRAME_PADDING,
)
layout.setSpacing(4)
text_browser = QTextBrowser()
text_browser.setOpenExternalLinks(True)
text_browser.setFrameStyle(QFrame.NoFrame)
text_browser.setStyleSheet("QTextBrowser { background: transparent; }")
if scrollbar_policy is None:
scrollbar_policy = Qt.ScrollBarPolicy.ScrollBarAlwaysOff
text_browser.setVerticalScrollBarPolicy(scrollbar_policy)
text_browser.setHtml(html_content)
layout.addWidget(text_browser)
return frame
def _toggle_other_tools(self, checked):
"""Toggle visibility of other tools section."""
self._other_tools_frame.setVisible(checked)
# Update button text to show expand/collapse state
arrow = "▼" if checked else "▶"
icon = "📊"
self._other_tools_btn.setText(
f"{icon} {arrow} Other tools supporting PEtab"
)
# Adjust window size
self.adjustSize()
def set_dont_show_again(self, dont_show: bool):
"""Set the 'don't show again' checkbox state."""
self._dont_show_checkbox.setChecked(dont_show)
def show_panel(self):
"""Show the panel and center it on the parent."""
if self.parent():
# Center on parent window
parent_geo = self.parent().geometry()
self.move(
parent_geo.center().x() - self.width() // 2,
parent_geo.center().y() - self.height() // 2,
)
self.show()
self.raise_()
self.activateWindow()