statstudio 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- statstudio/__init__.py +9 -0
- statstudio/__main__.py +3 -0
- statstudio/app.py +83 -0
- statstudio/cli.py +116 -0
- statstudio/core/__init__.py +3 -0
- statstudio/core/archive.py +27 -0
- statstudio/core/commands.py +67 -0
- statstudio/core/formula_catalog.py +74 -0
- statstudio/core/formulas.py +605 -0
- statstudio/core/joins.py +123 -0
- statstudio/core/project.py +358 -0
- statstudio/core/runtime.py +321 -0
- statstudio/core/scripting.py +594 -0
- statstudio/core/table.py +796 -0
- statstudio/core/transform.py +450 -0
- statstudio/feature_help.py +595 -0
- statstudio/io/__init__.py +3 -0
- statstudio/io/docx.py +201 -0
- statstudio/io/export.py +99 -0
- statstudio/io/file_import.py +199 -0
- statstudio/io/odbc.py +334 -0
- statstudio/io/sample_data.py +164 -0
- statstudio/io/table_io.py +118 -0
- statstudio/plots/__init__.py +19 -0
- statstudio/plots/advanced.py +651 -0
- statstudio/plots/basic.py +957 -0
- statstudio/plots/bayesian_plots.py +94 -0
- statstudio/plots/common.py +334 -0
- statstudio/plots/diagnostics.py +214 -0
- statstudio/plots/doe_plots.py +235 -0
- statstudio/plots/plotly_builders.py +719 -0
- statstudio/plots/predictive_plots.py +72 -0
- statstudio/plots/registry.py +251 -0
- statstudio/plugins.py +111 -0
- statstudio/resources/help_topics.json +13195 -0
- statstudio/resources/logo.ico +0 -0
- statstudio/resources/logo.png +0 -0
- statstudio/resources/statstudio.svg +8 -0
- statstudio/stats/__init__.py +42 -0
- statstudio/stats/bayesian.py +1094 -0
- statstudio/stats/bayesian_optimization.py +590 -0
- statstudio/stats/common.py +140 -0
- statstudio/stats/correlation.py +135 -0
- statstudio/stats/custom_doe.py +1714 -0
- statstudio/stats/descriptive.py +200 -0
- statstudio/stats/desirability.py +132 -0
- statstudio/stats/distributions.py +331 -0
- statstudio/stats/doe.py +1070 -0
- statstudio/stats/hypothesis.py +1305 -0
- statstudio/stats/multivariate.py +307 -0
- statstudio/stats/optimal_doe.py +264 -0
- statstudio/stats/power.py +194 -0
- statstudio/stats/predictive.py +605 -0
- statstudio/stats/profiler.py +379 -0
- statstudio/stats/quality.py +1218 -0
- statstudio/stats/regression.py +1600 -0
- statstudio/stats/results.py +235 -0
- statstudio/stats/simulator.py +95 -0
- statstudio/stats/survival.py +637 -0
- statstudio/stats/timeseries.py +643 -0
- statstudio/stats/tolerance.py +154 -0
- statstudio/ui/__init__.py +0 -0
- statstudio/ui/analysis_hub.py +271 -0
- statstudio/ui/command_catalog.py +460 -0
- statstudio/ui/command_palette.py +55 -0
- statstudio/ui/console.py +239 -0
- statstudio/ui/dialogs/__init__.py +0 -0
- statstudio/ui/dialogs/advanced_dialogs.py +392 -0
- statstudio/ui/dialogs/base.py +537 -0
- statstudio/ui/dialogs/bayesian_dialogs.py +488 -0
- statstudio/ui/dialogs/bayesian_optimization_dialog.py +299 -0
- statstudio/ui/dialogs/custom_doe_dialog.py +467 -0
- statstudio/ui/dialogs/doe_dialogs.py +220 -0
- statstudio/ui/dialogs/extended_dialogs.py +665 -0
- statstudio/ui/dialogs/graph_builder.py +139 -0
- statstudio/ui/dialogs/help_dialog.py +207 -0
- statstudio/ui/dialogs/help_topics.py +280 -0
- statstudio/ui/dialogs/lazy.py +184 -0
- statstudio/ui/dialogs/odbc_dialog.py +311 -0
- statstudio/ui/dialogs/plot_dialog.py +1385 -0
- statstudio/ui/dialogs/report_composer.py +218 -0
- statstudio/ui/dialogs/script_dialogs.py +267 -0
- statstudio/ui/dialogs/stats_dialogs.py +1688 -0
- statstudio/ui/dialogs/table_dialogs.py +997 -0
- statstudio/ui/dialogs/window.py +58 -0
- statstudio/ui/docks/__init__.py +0 -0
- statstudio/ui/formula_editor.py +121 -0
- statstudio/ui/icons.py +257 -0
- statstudio/ui/jobs.py +179 -0
- statstudio/ui/main_window.py +3934 -0
- statstudio/ui/plot_interaction.py +178 -0
- statstudio/ui/profiler_widget.py +437 -0
- statstudio/ui/recent.py +82 -0
- statstudio/ui/reports/__init__.py +0 -0
- statstudio/ui/reports/report_view.py +1632 -0
- statstudio/ui/script_jobs.py +35 -0
- statstudio/ui/scripts_panel.py +271 -0
- statstudio/ui/table_document.py +233 -0
- statstudio/ui/table_model.py +285 -0
- statstudio/ui/table_view.py +285 -0
- statstudio/ui/theme.py +645 -0
- statstudio/ui/welcome.py +453 -0
- statstudio/ui/window_controls.py +53 -0
- statstudio/ui/workers.py +53 -0
- statstudio-0.1.0.dist-info/METADATA +261 -0
- statstudio-0.1.0.dist-info/RECORD +110 -0
- statstudio-0.1.0.dist-info/WHEEL +5 -0
- statstudio-0.1.0.dist-info/entry_points.txt +5 -0
- statstudio-0.1.0.dist-info/licenses/LICENSE +674 -0
- statstudio-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Iterable, Sequence
|
|
4
|
+
|
|
5
|
+
from PySide6.QtCore import QMimeData, Qt, Signal
|
|
6
|
+
from PySide6.QtWidgets import (
|
|
7
|
+
QCheckBox,
|
|
8
|
+
QComboBox,
|
|
9
|
+
QDialog,
|
|
10
|
+
QDialogButtonBox,
|
|
11
|
+
QDoubleSpinBox,
|
|
12
|
+
QFormLayout,
|
|
13
|
+
QFrame,
|
|
14
|
+
QHBoxLayout,
|
|
15
|
+
QLabel,
|
|
16
|
+
QLineEdit,
|
|
17
|
+
QListWidget,
|
|
18
|
+
QListWidgetItem,
|
|
19
|
+
QMessageBox,
|
|
20
|
+
QSpinBox,
|
|
21
|
+
QTabWidget,
|
|
22
|
+
QToolButton,
|
|
23
|
+
QVBoxLayout,
|
|
24
|
+
QWidget,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from statstudio.core.table import DataTable
|
|
28
|
+
from statstudio.ui.dialogs.window import IndependentDialog
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ColumnDragList(QListWidget):
|
|
32
|
+
"""A read-only list of column names that can be dragged onto role widgets."""
|
|
33
|
+
|
|
34
|
+
def __init__(self, items: Iterable[str], parent: QWidget | None = None) -> None:
|
|
35
|
+
super().__init__(parent)
|
|
36
|
+
self.addItems([str(item) for item in items])
|
|
37
|
+
self.setDragEnabled(True)
|
|
38
|
+
self.setDragDropMode(QListWidget.DragDropMode.DragOnly)
|
|
39
|
+
self.setSelectionMode(QListWidget.SelectionMode.SingleSelection)
|
|
40
|
+
self.setToolTip("Drag a column onto a graph role to assign it.")
|
|
41
|
+
|
|
42
|
+
def mimeData(self, items) -> QMimeData: # type: ignore[override]
|
|
43
|
+
data = QMimeData()
|
|
44
|
+
if items:
|
|
45
|
+
data.setText(items[0].text())
|
|
46
|
+
return data
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ColumnDropCombo(QComboBox):
|
|
50
|
+
"""A combo box that accepts a dragged column name and selects it."""
|
|
51
|
+
|
|
52
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
53
|
+
super().__init__(parent)
|
|
54
|
+
self.setAcceptDrops(True)
|
|
55
|
+
|
|
56
|
+
def dragEnterEvent(self, event) -> None: # type: ignore[override]
|
|
57
|
+
if event.mimeData().hasText():
|
|
58
|
+
event.acceptProposedAction()
|
|
59
|
+
else:
|
|
60
|
+
super().dragEnterEvent(event)
|
|
61
|
+
|
|
62
|
+
def dragMoveEvent(self, event) -> None: # type: ignore[override]
|
|
63
|
+
if event.mimeData().hasText():
|
|
64
|
+
event.acceptProposedAction()
|
|
65
|
+
else:
|
|
66
|
+
super().dragMoveEvent(event)
|
|
67
|
+
|
|
68
|
+
def dropEvent(self, event) -> None: # type: ignore[override]
|
|
69
|
+
if event.mimeData().hasText():
|
|
70
|
+
text = event.mimeData().text().strip()
|
|
71
|
+
index = self.findData(text)
|
|
72
|
+
if index < 0:
|
|
73
|
+
index = self.findText(text)
|
|
74
|
+
if index >= 0:
|
|
75
|
+
self.setCurrentIndex(index)
|
|
76
|
+
event.acceptProposedAction()
|
|
77
|
+
return
|
|
78
|
+
super().dropEvent(event)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class ColumnDropZone(QFrame):
|
|
82
|
+
"""A drag-only graph role cell that holds one or more column names."""
|
|
83
|
+
|
|
84
|
+
columns_changed = Signal(list)
|
|
85
|
+
|
|
86
|
+
def __init__(
|
|
87
|
+
self,
|
|
88
|
+
label: str,
|
|
89
|
+
columns: Iterable[str] | None = None,
|
|
90
|
+
*,
|
|
91
|
+
multi: bool = False,
|
|
92
|
+
parent: QWidget | None = None,
|
|
93
|
+
) -> None:
|
|
94
|
+
super().__init__(parent)
|
|
95
|
+
self._label = label
|
|
96
|
+
self._multi = multi
|
|
97
|
+
self._columns: list[str] = []
|
|
98
|
+
self.allowed_columns: set[str] | None = None
|
|
99
|
+
self.setObjectName("ColumnDropZone")
|
|
100
|
+
self.setAcceptDrops(True)
|
|
101
|
+
self.setMinimumHeight(34)
|
|
102
|
+
self.setStyleSheet(
|
|
103
|
+
"QFrame#ColumnDropZone {"
|
|
104
|
+
" border: 1px dashed #9aa4b2;"
|
|
105
|
+
" border-radius: 7px;"
|
|
106
|
+
" background: rgba(255, 255, 255, 220);"
|
|
107
|
+
"}"
|
|
108
|
+
"QFrame#ColumnDropZone:hover {"
|
|
109
|
+
" border-color: #4a7dbd;"
|
|
110
|
+
" background: rgba(240, 246, 255, 235);"
|
|
111
|
+
"}"
|
|
112
|
+
)
|
|
113
|
+
self.setToolTip(f"Drag one or more columns onto {label}.")
|
|
114
|
+
self._layout = QHBoxLayout(self)
|
|
115
|
+
self._layout.setContentsMargins(7, 3, 7, 3)
|
|
116
|
+
self._layout.setSpacing(4)
|
|
117
|
+
self.set_columns(columns or [])
|
|
118
|
+
|
|
119
|
+
def columns(self) -> list[str]:
|
|
120
|
+
return list(self._columns)
|
|
121
|
+
|
|
122
|
+
def set_multi(self, multi: bool) -> None:
|
|
123
|
+
if self._multi == multi:
|
|
124
|
+
return
|
|
125
|
+
self._multi = multi
|
|
126
|
+
if not multi and len(self._columns) > 1:
|
|
127
|
+
self.set_columns(self._columns[:1])
|
|
128
|
+
|
|
129
|
+
def column(self) -> str | None:
|
|
130
|
+
return self._columns[0] if self._columns else None
|
|
131
|
+
|
|
132
|
+
def set_column(self, column: str | None) -> None:
|
|
133
|
+
self.set_columns([column] if column else [])
|
|
134
|
+
|
|
135
|
+
def set_columns(self, columns: Iterable[str]) -> None:
|
|
136
|
+
clean: list[str] = []
|
|
137
|
+
for column in columns or []:
|
|
138
|
+
name = str(column)
|
|
139
|
+
if name and name not in clean:
|
|
140
|
+
clean.append(name)
|
|
141
|
+
if not self._multi:
|
|
142
|
+
break
|
|
143
|
+
if clean == self._columns:
|
|
144
|
+
return
|
|
145
|
+
self._columns = clean
|
|
146
|
+
self._rebuild()
|
|
147
|
+
self.columns_changed.emit(list(self._columns))
|
|
148
|
+
|
|
149
|
+
def add_column(self, column: str) -> None:
|
|
150
|
+
name = str(column).strip()
|
|
151
|
+
if not name:
|
|
152
|
+
return
|
|
153
|
+
if self._multi:
|
|
154
|
+
if name in self._columns:
|
|
155
|
+
return
|
|
156
|
+
self._columns.append(name)
|
|
157
|
+
else:
|
|
158
|
+
if self._columns == [name]:
|
|
159
|
+
return
|
|
160
|
+
self._columns = [name]
|
|
161
|
+
self._rebuild()
|
|
162
|
+
self.columns_changed.emit(list(self._columns))
|
|
163
|
+
|
|
164
|
+
def remove_column(self, column: str) -> None:
|
|
165
|
+
if column not in self._columns:
|
|
166
|
+
return
|
|
167
|
+
self._columns = [name for name in self._columns if name != column]
|
|
168
|
+
self._rebuild()
|
|
169
|
+
self.columns_changed.emit(list(self._columns))
|
|
170
|
+
|
|
171
|
+
def clear(self) -> None:
|
|
172
|
+
if not self._columns:
|
|
173
|
+
return
|
|
174
|
+
self._columns = []
|
|
175
|
+
self._rebuild()
|
|
176
|
+
self.columns_changed.emit([])
|
|
177
|
+
|
|
178
|
+
def _clear_layout(self) -> None:
|
|
179
|
+
while self._layout.count():
|
|
180
|
+
item = self._layout.takeAt(0)
|
|
181
|
+
widget = item.widget()
|
|
182
|
+
if widget is not None:
|
|
183
|
+
widget.deleteLater()
|
|
184
|
+
|
|
185
|
+
def _rebuild(self) -> None:
|
|
186
|
+
self._clear_layout()
|
|
187
|
+
if not self._columns:
|
|
188
|
+
placeholder = QLabel(self._label)
|
|
189
|
+
placeholder.setStyleSheet("color: #8a93a0; background: transparent;")
|
|
190
|
+
placeholder.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents, True)
|
|
191
|
+
self._layout.addWidget(placeholder)
|
|
192
|
+
else:
|
|
193
|
+
for name in self._columns:
|
|
194
|
+
chip = QToolButton(self)
|
|
195
|
+
chip.setText(f"{name} \u00d7")
|
|
196
|
+
chip.setAutoRaise(True)
|
|
197
|
+
chip.setCursor(Qt.CursorShape.PointingHandCursor)
|
|
198
|
+
chip.setToolTip(f"Remove {name}")
|
|
199
|
+
chip.setStyleSheet(
|
|
200
|
+
"QToolButton {"
|
|
201
|
+
" border: 1px solid #c2cbd6;"
|
|
202
|
+
" border-radius: 5px;"
|
|
203
|
+
" padding: 1px 5px;"
|
|
204
|
+
" background: #eef3fa;"
|
|
205
|
+
" color: #263447;"
|
|
206
|
+
"}"
|
|
207
|
+
"QToolButton:hover { background: #dde9f8; }"
|
|
208
|
+
)
|
|
209
|
+
chip.clicked.connect(lambda _checked=False, column=name: self.remove_column(column))
|
|
210
|
+
self._layout.addWidget(chip)
|
|
211
|
+
self._layout.addStretch(1)
|
|
212
|
+
self.updateGeometry()
|
|
213
|
+
|
|
214
|
+
def dragEnterEvent(self, event) -> None: # type: ignore[override]
|
|
215
|
+
if event.mimeData().hasText():
|
|
216
|
+
event.acceptProposedAction()
|
|
217
|
+
else:
|
|
218
|
+
super().dragEnterEvent(event)
|
|
219
|
+
|
|
220
|
+
def dragMoveEvent(self, event) -> None: # type: ignore[override]
|
|
221
|
+
if event.mimeData().hasText():
|
|
222
|
+
event.acceptProposedAction()
|
|
223
|
+
else:
|
|
224
|
+
super().dragMoveEvent(event)
|
|
225
|
+
|
|
226
|
+
def dropEvent(self, event) -> None: # type: ignore[override]
|
|
227
|
+
if event.mimeData().hasText():
|
|
228
|
+
column = event.mimeData().text().strip()
|
|
229
|
+
if column and (self.allowed_columns is None or column in self.allowed_columns):
|
|
230
|
+
self.add_column(column)
|
|
231
|
+
event.acceptProposedAction()
|
|
232
|
+
return
|
|
233
|
+
super().dropEvent(event)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class CheckList(QListWidget):
|
|
237
|
+
def __init__(self, items: Iterable[str], checked: Iterable[str] | None = None, parent: QWidget | None = None) -> None:
|
|
238
|
+
super().__init__(parent)
|
|
239
|
+
checked = set(checked or [])
|
|
240
|
+
self.setSelectionMode(QListWidget.SelectionMode.NoSelection)
|
|
241
|
+
for name in items:
|
|
242
|
+
item = QListWidgetItem(str(name))
|
|
243
|
+
item.setFlags(item.flags() | Qt.ItemFlag.ItemIsUserCheckable)
|
|
244
|
+
item.setCheckState(Qt.CheckState.Checked if str(name) in checked else Qt.CheckState.Unchecked)
|
|
245
|
+
self.addItem(item)
|
|
246
|
+
|
|
247
|
+
def checked_items(self) -> list[str]:
|
|
248
|
+
return [self.item(i).text() for i in range(self.count()) if self.item(i).checkState() == Qt.CheckState.Checked]
|
|
249
|
+
|
|
250
|
+
def check_all(self, checked: bool = True) -> None:
|
|
251
|
+
state = Qt.CheckState.Checked if checked else Qt.CheckState.Unchecked
|
|
252
|
+
for index in range(self.count()):
|
|
253
|
+
self.item(index).setCheckState(state)
|
|
254
|
+
|
|
255
|
+
def set_checked(self, items: Iterable[str]) -> None:
|
|
256
|
+
wanted = {str(item) for item in items}
|
|
257
|
+
for index in range(self.count()):
|
|
258
|
+
item = self.item(index)
|
|
259
|
+
item.setCheckState(Qt.CheckState.Checked if item.text() in wanted else Qt.CheckState.Unchecked)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
class BaseDialog(IndependentDialog):
|
|
263
|
+
def __init__(self, table: DataTable | None, title: str, parent: QWidget | None = None) -> None:
|
|
264
|
+
super().__init__(parent)
|
|
265
|
+
self.setWindowTitle(title)
|
|
266
|
+
self.table = table
|
|
267
|
+
self.result: Any = None
|
|
268
|
+
self._outer = QVBoxLayout(self)
|
|
269
|
+
self._tabs = QTabWidget()
|
|
270
|
+
self._outer.addWidget(self._tabs, 1)
|
|
271
|
+
self._form = QFormLayout()
|
|
272
|
+
self._add_page("Main")
|
|
273
|
+
self._buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
|
|
274
|
+
self._buttons.accepted.connect(self.accept)
|
|
275
|
+
self._buttons.rejected.connect(self.reject)
|
|
276
|
+
self._outer.addWidget(self._buttons)
|
|
277
|
+
self.setMinimumWidth(460)
|
|
278
|
+
self._active_job = None
|
|
279
|
+
from statstudio.ui.dialogs.help_topics import add_help_button, install_context_help
|
|
280
|
+
|
|
281
|
+
self._help_button = add_help_button(self._buttons, self)
|
|
282
|
+
install_context_help(self)
|
|
283
|
+
|
|
284
|
+
def _add_page(self, title: str) -> QFormLayout:
|
|
285
|
+
page = QWidget()
|
|
286
|
+
form = QFormLayout(page)
|
|
287
|
+
form.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow)
|
|
288
|
+
self._tabs.addTab(page, title)
|
|
289
|
+
self._form = form
|
|
290
|
+
return form
|
|
291
|
+
|
|
292
|
+
def add_page(self, title: str) -> QFormLayout:
|
|
293
|
+
return self._add_page(title)
|
|
294
|
+
|
|
295
|
+
def add_drag_drop_page(self, title: str, columns: Sequence[str]) -> tuple[QFormLayout, "ColumnDragList"]:
|
|
296
|
+
"""Create a page with draggable columns on the left and role inputs on the right."""
|
|
297
|
+
page = QWidget()
|
|
298
|
+
row = QHBoxLayout(page)
|
|
299
|
+
palette = ColumnDragList(columns)
|
|
300
|
+
palette.setFixedWidth(170)
|
|
301
|
+
row.addWidget(palette, 0)
|
|
302
|
+
form = QFormLayout()
|
|
303
|
+
form.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow)
|
|
304
|
+
row.addLayout(form, 1)
|
|
305
|
+
self._tabs.addTab(page, title)
|
|
306
|
+
self._form = form
|
|
307
|
+
return form, palette
|
|
308
|
+
|
|
309
|
+
@property
|
|
310
|
+
def df(self):
|
|
311
|
+
if self.table is None:
|
|
312
|
+
raise ValueError("No data table selected.")
|
|
313
|
+
return self.table.analysis_df(honor_modeling=True)
|
|
314
|
+
|
|
315
|
+
def add_row(self, label: str, widget: QWidget) -> QWidget:
|
|
316
|
+
self._form.addRow(label, widget)
|
|
317
|
+
return widget
|
|
318
|
+
|
|
319
|
+
def add_label(self, text: str) -> QLabel:
|
|
320
|
+
label = QLabel(text)
|
|
321
|
+
label.setWordWrap(True)
|
|
322
|
+
label.setStyleSheet("color:#5a6270;")
|
|
323
|
+
self._outer.insertWidget(0, label)
|
|
324
|
+
return label
|
|
325
|
+
|
|
326
|
+
def add_combo(
|
|
327
|
+
self,
|
|
328
|
+
label: str,
|
|
329
|
+
items: Sequence[str],
|
|
330
|
+
*,
|
|
331
|
+
default: str | None = None,
|
|
332
|
+
allow_none: bool = False,
|
|
333
|
+
none_label: str = "(none)",
|
|
334
|
+
drop_enabled: bool = False,
|
|
335
|
+
) -> QComboBox:
|
|
336
|
+
combo = ColumnDropCombo() if drop_enabled else QComboBox()
|
|
337
|
+
if allow_none:
|
|
338
|
+
combo.addItem(none_label, None)
|
|
339
|
+
for item in items:
|
|
340
|
+
combo.addItem(str(item), str(item))
|
|
341
|
+
if default is not None:
|
|
342
|
+
index = combo.findData(default)
|
|
343
|
+
if index >= 0:
|
|
344
|
+
combo.setCurrentIndex(index)
|
|
345
|
+
self.add_row(label, combo)
|
|
346
|
+
return combo
|
|
347
|
+
|
|
348
|
+
def add_multi(self, label: str, items: Sequence[str], checked: Sequence[str] | None = None) -> CheckList:
|
|
349
|
+
widget = CheckList(items, checked)
|
|
350
|
+
widget.setMaximumHeight(150)
|
|
351
|
+
self.add_row(label, widget)
|
|
352
|
+
return widget
|
|
353
|
+
|
|
354
|
+
def add_int(self, label: str, value: int = 0, minimum: int = -1_000_000, maximum: int = 1_000_000) -> QSpinBox:
|
|
355
|
+
widget = QSpinBox()
|
|
356
|
+
widget.setRange(minimum, maximum)
|
|
357
|
+
widget.setValue(value)
|
|
358
|
+
self.add_row(label, widget)
|
|
359
|
+
return widget
|
|
360
|
+
|
|
361
|
+
def add_float(self, label: str, value: float = 0.0, minimum: float = -1e12, maximum: float = 1e12, decimals: int = 4) -> QDoubleSpinBox:
|
|
362
|
+
widget = QDoubleSpinBox()
|
|
363
|
+
widget.setRange(minimum, maximum)
|
|
364
|
+
widget.setDecimals(decimals)
|
|
365
|
+
widget.setValue(value)
|
|
366
|
+
self.add_row(label, widget)
|
|
367
|
+
return widget
|
|
368
|
+
|
|
369
|
+
def add_text(self, label: str, value: str = "") -> QLineEdit:
|
|
370
|
+
widget = QLineEdit(value)
|
|
371
|
+
self.add_row(label, widget)
|
|
372
|
+
return widget
|
|
373
|
+
|
|
374
|
+
def add_bool(self, label: str, checked: bool = False) -> QCheckBox:
|
|
375
|
+
widget = QCheckBox()
|
|
376
|
+
widget.setChecked(checked)
|
|
377
|
+
self.add_row(label, widget)
|
|
378
|
+
return widget
|
|
379
|
+
|
|
380
|
+
def make_job(self):
|
|
381
|
+
"""Return a pure worker callable, or None for a quick synchronous compute."""
|
|
382
|
+
return None
|
|
383
|
+
|
|
384
|
+
def accept(self) -> None:
|
|
385
|
+
if self._active_job is not None:
|
|
386
|
+
return
|
|
387
|
+
try:
|
|
388
|
+
job = self.make_job()
|
|
389
|
+
except Exception as exc:
|
|
390
|
+
QMessageBox.critical(self, "Analysis failed", str(exc))
|
|
391
|
+
return
|
|
392
|
+
if job is None:
|
|
393
|
+
try:
|
|
394
|
+
self.result = self.compute()
|
|
395
|
+
except Exception as exc:
|
|
396
|
+
QMessageBox.critical(self, "Analysis failed", str(exc))
|
|
397
|
+
return
|
|
398
|
+
super().accept()
|
|
399
|
+
return
|
|
400
|
+
|
|
401
|
+
from shiboken6 import isValid
|
|
402
|
+
|
|
403
|
+
from statstudio.ui.jobs import start_job
|
|
404
|
+
|
|
405
|
+
self.setEnabled(False)
|
|
406
|
+
|
|
407
|
+
def completed(result) -> None:
|
|
408
|
+
if not isValid(self):
|
|
409
|
+
return
|
|
410
|
+
self._active_job = None
|
|
411
|
+
self.result = self.finish(result)
|
|
412
|
+
self.setEnabled(True)
|
|
413
|
+
QDialog.accept(self)
|
|
414
|
+
|
|
415
|
+
def failed(message: str, details: str) -> None:
|
|
416
|
+
if not isValid(self):
|
|
417
|
+
return
|
|
418
|
+
self._active_job = None
|
|
419
|
+
self.setEnabled(True)
|
|
420
|
+
QMessageBox.critical(self, "Analysis failed", f"{message}\n\n{details}".strip())
|
|
421
|
+
|
|
422
|
+
def cancelled() -> None:
|
|
423
|
+
if not isValid(self):
|
|
424
|
+
return
|
|
425
|
+
self._active_job = None
|
|
426
|
+
self.setEnabled(True)
|
|
427
|
+
|
|
428
|
+
self._active_job = start_job(
|
|
429
|
+
self,
|
|
430
|
+
self.windowTitle(),
|
|
431
|
+
job,
|
|
432
|
+
on_result=completed,
|
|
433
|
+
on_error=failed,
|
|
434
|
+
on_cancelled=cancelled,
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
def reject(self) -> None:
|
|
438
|
+
if self._active_job is not None:
|
|
439
|
+
return
|
|
440
|
+
super().reject()
|
|
441
|
+
|
|
442
|
+
def show_help(self) -> None:
|
|
443
|
+
from statstudio.ui.dialogs.help_topics import dialog_help_topic, open_help
|
|
444
|
+
|
|
445
|
+
open_help(self, dialog_help_topic(self))
|
|
446
|
+
|
|
447
|
+
def compute(self) -> Any:
|
|
448
|
+
raise NotImplementedError
|
|
449
|
+
|
|
450
|
+
def require_table(self) -> DataTable:
|
|
451
|
+
if self.table is None:
|
|
452
|
+
raise ValueError("No data table selected.")
|
|
453
|
+
return self.table
|
|
454
|
+
|
|
455
|
+
def finish(self, result):
|
|
456
|
+
if hasattr(result, "source_table"):
|
|
457
|
+
result.source_table = self.table.name if self.table else ""
|
|
458
|
+
return result
|
|
459
|
+
|
|
460
|
+
def apply_kind(self, kind: str) -> None:
|
|
461
|
+
"""Select the sub-analysis that produced a saved report, when applicable."""
|
|
462
|
+
|
|
463
|
+
def apply_params(self, params: dict[str, Any] | None) -> None:
|
|
464
|
+
for key, value in (params or {}).items():
|
|
465
|
+
widget = getattr(self, key, None)
|
|
466
|
+
if widget is None:
|
|
467
|
+
for suffix in ("_combo", "_spin", "_check", "_edit", "_text", "_list"):
|
|
468
|
+
candidate = getattr(self, f"{key}{suffix}", None)
|
|
469
|
+
if candidate is not None:
|
|
470
|
+
widget = candidate
|
|
471
|
+
break
|
|
472
|
+
if widget is None:
|
|
473
|
+
continue
|
|
474
|
+
if isinstance(widget, QComboBox):
|
|
475
|
+
if value is None:
|
|
476
|
+
index = widget.findData(None)
|
|
477
|
+
else:
|
|
478
|
+
index = widget.findData(value)
|
|
479
|
+
if index < 0:
|
|
480
|
+
index = widget.findText(str(value))
|
|
481
|
+
if index >= 0:
|
|
482
|
+
widget.setCurrentIndex(index)
|
|
483
|
+
continue
|
|
484
|
+
if value is None:
|
|
485
|
+
continue
|
|
486
|
+
if isinstance(widget, CheckList):
|
|
487
|
+
widget.check_all(False)
|
|
488
|
+
selected = {str(item) for item in value} if isinstance(value, (list, tuple, set)) else {str(value)}
|
|
489
|
+
for index in range(widget.count()):
|
|
490
|
+
item = widget.item(index)
|
|
491
|
+
if item.text() in selected:
|
|
492
|
+
item.setCheckState(Qt.CheckState.Checked)
|
|
493
|
+
elif isinstance(widget, (QSpinBox, QDoubleSpinBox)):
|
|
494
|
+
widget.setValue(value)
|
|
495
|
+
elif isinstance(widget, QCheckBox):
|
|
496
|
+
widget.setChecked(bool(value))
|
|
497
|
+
elif isinstance(widget, QLineEdit):
|
|
498
|
+
widget.setText(str(value))
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def text_value(widget: QLineEdit) -> str:
|
|
502
|
+
return widget.text().strip()
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
def combo_value(widget: QComboBox) -> str | None:
|
|
506
|
+
data = widget.currentData()
|
|
507
|
+
return None if data is None else str(data)
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
def show_frame(parent: QWidget | None, title: str, frame, message: str = "") -> None:
|
|
511
|
+
import pandas as pd
|
|
512
|
+
from PySide6.QtWidgets import QTableWidget, QTableWidgetItem
|
|
513
|
+
|
|
514
|
+
dialog = QDialog(parent)
|
|
515
|
+
dialog.setWindowTitle(title)
|
|
516
|
+
dialog.resize(820, 480)
|
|
517
|
+
layout = QVBoxLayout(dialog)
|
|
518
|
+
if message:
|
|
519
|
+
layout.addWidget(QLabel(message))
|
|
520
|
+
if frame is None or frame.empty:
|
|
521
|
+
layout.addWidget(QLabel("No rows."))
|
|
522
|
+
else:
|
|
523
|
+
display = frame.head(100)
|
|
524
|
+
table = QTableWidget(len(display), len(display.columns))
|
|
525
|
+
table.setHorizontalHeaderLabels([str(c) for c in display.columns])
|
|
526
|
+
for row in range(len(display)):
|
|
527
|
+
for col in range(len(display.columns)):
|
|
528
|
+
value = display.iat[row, col]
|
|
529
|
+
text = "" if pd.isna(value) else (f"{value:.6g}" if isinstance(value, float) else str(value))
|
|
530
|
+
table.setItem(row, col, QTableWidgetItem(text))
|
|
531
|
+
table.resizeColumnsToContents()
|
|
532
|
+
layout.addWidget(table)
|
|
533
|
+
close = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
|
|
534
|
+
close.rejected.connect(dialog.reject)
|
|
535
|
+
close.accepted.connect(dialog.accept)
|
|
536
|
+
layout.addWidget(close)
|
|
537
|
+
dialog.exec()
|