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.
Files changed (110) hide show
  1. statstudio/__init__.py +9 -0
  2. statstudio/__main__.py +3 -0
  3. statstudio/app.py +83 -0
  4. statstudio/cli.py +116 -0
  5. statstudio/core/__init__.py +3 -0
  6. statstudio/core/archive.py +27 -0
  7. statstudio/core/commands.py +67 -0
  8. statstudio/core/formula_catalog.py +74 -0
  9. statstudio/core/formulas.py +605 -0
  10. statstudio/core/joins.py +123 -0
  11. statstudio/core/project.py +358 -0
  12. statstudio/core/runtime.py +321 -0
  13. statstudio/core/scripting.py +594 -0
  14. statstudio/core/table.py +796 -0
  15. statstudio/core/transform.py +450 -0
  16. statstudio/feature_help.py +595 -0
  17. statstudio/io/__init__.py +3 -0
  18. statstudio/io/docx.py +201 -0
  19. statstudio/io/export.py +99 -0
  20. statstudio/io/file_import.py +199 -0
  21. statstudio/io/odbc.py +334 -0
  22. statstudio/io/sample_data.py +164 -0
  23. statstudio/io/table_io.py +118 -0
  24. statstudio/plots/__init__.py +19 -0
  25. statstudio/plots/advanced.py +651 -0
  26. statstudio/plots/basic.py +957 -0
  27. statstudio/plots/bayesian_plots.py +94 -0
  28. statstudio/plots/common.py +334 -0
  29. statstudio/plots/diagnostics.py +214 -0
  30. statstudio/plots/doe_plots.py +235 -0
  31. statstudio/plots/plotly_builders.py +719 -0
  32. statstudio/plots/predictive_plots.py +72 -0
  33. statstudio/plots/registry.py +251 -0
  34. statstudio/plugins.py +111 -0
  35. statstudio/resources/help_topics.json +13195 -0
  36. statstudio/resources/logo.ico +0 -0
  37. statstudio/resources/logo.png +0 -0
  38. statstudio/resources/statstudio.svg +8 -0
  39. statstudio/stats/__init__.py +42 -0
  40. statstudio/stats/bayesian.py +1094 -0
  41. statstudio/stats/bayesian_optimization.py +590 -0
  42. statstudio/stats/common.py +140 -0
  43. statstudio/stats/correlation.py +135 -0
  44. statstudio/stats/custom_doe.py +1714 -0
  45. statstudio/stats/descriptive.py +200 -0
  46. statstudio/stats/desirability.py +132 -0
  47. statstudio/stats/distributions.py +331 -0
  48. statstudio/stats/doe.py +1070 -0
  49. statstudio/stats/hypothesis.py +1305 -0
  50. statstudio/stats/multivariate.py +307 -0
  51. statstudio/stats/optimal_doe.py +264 -0
  52. statstudio/stats/power.py +194 -0
  53. statstudio/stats/predictive.py +605 -0
  54. statstudio/stats/profiler.py +379 -0
  55. statstudio/stats/quality.py +1218 -0
  56. statstudio/stats/regression.py +1600 -0
  57. statstudio/stats/results.py +235 -0
  58. statstudio/stats/simulator.py +95 -0
  59. statstudio/stats/survival.py +637 -0
  60. statstudio/stats/timeseries.py +643 -0
  61. statstudio/stats/tolerance.py +154 -0
  62. statstudio/ui/__init__.py +0 -0
  63. statstudio/ui/analysis_hub.py +271 -0
  64. statstudio/ui/command_catalog.py +460 -0
  65. statstudio/ui/command_palette.py +55 -0
  66. statstudio/ui/console.py +239 -0
  67. statstudio/ui/dialogs/__init__.py +0 -0
  68. statstudio/ui/dialogs/advanced_dialogs.py +392 -0
  69. statstudio/ui/dialogs/base.py +537 -0
  70. statstudio/ui/dialogs/bayesian_dialogs.py +488 -0
  71. statstudio/ui/dialogs/bayesian_optimization_dialog.py +299 -0
  72. statstudio/ui/dialogs/custom_doe_dialog.py +467 -0
  73. statstudio/ui/dialogs/doe_dialogs.py +220 -0
  74. statstudio/ui/dialogs/extended_dialogs.py +665 -0
  75. statstudio/ui/dialogs/graph_builder.py +139 -0
  76. statstudio/ui/dialogs/help_dialog.py +207 -0
  77. statstudio/ui/dialogs/help_topics.py +280 -0
  78. statstudio/ui/dialogs/lazy.py +184 -0
  79. statstudio/ui/dialogs/odbc_dialog.py +311 -0
  80. statstudio/ui/dialogs/plot_dialog.py +1385 -0
  81. statstudio/ui/dialogs/report_composer.py +218 -0
  82. statstudio/ui/dialogs/script_dialogs.py +267 -0
  83. statstudio/ui/dialogs/stats_dialogs.py +1688 -0
  84. statstudio/ui/dialogs/table_dialogs.py +997 -0
  85. statstudio/ui/dialogs/window.py +58 -0
  86. statstudio/ui/docks/__init__.py +0 -0
  87. statstudio/ui/formula_editor.py +121 -0
  88. statstudio/ui/icons.py +257 -0
  89. statstudio/ui/jobs.py +179 -0
  90. statstudio/ui/main_window.py +3934 -0
  91. statstudio/ui/plot_interaction.py +178 -0
  92. statstudio/ui/profiler_widget.py +437 -0
  93. statstudio/ui/recent.py +82 -0
  94. statstudio/ui/reports/__init__.py +0 -0
  95. statstudio/ui/reports/report_view.py +1632 -0
  96. statstudio/ui/script_jobs.py +35 -0
  97. statstudio/ui/scripts_panel.py +271 -0
  98. statstudio/ui/table_document.py +233 -0
  99. statstudio/ui/table_model.py +285 -0
  100. statstudio/ui/table_view.py +285 -0
  101. statstudio/ui/theme.py +645 -0
  102. statstudio/ui/welcome.py +453 -0
  103. statstudio/ui/window_controls.py +53 -0
  104. statstudio/ui/workers.py +53 -0
  105. statstudio-0.1.0.dist-info/METADATA +261 -0
  106. statstudio-0.1.0.dist-info/RECORD +110 -0
  107. statstudio-0.1.0.dist-info/WHEEL +5 -0
  108. statstudio-0.1.0.dist-info/entry_points.txt +5 -0
  109. statstudio-0.1.0.dist-info/licenses/LICENSE +674 -0
  110. statstudio-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,460 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from dataclasses import dataclass
