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