5
+
6
+ from PySide6.QtGui import QAction
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class HubCommandSpec:
11
+ id: str
12
+ path: tuple[str, ...]
13
+ category: str
14
+ description: str
15
+ keywords: tuple[str, ...] = ()
16
+
17
+
18
+ @dataclass(frozen=True)
19
+ class HubCommand:
20
+ id: str
21
+ title: str
22
+ category: str
23
+ description: str
24
+ path: tuple[str, ...]
25
+ action: QAction
26
+ keywords: tuple[str, ...] = ()
27
+
28
+ @property
29
+ def menu_path(self) -> str:
30
+ return " > ".join(self.path)
31
+
32
+
33
+ def normalize_label(text: str) -> str:
34
+ return text.replace("&&", "\0").replace("&", "").replace("\0", "&")
35
+
36
+
37
+ def find_action(menu_bar, path: tuple[str, ...]) -> QAction | None:
38
+ actions = list(menu_bar.actions())
39
+ found: QAction | None = None
40
+ for part in path:
41
+ found = next(
42
+ (action for action in actions if normalize_label(action.text()) == part),
43
+ None,
44
+ )
45
+ if found is None:
46
+ return None
47
+ if part != path[-1]:
48
+ menu = found.menu()
49
+ if menu is None:
50
+ return None
51
+ actions = list(menu.actions())
52
+ return found
53
+
54
+
55
+ def _slug(text: str) -> str:
56
+ value = re.sub(r"[^a-z0-9]+", "-", text.lower()).strip("-")
57
+ return value or "command"
58
+
59
+
60
+ SPECS: tuple[HubCommandSpec, ...] = (
61
+ HubCommandSpec(
62
+ "file.new-table",
63
+ ("File", "New Data Table..."),
64
+ "Data",
65
+ "Create an empty table with columns you define.",
66
+ ("new", "table", "data", "create"),
67
+ ),
68
+ HubCommandSpec(
69
+ "file.import",
70
+ ("File", "Import File..."),
71
+ "Data",
72
+ "Import CSV, Excel, Parquet, JSON, SAS, SPSS, or text data.",
73
+ ("import", "csv", "excel", "parquet", "json"),
74
+ ),
75
+ HubCommandSpec(
76
+ "file.open-project",
77
+ ("File", "Open Project..."),
78
+ "Workspace",
79
+ "Open a saved StatStudio project.",
80
+ ("open", "project", "workspace"),
81
+ ),
82
+ HubCommandSpec(
83
+ "file.new-project",
84
+ ("File", "New Project"),
85
+ "Workspace",
86
+ "Start a new analysis workspace.",
87
+ ("new", "project", "workspace"),
88
+ ),
89
+ HubCommandSpec(
90
+ "analyze.descriptive",
91
+ ("Analyze", "Summary & Distributions", "Summary", "Descriptive Statistics..."),
92
+ "Data",
93
+ "Summarize numeric columns with counts, means, spread, and confidence intervals.",
94
+ ("summary", "mean", "median", "standard deviation"),
95
+ ),
96
+ HubCommandSpec(
97
+ "analyze.grouped-summary",
98
+ ("Analyze", "Summary & Distributions", "Summary", "Grouped Summary..."),
99
+ "Data",
100
+ "Summarize a response by one or more grouping columns.",
101
+ ("summary", "groups", "by", "aggregate"),
102
+ ),
103
+ HubCommandSpec(
104
+ "analyze.frequency",
105
+ ("Analyze", "Summary & Distributions", "Summary", "Frequency Distribution..."),
106
+ "Data",
107
+ "Count category levels and inspect frequency distributions.",
108
+ ("frequency", "count", "categories"),
109
+ ),
110
+ HubCommandSpec(
111
+ "analyze.distribution",
112
+ ("Analyze", "Summary & Distributions", "Distribution", "Distribution Fit..."),
113
+ "Data",
114
+ "Fit and compare probability distributions.",
115
+ ("distribution", "fit", "normal", "weibull"),
116
+ ),
117
+ HubCommandSpec(
118
+ "analyze.distribution-summary",
119
+ ("Analyze", "Summary & Distributions", "Distribution", "Distribution Summary..."),
120
+ "Data",
121
+ "Review distribution quantiles, moments, and diagnostics.",
122
+ ("distribution", "summary", "quantiles"),
123
+ ),
124
+ HubCommandSpec(
125
+ "analyze.normality",
126
+ ("Analyze", "Summary & Distributions", "Distribution", "Normality Test..."),
127
+ "Data",
128
+ "Test whether a column is consistent with a normal distribution.",
129
+ ("normality", "normal", "shapiro", "anderson"),
130
+ ),
131
+ HubCommandSpec(
132
+ "analyze.correlation",
133
+ ("Analyze", "Summary & Distributions", "Correlation..."),
134
+ "Data",
135
+ "Measure linear association between numeric columns.",
136
+ ("correlation", "pearson", "spearman"),
137
+ ),
138
+ HubCommandSpec(
139
+ "analyze.ttest",
140
+ ("Analyze", "Compare Means", "Parametric", "t Test..."),
141
+ "Compare",
142
+ "Compare one or two means, or analyze paired observations.",
143
+ ("t test", "compare", "means", "groups", "paired"),
144
+ ),
145
+ HubCommandSpec(
146
+ "analyze.anova",
147
+ ("Analyze", "Compare Means", "Parametric", "ANOVA / Kruskal-Wallis..."),
148
+ "Compare",
149
+ "Compare several group means with ANOVA or Kruskal-Wallis.",
150
+ ("anova", "kruskal", "compare", "groups", "tukey"),
151
+ ),
152
+ HubCommandSpec(
153
+ "analyze.two-way-anova",
154
+ ("Analyze", "Compare Means", "Parametric", "Two-Way ANOVA..."),
155
+ "Compare",
156
+ "Analyze two factors and their interaction.",
157
+ ("two way", "anova", "interaction", "factors"),
158
+ ),
159
+ HubCommandSpec(
160
+ "analyze.posthoc",
161
+ ("Analyze", "Compare Means", "Parametric", "Post-Hoc Comparisons..."),
162
+ "Compare",
163
+ "Run pairwise comparisons after a significant omnibus test.",
164
+ ("post hoc", "tukey", "dunnett", "pairwise"),
165
+ ),
166
+ HubCommandSpec(
167
+ "analyze.mann-whitney",
168
+ ("Analyze", "Compare Means", "Nonparametric", "Mann-Whitney Test..."),
169
+ "Compare",
170
+ "Compare two independent groups without a normality assumption.",
171
+ ("mann whitney", "nonparametric", "ranks"),
172
+ ),
173
+ HubCommandSpec(
174
+ "analyze.wilcoxon",
175
+ ("Analyze", "Compare Means", "Nonparametric", "Wilcoxon Signed-Rank..."),
176
+ "Compare",
177
+ "Compare paired observations with a signed-rank test.",
178
+ ("wilcoxon", "paired", "nonparametric"),
179
+ ),
180
+ HubCommandSpec(
181
+ "analyze.contingency",
182
+ ("Analyze", "Contingency", "Contingency Analysis..."),
183
+ "Compare",
184
+ "Analyze relationships between categorical variables.",
185
+ ("contingency", "categorical", "chi square", "table"),
186
+ ),
187
+ HubCommandSpec(
188
+ "analyze.chi-square",
189
+ ("Analyze", "Contingency", "Chi-Square Test..."),
190
+ "Compare",
191
+ "Test independence in a contingency table.",
192
+ ("chi square", "independence", "categorical"),
193
+ ),
194
+ HubCommandSpec(
195
+ "analyze.simple-regression",
196
+ ("Analyze", "Regression & Multivariate", "Linear Regression", "Simple..."),
197
+ "Model",
198
+ "Fit a simple linear regression with one predictor.",
199
+ ("regression", "simple", "fit", "line"),
200
+ ),
201
+ HubCommandSpec(
202
+ "analyze.regression",
203
+ ("Analyze", "Regression & Multivariate", "Linear Regression", "Multi Linear..."),
204
+ "Model",
205
+ "Fit a multiple linear regression model.",
206
+ ("regression", "multiple", "linear", "model"),
207
+ ),
208
+ HubCommandSpec(
209
+ "analyze.regression-profiler",
210
+ ("Analyze", "Regression & Multivariate", "Linear Regression", "Prediction Profiler..."),
211
+ "Model",
212
+ "Explore predicted responses across model factors.",
213
+ ("profiler", "prediction", "regression"),
214
+ ),
215
+ HubCommandSpec(
216
+ "analyze.predictive",
217
+ ("Analyze", "Regression & Multivariate", "Predictive Modeling..."),
218
+ "Model",
219
+ "Build and compare predictive machine-learning models.",
220
+ ("predictive", "machine learning", "cart", "random forest", "xgboost"),
221
+ ),
222
+ HubCommandSpec(
223
+ "analyze.multivariate",
224
+ ("Analyze", "Regression & Multivariate", "Multivariate..."),
225
+ "Model",
226
+ "Use PCA, clustering, factor analysis, and related methods.",
227
+ ("multivariate", "pca", "cluster", "factor"),
228
+ ),
229
+ HubCommandSpec(
230
+ "analyze.time-series",
231
+ ("Analyze", "Time Series", "Time Series..."),
232
+ "Model",
233
+ "Explore, decompose, and model time-series data.",
234
+ ("time series", "forecast", "arima", "trend"),
235
+ ),
236
+ HubCommandSpec(
237
+ "analyze.survival",
238
+ ("Analyze", "Survival & Reliability", "Survival..."),
239
+ "Model",
240
+ "Analyze time-to-event data with survival methods.",
241
+ ("survival", "kaplan meier", "logrank", "cox"),
242
+ ),
243
+ HubCommandSpec(
244
+ "analyze.reliability",
245
+ ("Analyze", "Survival & Reliability", "Reliability / Weibull..."),
246
+ "Model",
247
+ "Fit reliability distributions and estimate life characteristics.",
248
+ ("reliability", "weibull", "failure"),
249
+ ),
250
+ HubCommandSpec(
251
+ "analyze.quality",
252
+ ("Analyze", "Quality & SPC", "Quality / SPC..."),
253
+ "Quality",
254
+ "Create control charts, capability studies, Gage R&R, and Pareto charts.",
255
+ ("quality", "spc", "control chart", "cpk", "gage r&r", "pareto"),
256
+ ),
257
+ HubCommandSpec(
258
+ "analyze.process-screening",
259
+ ("Analyze", "Quality & SPC", "Process Screening..."),
260
+ "Quality",
261
+ "Screen many process columns for stability and capability.",
262
+ ("process screening", "stability", "capability", "spc"),
263
+ ),
264
+ HubCommandSpec(
265
+ "analyze.power",
266
+ ("Analyze", "Quality & SPC", "Power and Sample Size..."),
267
+ "Quality",
268
+ "Plan studies with power, sample size, and effect-size calculations.",
269
+ ("power", "sample size", "effect size"),
270
+ ),
271
+ HubCommandSpec(
272
+ "doe.custom",
273
+ ("DOE", "Custom Design..."),
274
+ "DOE",
275
+ "Build a custom experimental design for your factors and constraints.",
276
+ ("doe", "design", "experiment", "custom"),
277
+ ),
278
+ HubCommandSpec(
279
+ "doe.full-factorial",
280
+ ("DOE", "Full Factorial Design..."),
281
+ "DOE",
282
+ "Create a full factorial experiment.",
283
+ ("doe", "factorial", "experiment"),
284
+ ),
285
+ HubCommandSpec(
286
+ "doe.analyze",
287
+ ("DOE", "Analyze Design..."),
288
+ "DOE",
289
+ "Analyze a designed experiment and inspect effects.",
290
+ ("doe", "analyze", "effects", "model"),
291
+ ),
292
+ HubCommandSpec(
293
+ "doe.bayesian-optimization",
294
+ ("DOE", "Bayesian Optimization..."),
295
+ "DOE",
296
+ "Optimize a response with Bayesian adaptive experimentation.",
297
+ ("bayesian", "optimization", "response"),
298
+ ),
299
+ HubCommandSpec(
300
+ "graph.builder",
301
+ ("Graph", "Graph Builder..."),
302
+ "Graphs",
303
+ "Create an interactive graph by assigning columns to roles.",
304
+ ("graph", "chart", "plot", "builder"),
305
+ ),
306
+ HubCommandSpec(
307
+ "graph.histogram",
308
+ ("Graph", "Basic", "Histogram..."),
309
+ "Graphs",
310
+ "Show the distribution of a numeric column.",
311
+ ("histogram", "distribution", "plot"),
312
+ ),
313
+ HubCommandSpec(
314
+ "graph.box",
315
+ ("Graph", "Basic", "Box Plot..."),
316
+ "Graphs",
317
+ "Compare distributions with box plots.",
318
+ ("box plot", "distribution", "groups"),
319
+ ),
320
+ HubCommandSpec(
321
+ "graph.scatter",
322
+ ("Graph", "XY & Time", "Scatter Plot..."),
323
+ "Graphs",
324
+ "Plot the relationship between two numeric columns.",
325
+ ("scatter", "xy", "relationship"),
326
+ ),
327
+ HubCommandSpec(
328
+ "graph.heatmap",
329
+ ("Graph", "Multivariate", "Correlation Heatmap..."),
330
+ "Graphs",
331
+ "Visualize a correlation matrix as a heatmap.",
332
+ ("heatmap", "correlation", "matrix"),
333
+ ),
334
+ HubCommandSpec(
335
+ "tools.report-composer",
336
+ ("Tools", "Report Composer..."),
337
+ "Reports",
338
+ "Assemble saved reports into a shareable document.",
339
+ ("report", "compose", "export", "document"),
340
+ ),
341
+ HubCommandSpec(
342
+ "tools.python-console",
343
+ ("Tools", "Python Console"),
344
+ "Scripting",
345
+ "Open the embedded Python console.",
346
+ ("python", "console", "script", "api"),
347
+ ),
348
+ HubCommandSpec(
349
+ "tools.scripts",
350
+ ("Tools", "Scripts"),
351
+ "Scripting",
352
+ "Open the project script editor.",
353
+ ("script", "python", "automation"),
354
+ ),
355
+ HubCommandSpec(
356
+ "view.command-palette",
357
+ ("View", "Command Palette..."),
358
+ "Workspace",
359
+ "Search every command by name and shortcut.",
360
+ ("command", "palette", "search", "shortcut"),
361
+ ),
362
+ )
363
+
364
+ _SPEC_BY_PATH = {spec.path: spec for spec in SPECS}
365
+
366
+
367
+ def _traverse(menu, path: tuple[str, ...], output: list[tuple[tuple[str, ...], QAction]]) -> None:
368
+ for action in menu.actions():
369
+ if action.isSeparator() or not action.text():
370
+ continue
371
+ label = normalize_label(action.text())
372
+ child = path + (label,)
373
+ submenu = action.menu()
374
+ if submenu is not None:
375
+ _traverse(submenu, child, output)
376
+ else:
377
+ output.append((child, action))
378
+
379
+
380
+ def _category_for(path: tuple[str, ...]) -> str:
381
+ top = path[0]
382
+ if top == "Graph":
383
+ return "Graphs"
384
+ if top == "DOE":
385
+ return "DOE"
386
+ if top == "Tools":
387
+ if any(part in {"Python Console", "Scripts", "Analysis Journal..."} for part in path):
388
+ return "Scripting"
389
+ return "Reports"
390
+ if top == "Analyze":
391
+ section = path[1] if len(path) > 1 else ""
392
+ if section in {"Summary & Distributions"}:
393
+ return "Data"
394
+ if section in {"Compare Means", "Contingency"}:
395
+ return "Compare"
396
+ if section in {"Quality & SPC"}:
397
+ return "Quality"
398
+ return "Model"
399
+ if top in {"File", "Tables"}:
400
+ return "Data"
401
+ return "Workspace"
402
+
403
+
404
+ def build_catalog(menu_bar) -> dict[str, HubCommand]:
405
+ commands: dict[str, HubCommand] = {}
406
+ path_to_spec = dict(_SPEC_BY_PATH)
407
+
408
+ leaves: list[tuple[tuple[str, ...], QAction]] = []
409
+ for top_action in menu_bar.actions():
410
+ menu = top_action.menu()
411
+ if menu is None:
412
+ continue
413
+ top = normalize_label(top_action.text())
414
+ if top in {"Analyze", "Graph", "DOE", "Tools"}:
415
+ _traverse(menu, (top,), leaves)
416
+
417
+ for path, action in leaves:
418
+ if action.isSeparator():
419
+ continue
420
+ spec = path_to_spec.get(path)
421
+ if spec is None:
422
+ title = normalize_label(action.text()).removesuffix("...").strip()
423
+ command_id = f"cmd.{_slug(' '.join(path))}"
424
+ commands[command_id] = HubCommand(
425
+ id=command_id,
426
+ title=title,
427
+ category=_category_for(path),
428
+ description=" > ".join(path[1:]),
429
+ path=path,
430
+ action=action,
431
+ keywords=tuple(part.lower() for part in path),
432
+ )
433
+ else:
434
+ title = normalize_label(action.text()).removesuffix("...").strip()
435
+ commands[spec.id] = HubCommand(
436
+ id=spec.id,
437
+ title=title,
438
+ category=spec.category,
439
+ description=spec.description,
440
+ path=path,
441
+ action=action,
442
+ keywords=spec.keywords,
443
+ )
444
+
445
+ for spec in SPECS:
446
+ if spec.id in commands:
447
+ continue
448
+ action = find_action(menu_bar, spec.path)
449
+ if action is None:
450
+ continue
451
+ commands[spec.id] = HubCommand(
452
+ id=spec.id,
453
+ title=normalize_label(action.text()).removesuffix("...").strip(),
454
+ category=spec.category,
455
+ description=spec.description,
456
+ path=spec.path,
457
+ action=action,
458
+ keywords=spec.keywords,
459
+ )
460
+ return commands
@@ -0,0 +1,55 @@
1
+ from __future__ import annotations
2
+
3
+ from PySide6.QtCore import Qt
4
+ from PySide6.QtWidgets import QLineEdit, QListWidget, QListWidgetItem, QVBoxLayout, QWidget
5
+
6
+ from statstudio.ui.dialogs.window import IndependentDialog
7
+
8
+
9
+ class CommandPaletteDialog(IndependentDialog):
10
+ def __init__(self, actions, parent: QWidget | None = None) -> None:
11
+ super().__init__(parent)
12
+ self.setWindowTitle("Command Palette")
13
+ self.resize(620, 400)
14
+ self.actions = [action for action in actions if action.text() and not action.isSeparator()]
15
+ layout = QVBoxLayout(self)
16
+ self.search = QLineEdit()
17
+ self.search.setPlaceholderText("Type a command, menu path, or shortcut…")
18
+ self.search.setClearButtonEnabled(True)
19
+ self.search.textChanged.connect(self._filter)
20
+ layout.addWidget(self.search)
21
+ self.list = QListWidget()
22
+ self.list.setIconSize(self.list.iconSize())
23
+ self.list.itemActivated.connect(self._run)
24
+ layout.addWidget(self.list, 1)
25
+ self._filter("")
26
+ self.search.setFocus()
27
+
28
+ def _filter(self, text: str) -> None:
29
+ tokens = [token for token in text.strip().lower().split() if token]
30
+ self.list.clear()
31
+ for action in self.actions:
32
+ label = action.text()
33
+ shortcut = action.shortcut().toString()
34
+ path = str(action.property("menu_path") or "")
35
+ haystack = f"{label} {shortcut} {path}".lower()
36
+ if tokens and not all(token in haystack for token in tokens):
37
+ continue
38
+ suffix = f" {shortcut}" if shortcut else ""
39
+ item = QListWidgetItem(f"{label}{suffix}")
40
+ if path:
41
+ item.setToolTip(path)
42
+ item.setData(Qt.ItemDataRole.UserRole + 1, path)
43
+ item.setData(Qt.ItemDataRole.UserRole, action)
44
+ icon = action.icon()
45
+ if not icon.isNull():
46
+ item.setIcon(icon)
47
+ self.list.addItem(item)
48
+ if self.list.count():
49
+ self.list.setCurrentRow(0)
50
+
51
+ def _run(self, item: QListWidgetItem) -> None:
52
+ action = item.data(Qt.ItemDataRole.UserRole)
53
+ self.accept()
54
+ if action is not None:
55
+ action.trigger()