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,184 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
_MODULES: dict[str, str] = {
|
|
7
|
+
"ANOVADialog": "stats_dialogs",
|
|
8
|
+
"AppendDialog": "table_dialogs",
|
|
9
|
+
"BayesianANOVADialog": "bayesian_dialogs",
|
|
10
|
+
"BayesianLinearRegressionDialog": "bayesian_dialogs",
|
|
11
|
+
"BayesianLogisticRegressionDialog": "bayesian_dialogs",
|
|
12
|
+
"BayesianOptimizationDialog": "bayesian_optimization_dialog",
|
|
13
|
+
"BayesianTwoSampleDialog": "bayesian_dialogs",
|
|
14
|
+
"ChiSquareDialog": "stats_dialogs",
|
|
15
|
+
"ColumnManagerDialog": "table_dialogs",
|
|
16
|
+
"ColumnPropertiesDialog": "table_dialogs",
|
|
17
|
+
"ColumnSwitcherDialog": "plot_dialog",
|
|
18
|
+
"CompetingRiskDialog": "extended_dialogs",
|
|
19
|
+
"ContingencyDialog": "extended_dialogs",
|
|
20
|
+
"CorrelationDialog": "stats_dialogs",
|
|
21
|
+
"CovarianceDialog": "stats_dialogs",
|
|
22
|
+
"CSVOptionsDialog": "table_dialogs",
|
|
23
|
+
"CustomDesignDialog": "custom_doe_dialog",
|
|
24
|
+
"DescriptiveDialog": "stats_dialogs",
|
|
25
|
+
"DistributionIDDialog": "advanced_dialogs",
|
|
26
|
+
"DistributionSummaryDialog": "extended_dialogs",
|
|
27
|
+
"DistributionDialog": "stats_dialogs",
|
|
28
|
+
"DOEAnalysisDialog": "stats_dialogs",
|
|
29
|
+
"DOEDesignDialog": "doe_dialogs",
|
|
30
|
+
"DuplicateTableDialog": "table_dialogs",
|
|
31
|
+
"EquivalentTestDialog": "advanced_dialogs",
|
|
32
|
+
"FilterDialog": "table_dialogs",
|
|
33
|
+
"FindReplaceDialog": "table_dialogs",
|
|
34
|
+
"FitYByXDialog": "extended_dialogs",
|
|
35
|
+
"ForecastDialog": "extended_dialogs",
|
|
36
|
+
"FormulaDialog": "table_dialogs",
|
|
37
|
+
"FrequencyDialog": "stats_dialogs",
|
|
38
|
+
"FriedmanDialog": "advanced_dialogs",
|
|
39
|
+
"GroupSummaryDialog": "stats_dialogs",
|
|
40
|
+
"ImportPreviewDialog": "table_dialogs",
|
|
41
|
+
"JoinDialog": "table_dialogs",
|
|
42
|
+
"MannWhitneyDialog": "stats_dialogs",
|
|
43
|
+
"MissingDialog": "table_dialogs",
|
|
44
|
+
"MoodMedianDialog": "advanced_dialogs",
|
|
45
|
+
"MultiResponseDialog": "advanced_dialogs",
|
|
46
|
+
"MultivariateDialog": "stats_dialogs",
|
|
47
|
+
"NewColumnDialog": "table_dialogs",
|
|
48
|
+
"NewTableDialog": "table_dialogs",
|
|
49
|
+
"NormalityDialog": "stats_dialogs",
|
|
50
|
+
"ODBCDialog": "odbc_dialog",
|
|
51
|
+
"PasteDialog": "table_dialogs",
|
|
52
|
+
"PlotDialog": "plot_dialog",
|
|
53
|
+
"PostHocDialog": "extended_dialogs",
|
|
54
|
+
"PowerDialog": "stats_dialogs",
|
|
55
|
+
"PredictiveDialog": "extended_dialogs",
|
|
56
|
+
"ProcessScreeningDialog": "advanced_dialogs",
|
|
57
|
+
"ProfilerDialog": "advanced_dialogs",
|
|
58
|
+
"ProportionDialog": "stats_dialogs",
|
|
59
|
+
"QualityDialog": "stats_dialogs",
|
|
60
|
+
"RecodeDialog": "table_dialogs",
|
|
61
|
+
"RegressionDialog": "stats_dialogs",
|
|
62
|
+
"RegressionMultiResponseDialog": "stats_dialogs",
|
|
63
|
+
"RegressionProfilerDialog": "stats_dialogs",
|
|
64
|
+
"ReliabilityDialog": "extended_dialogs",
|
|
65
|
+
"RenameTableDialog": "table_dialogs",
|
|
66
|
+
"ReportComposerDialog": "report_composer",
|
|
67
|
+
"RunsTestDialog": "advanced_dialogs",
|
|
68
|
+
"SignTestDialog": "advanced_dialogs",
|
|
69
|
+
"SimulationDialog": "advanced_dialogs",
|
|
70
|
+
"SortDialog": "table_dialogs",
|
|
71
|
+
"SplitDialog": "table_dialogs",
|
|
72
|
+
"StackDialog": "table_dialogs",
|
|
73
|
+
"StandardizeDialog": "table_dialogs",
|
|
74
|
+
"STLDialog": "extended_dialogs",
|
|
75
|
+
"SubsetColumnsDialog": "table_dialogs",
|
|
76
|
+
"SurvivalDialog": "stats_dialogs",
|
|
77
|
+
"TTestDialog": "stats_dialogs",
|
|
78
|
+
"TimeSeriesDialog": "stats_dialogs",
|
|
79
|
+
"ToleranceDialog": "advanced_dialogs",
|
|
80
|
+
"TwoWayANOVADialog": "extended_dialogs",
|
|
81
|
+
"UnstackDialog": "table_dialogs",
|
|
82
|
+
"WilcoxonDialog": "stats_dialogs",
|
|
83
|
+
"WilcoxonOneDialog": "advanced_dialogs",
|
|
84
|
+
"ZeroFailureReliabilityDialog": "extended_dialogs",
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class LazyDialog:
|
|
89
|
+
"""Resolve a dialog class on first use without importing heavy stats modules."""
|
|
90
|
+
|
|
91
|
+
def __init__(self, name: str) -> None:
|
|
92
|
+
self.name = name
|
|
93
|
+
|
|
94
|
+
def load(self):
|
|
95
|
+
module = importlib.import_module(f"statstudio.ui.dialogs.{_MODULES[self.name]}")
|
|
96
|
+
return getattr(module, self.name)
|
|
97
|
+
|
|
98
|
+
def __call__(self, *args: Any, **kwargs: Any):
|
|
99
|
+
return self.load()(*args, **kwargs)
|
|
100
|
+
|
|
101
|
+
def __repr__(self) -> str:
|
|
102
|
+
return f"LazyDialog({self.name!r})"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
ANOVADialog = LazyDialog("ANOVADialog")
|
|
106
|
+
AppendDialog = LazyDialog("AppendDialog")
|
|
107
|
+
BayesianANOVADialog = LazyDialog("BayesianANOVADialog")
|
|
108
|
+
BayesianLinearRegressionDialog = LazyDialog("BayesianLinearRegressionDialog")
|
|
109
|
+
BayesianLogisticRegressionDialog = LazyDialog("BayesianLogisticRegressionDialog")
|
|
110
|
+
BayesianOptimizationDialog = LazyDialog("BayesianOptimizationDialog")
|
|
111
|
+
BayesianTwoSampleDialog = LazyDialog("BayesianTwoSampleDialog")
|
|
112
|
+
ChiSquareDialog = LazyDialog("ChiSquareDialog")
|
|
113
|
+
ColumnManagerDialog = LazyDialog("ColumnManagerDialog")
|
|
114
|
+
ColumnPropertiesDialog = LazyDialog("ColumnPropertiesDialog")
|
|
115
|
+
ColumnSwitcherDialog = LazyDialog("ColumnSwitcherDialog")
|
|
116
|
+
CompetingRiskDialog = LazyDialog("CompetingRiskDialog")
|
|
117
|
+
ContingencyDialog = LazyDialog("ContingencyDialog")
|
|
118
|
+
CorrelationDialog = LazyDialog("CorrelationDialog")
|
|
119
|
+
CovarianceDialog = LazyDialog("CovarianceDialog")
|
|
120
|
+
CSVOptionsDialog = LazyDialog("CSVOptionsDialog")
|
|
121
|
+
CustomDesignDialog = LazyDialog("CustomDesignDialog")
|
|
122
|
+
DescriptiveDialog = LazyDialog("DescriptiveDialog")
|
|
123
|
+
DistributionIDDialog = LazyDialog("DistributionIDDialog")
|
|
124
|
+
DistributionSummaryDialog = LazyDialog("DistributionSummaryDialog")
|
|
125
|
+
DistributionDialog = LazyDialog("DistributionDialog")
|
|
126
|
+
DOEAnalysisDialog = LazyDialog("DOEAnalysisDialog")
|
|
127
|
+
DOEDesignDialog = LazyDialog("DOEDesignDialog")
|
|
128
|
+
DuplicateTableDialog = LazyDialog("DuplicateTableDialog")
|
|
129
|
+
EquivalentTestDialog = LazyDialog("EquivalentTestDialog")
|
|
130
|
+
FilterDialog = LazyDialog("FilterDialog")
|
|
131
|
+
FindReplaceDialog = LazyDialog("FindReplaceDialog")
|
|
132
|
+
FitYByXDialog = LazyDialog("FitYByXDialog")
|
|
133
|
+
ForecastDialog = LazyDialog("ForecastDialog")
|
|
134
|
+
FormulaDialog = LazyDialog("FormulaDialog")
|
|
135
|
+
FrequencyDialog = LazyDialog("FrequencyDialog")
|
|
136
|
+
FriedmanDialog = LazyDialog("FriedmanDialog")
|
|
137
|
+
GroupSummaryDialog = LazyDialog("GroupSummaryDialog")
|
|
138
|
+
ImportPreviewDialog = LazyDialog("ImportPreviewDialog")
|
|
139
|
+
JoinDialog = LazyDialog("JoinDialog")
|
|
140
|
+
MannWhitneyDialog = LazyDialog("MannWhitneyDialog")
|
|
141
|
+
MissingDialog = LazyDialog("MissingDialog")
|
|
142
|
+
MoodMedianDialog = LazyDialog("MoodMedianDialog")
|
|
143
|
+
MultiResponseDialog = LazyDialog("MultiResponseDialog")
|
|
144
|
+
MultivariateDialog = LazyDialog("MultivariateDialog")
|
|
145
|
+
NewColumnDialog = LazyDialog("NewColumnDialog")
|
|
146
|
+
NewTableDialog = LazyDialog("NewTableDialog")
|
|
147
|
+
NormalityDialog = LazyDialog("NormalityDialog")
|
|
148
|
+
ODBCDialog = LazyDialog("ODBCDialog")
|
|
149
|
+
PasteDialog = LazyDialog("PasteDialog")
|
|
150
|
+
PlotDialog = LazyDialog("PlotDialog")
|
|
151
|
+
PostHocDialog = LazyDialog("PostHocDialog")
|
|
152
|
+
PowerDialog = LazyDialog("PowerDialog")
|
|
153
|
+
PredictiveDialog = LazyDialog("PredictiveDialog")
|
|
154
|
+
ProcessScreeningDialog = LazyDialog("ProcessScreeningDialog")
|
|
155
|
+
ProfilerDialog = LazyDialog("ProfilerDialog")
|
|
156
|
+
ProportionDialog = LazyDialog("ProportionDialog")
|
|
157
|
+
QualityDialog = LazyDialog("QualityDialog")
|
|
158
|
+
RecodeDialog = LazyDialog("RecodeDialog")
|
|
159
|
+
RegressionDialog = LazyDialog("RegressionDialog")
|
|
160
|
+
RegressionMultiResponseDialog = LazyDialog("RegressionMultiResponseDialog")
|
|
161
|
+
RegressionProfilerDialog = LazyDialog("RegressionProfilerDialog")
|
|
162
|
+
ReliabilityDialog = LazyDialog("ReliabilityDialog")
|
|
163
|
+
RenameTableDialog = LazyDialog("RenameTableDialog")
|
|
164
|
+
ReportComposerDialog = LazyDialog("ReportComposerDialog")
|
|
165
|
+
RunsTestDialog = LazyDialog("RunsTestDialog")
|
|
166
|
+
SignTestDialog = LazyDialog("SignTestDialog")
|
|
167
|
+
SimulationDialog = LazyDialog("SimulationDialog")
|
|
168
|
+
SortDialog = LazyDialog("SortDialog")
|
|
169
|
+
SplitDialog = LazyDialog("SplitDialog")
|
|
170
|
+
StackDialog = LazyDialog("StackDialog")
|
|
171
|
+
StandardizeDialog = LazyDialog("StandardizeDialog")
|
|
172
|
+
STLDialog = LazyDialog("STLDialog")
|
|
173
|
+
SubsetColumnsDialog = LazyDialog("SubsetColumnsDialog")
|
|
174
|
+
SurvivalDialog = LazyDialog("SurvivalDialog")
|
|
175
|
+
TTestDialog = LazyDialog("TTestDialog")
|
|
176
|
+
TimeSeriesDialog = LazyDialog("TimeSeriesDialog")
|
|
177
|
+
ToleranceDialog = LazyDialog("ToleranceDialog")
|
|
178
|
+
TwoWayANOVADialog = LazyDialog("TwoWayANOVADialog")
|
|
179
|
+
UnstackDialog = LazyDialog("UnstackDialog")
|
|
180
|
+
WilcoxonDialog = LazyDialog("WilcoxonDialog")
|
|
181
|
+
WilcoxonOneDialog = LazyDialog("WilcoxonOneDialog")
|
|
182
|
+
ZeroFailureReliabilityDialog = LazyDialog("ZeroFailureReliabilityDialog")
|
|
183
|
+
|
|
184
|
+
__all__ = sorted(_MODULES)
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
from PySide6.QtCore import Qt
|
|
5
|
+
from PySide6.QtWidgets import (
|
|
6
|
+
QCheckBox,
|
|
7
|
+
QComboBox,
|
|
8
|
+
QDialogButtonBox,
|
|
9
|
+
QFormLayout,
|
|
10
|
+
QHBoxLayout,
|
|
11
|
+
QLabel,
|
|
12
|
+
QLineEdit,
|
|
13
|
+
QListWidget,
|
|
14
|
+
QMessageBox,
|
|
15
|
+
QPlainTextEdit,
|
|
16
|
+
QPushButton,
|
|
17
|
+
QSpinBox,
|
|
18
|
+
QTableWidget,
|
|
19
|
+
QTableWidgetItem,
|
|
20
|
+
QTabWidget,
|
|
21
|
+
QVBoxLayout,
|
|
22
|
+
QWidget,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from statstudio.core.project import Project
|
|
26
|
+
from statstudio.io import odbc
|
|
27
|
+
from statstudio.ui.dialogs.window import IndependentDialog
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ODBCDialog(IndependentDialog):
|
|
31
|
+
def __init__(self, project: Project, parent=None) -> None:
|
|
32
|
+
super().__init__(parent)
|
|
33
|
+
self.project = project
|
|
34
|
+
self.result = None
|
|
35
|
+
self.import_profile = None
|
|
36
|
+
self.import_query = ""
|
|
37
|
+
self.setWindowTitle("Import from ODBC")
|
|
38
|
+
self.resize(800, 650)
|
|
39
|
+
layout = QVBoxLayout(self)
|
|
40
|
+
tabs = QTabWidget()
|
|
41
|
+
layout.addWidget(tabs, 1)
|
|
42
|
+
|
|
43
|
+
connection_tab = QWidget()
|
|
44
|
+
connection_layout = QVBoxLayout(connection_tab)
|
|
45
|
+
form = QFormLayout()
|
|
46
|
+
connection_layout.addLayout(form)
|
|
47
|
+
self.saved_combo = QComboBox()
|
|
48
|
+
self.saved_combo.addItem("(new connection)", None)
|
|
49
|
+
for saved in project.connections:
|
|
50
|
+
if saved.get("name"):
|
|
51
|
+
self.saved_combo.addItem(saved["name"], saved["name"])
|
|
52
|
+
form.addRow("Saved connection", self.saved_combo)
|
|
53
|
+
self.name_edit = QLineEdit("New Connection")
|
|
54
|
+
form.addRow("Connection name", self.name_edit)
|
|
55
|
+
self.use_dsn_check = QCheckBox("Use a DSN")
|
|
56
|
+
self.use_dsn_check.setChecked(True)
|
|
57
|
+
form.addRow("", self.use_dsn_check)
|
|
58
|
+
self.dsn_combo = QComboBox()
|
|
59
|
+
form.addRow("DSN", self.dsn_combo)
|
|
60
|
+
self.driver_combo = QComboBox()
|
|
61
|
+
form.addRow("Driver", self.driver_combo)
|
|
62
|
+
self.server_edit = QLineEdit()
|
|
63
|
+
self.database_edit = QLineEdit()
|
|
64
|
+
self.user_edit = QLineEdit()
|
|
65
|
+
self.password_edit = QLineEdit()
|
|
66
|
+
self.password_edit.setEchoMode(QLineEdit.EchoMode.Password)
|
|
67
|
+
self.trusted_check = QCheckBox("Trusted connection")
|
|
68
|
+
self.extra_edit = QLineEdit()
|
|
69
|
+
self.remember_check = QCheckBox("Remember password in OS keyring")
|
|
70
|
+
for label, widget in [
|
|
71
|
+
("Server", self.server_edit),
|
|
72
|
+
("Database", self.database_edit),
|
|
73
|
+
("Username", self.user_edit),
|
|
74
|
+
("Password", self.password_edit),
|
|
75
|
+
("", self.trusted_check),
|
|
76
|
+
("Extra options", self.extra_edit),
|
|
77
|
+
("", self.remember_check),
|
|
78
|
+
]:
|
|
79
|
+
form.addRow(label, widget)
|
|
80
|
+
button_row = QHBoxLayout()
|
|
81
|
+
test_button = QPushButton("Test connection")
|
|
82
|
+
test_button.clicked.connect(self._test)
|
|
83
|
+
refresh_button = QPushButton("Refresh drivers / DSNs")
|
|
84
|
+
refresh_button.clicked.connect(self._refresh_sources)
|
|
85
|
+
button_row.addWidget(test_button)
|
|
86
|
+
button_row.addWidget(refresh_button)
|
|
87
|
+
button_row.addStretch(1)
|
|
88
|
+
connection_layout.addLayout(button_row)
|
|
89
|
+
self.connection_status = QLabel("")
|
|
90
|
+
self.connection_status.setWordWrap(True)
|
|
91
|
+
connection_layout.addWidget(self.connection_status)
|
|
92
|
+
tabs.addTab(connection_tab, "Connection")
|
|
93
|
+
|
|
94
|
+
browse_tab = QWidget()
|
|
95
|
+
browse_layout = QVBoxLayout(browse_tab)
|
|
96
|
+
browse_row = QHBoxLayout()
|
|
97
|
+
self.schema_combo = QComboBox()
|
|
98
|
+
self.schema_combo.currentTextChanged.connect(self._filter_table_list)
|
|
99
|
+
browse_row.addWidget(QLabel("Schema"))
|
|
100
|
+
browse_row.addWidget(self.schema_combo)
|
|
101
|
+
browse_button = QPushButton("Load tables")
|
|
102
|
+
browse_button.clicked.connect(self._load_tables)
|
|
103
|
+
browse_row.addWidget(browse_button)
|
|
104
|
+
browse_row.addStretch(1)
|
|
105
|
+
browse_layout.addLayout(browse_row)
|
|
106
|
+
self.table_list = QListWidget()
|
|
107
|
+
self.table_list.itemDoubleClicked.connect(self._choose_table)
|
|
108
|
+
browse_layout.addWidget(self.table_list, 1)
|
|
109
|
+
use_table_button = QPushButton("Use selected table in SQL")
|
|
110
|
+
use_table_button.clicked.connect(lambda: self._choose_table(self.table_list.currentItem()))
|
|
111
|
+
browse_layout.addWidget(use_table_button)
|
|
112
|
+
tabs.addTab(browse_tab, "Browse")
|
|
113
|
+
|
|
114
|
+
query_tab = QWidget()
|
|
115
|
+
query_layout = QVBoxLayout(query_tab)
|
|
116
|
+
self._tables: list[dict[str, str]] = []
|
|
117
|
+
self.query_edit = QPlainTextEdit()
|
|
118
|
+
self.query_edit.setPlaceholderText("SELECT * FROM schema.table")
|
|
119
|
+
self.query_edit.setPlainText("SELECT 1")
|
|
120
|
+
query_layout.addWidget(self.query_edit, 1)
|
|
121
|
+
preview_row = QHBoxLayout()
|
|
122
|
+
preview_row.addWidget(QLabel("Preview rows"))
|
|
123
|
+
self.limit_spin = QSpinBox()
|
|
124
|
+
self.limit_spin.setRange(1, 10000)
|
|
125
|
+
self.limit_spin.setValue(100)
|
|
126
|
+
preview_row.addWidget(self.limit_spin)
|
|
127
|
+
preview_button = QPushButton("Preview query")
|
|
128
|
+
preview_button.clicked.connect(self._preview)
|
|
129
|
+
preview_row.addWidget(preview_button)
|
|
130
|
+
preview_row.addStretch(1)
|
|
131
|
+
query_layout.addLayout(preview_row)
|
|
132
|
+
self.preview_table = QTableWidget()
|
|
133
|
+
query_layout.addWidget(self.preview_table, 1)
|
|
134
|
+
tabs.addTab(query_tab, "SQL Query")
|
|
135
|
+
|
|
136
|
+
name_row = QHBoxLayout()
|
|
137
|
+
name_row.addWidget(QLabel("Imported table name"))
|
|
138
|
+
self.table_name_edit = QLineEdit("ODBC Query")
|
|
139
|
+
name_row.addWidget(self.table_name_edit, 1)
|
|
140
|
+
layout.addLayout(name_row)
|
|
141
|
+
|
|
142
|
+
self.buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
|
|
143
|
+
self.buttons.button(QDialogButtonBox.StandardButton.Ok).setText("Import")
|
|
144
|
+
self.buttons.accepted.connect(self._import)
|
|
145
|
+
self.buttons.rejected.connect(self.reject)
|
|
146
|
+
from statstudio.ui.dialogs.help_topics import add_help_button, install_context_help
|
|
147
|
+
|
|
148
|
+
add_help_button(self.buttons, self)
|
|
149
|
+
install_context_help(self)
|
|
150
|
+
layout.addWidget(self.buttons)
|
|
151
|
+
self._refresh_sources()
|
|
152
|
+
self.use_dsn_check.toggled.connect(self._toggle_dsn)
|
|
153
|
+
self.saved_combo.currentIndexChanged.connect(self._load_saved_profile)
|
|
154
|
+
self._toggle_dsn(self.use_dsn_check.isChecked())
|
|
155
|
+
|
|
156
|
+
def _load_saved_profile(self, index: int) -> None:
|
|
157
|
+
name = self.saved_combo.currentData()
|
|
158
|
+
if not name:
|
|
159
|
+
return
|
|
160
|
+
payload = next((item for item in self.project.connections if item.get("name") == name), None)
|
|
161
|
+
if not payload:
|
|
162
|
+
return
|
|
163
|
+
profile = odbc.OdbcProfile.from_dict(payload)
|
|
164
|
+
self.name_edit.setText(profile.name)
|
|
165
|
+
self.use_dsn_check.setChecked(profile.use_dsn)
|
|
166
|
+
if profile.dsn:
|
|
167
|
+
dsn_index = self.dsn_combo.findData(profile.dsn)
|
|
168
|
+
if dsn_index >= 0:
|
|
169
|
+
self.dsn_combo.setCurrentIndex(dsn_index)
|
|
170
|
+
if profile.driver:
|
|
171
|
+
driver_index = self.driver_combo.findText(profile.driver)
|
|
172
|
+
if driver_index >= 0:
|
|
173
|
+
self.driver_combo.setCurrentIndex(driver_index)
|
|
174
|
+
self.server_edit.setText(profile.server)
|
|
175
|
+
self.database_edit.setText(profile.database)
|
|
176
|
+
self.user_edit.setText(profile.username)
|
|
177
|
+
self.password_edit.setText(profile.password)
|
|
178
|
+
self.trusted_check.setChecked(profile.trusted_connection)
|
|
179
|
+
self.extra_edit.setText(profile.extra)
|
|
180
|
+
self.remember_check.setChecked(profile.remember_password)
|
|
181
|
+
self._toggle_dsn(profile.use_dsn)
|
|
182
|
+
|
|
183
|
+
def _toggle_dsn(self, use_dsn: bool) -> None:
|
|
184
|
+
self.dsn_combo.setEnabled(use_dsn)
|
|
185
|
+
for widget in (self.driver_combo, self.server_edit, self.database_edit):
|
|
186
|
+
widget.setEnabled(not use_dsn)
|
|
187
|
+
|
|
188
|
+
def _refresh_sources(self) -> None:
|
|
189
|
+
drivers = odbc.available_drivers()
|
|
190
|
+
dsns = odbc.available_dsns()
|
|
191
|
+
previous_driver = self.driver_combo.currentText()
|
|
192
|
+
previous_dsn = self.dsn_combo.currentData()
|
|
193
|
+
self.driver_combo.clear()
|
|
194
|
+
self.driver_combo.addItems(drivers)
|
|
195
|
+
self.dsn_combo.clear()
|
|
196
|
+
for name, driver in dsns.items():
|
|
197
|
+
self.dsn_combo.addItem(f"{name} ({driver})", name)
|
|
198
|
+
if previous_driver in drivers:
|
|
199
|
+
self.driver_combo.setCurrentText(previous_driver)
|
|
200
|
+
if previous_dsn in dsns:
|
|
201
|
+
index = self.dsn_combo.findData(previous_dsn)
|
|
202
|
+
if index >= 0:
|
|
203
|
+
self.dsn_combo.setCurrentIndex(index)
|
|
204
|
+
if not drivers and not dsns:
|
|
205
|
+
self.connection_status.setText(
|
|
206
|
+
"No ODBC drivers or DSNs were detected. Install unixODBC and a database driver "
|
|
207
|
+
"(for example PostgreSQL, MySQL, or SQLite ODBC), then refresh."
|
|
208
|
+
)
|
|
209
|
+
self.connection_status.setStyleSheet("color:#a33;")
|
|
210
|
+
else:
|
|
211
|
+
self.connection_status.setText(f"{len(drivers)} driver(s), {len(dsns)} DSN(s) detected.")
|
|
212
|
+
self.connection_status.setStyleSheet("color:#2e7d32;")
|
|
213
|
+
|
|
214
|
+
def _profile(self) -> odbc.OdbcProfile:
|
|
215
|
+
return odbc.OdbcProfile(
|
|
216
|
+
name=self.name_edit.text().strip() or "Connection",
|
|
217
|
+
dsn=self.dsn_combo.currentData() or "",
|
|
218
|
+
driver=self.driver_combo.currentText(),
|
|
219
|
+
server=self.server_edit.text().strip(),
|
|
220
|
+
database=self.database_edit.text().strip(),
|
|
221
|
+
username=self.user_edit.text().strip(),
|
|
222
|
+
password=self.password_edit.text(),
|
|
223
|
+
trusted_connection=self.trusted_check.isChecked(),
|
|
224
|
+
extra=self.extra_edit.text().strip(),
|
|
225
|
+
use_dsn=self.use_dsn_check.isChecked(),
|
|
226
|
+
remember_password=self.remember_check.isChecked(),
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
def _test(self) -> None:
|
|
230
|
+
try:
|
|
231
|
+
ok, message = odbc.test_connection(self._profile())
|
|
232
|
+
except Exception as exc:
|
|
233
|
+
ok, message = False, str(exc)
|
|
234
|
+
self.connection_status.setText(message)
|
|
235
|
+
self.connection_status.setStyleSheet("color:#2e7d32;" if ok else "color:#a33;")
|
|
236
|
+
|
|
237
|
+
def _load_tables(self) -> None:
|
|
238
|
+
try:
|
|
239
|
+
profile = self._profile()
|
|
240
|
+
tables = odbc.list_tables(profile)
|
|
241
|
+
except Exception as exc:
|
|
242
|
+
QMessageBox.critical(self, "ODBC", str(exc))
|
|
243
|
+
return
|
|
244
|
+
schemas = sorted({item["schema"] for item in tables if item["schema"]})
|
|
245
|
+
self._tables = tables
|
|
246
|
+
self.schema_combo.blockSignals(True)
|
|
247
|
+
self.schema_combo.clear()
|
|
248
|
+
self.schema_combo.addItem("")
|
|
249
|
+
self.schema_combo.addItems(schemas)
|
|
250
|
+
self.schema_combo.blockSignals(False)
|
|
251
|
+
self._filter_table_list("")
|
|
252
|
+
QMessageBox.information(self, "ODBC", f"Loaded {len(tables)} tables/views.")
|
|
253
|
+
|
|
254
|
+
def _filter_table_list(self, schema: str) -> None:
|
|
255
|
+
self.table_list.clear()
|
|
256
|
+
for item in self._tables:
|
|
257
|
+
if schema and item.get("schema") != schema:
|
|
258
|
+
continue
|
|
259
|
+
label = f"{item['schema']}.{item['table']}" if item.get("schema") else item["table"]
|
|
260
|
+
self.table_list.addItem(label)
|
|
261
|
+
self.table_list.item(self.table_list.count() - 1).setData(Qt.ItemDataRole.UserRole, item)
|
|
262
|
+
|
|
263
|
+
def _choose_table(self, item) -> None:
|
|
264
|
+
if item is None:
|
|
265
|
+
return
|
|
266
|
+
payload = item.data(Qt.ItemDataRole.UserRole) or {}
|
|
267
|
+
schema = str(payload.get("schema") or "")
|
|
268
|
+
table_name = str(payload.get("table") or item.text().split(".")[-1])
|
|
269
|
+
qualified = (
|
|
270
|
+
f"{odbc.quote_identifier(schema)}.{odbc.quote_identifier(table_name)}"
|
|
271
|
+
if schema
|
|
272
|
+
else odbc.quote_identifier(table_name)
|
|
273
|
+
)
|
|
274
|
+
self.query_edit.setPlainText(f"SELECT * FROM {qualified}")
|
|
275
|
+
self.table_name_edit.setText(table_name)
|
|
276
|
+
|
|
277
|
+
def _preview(self) -> None:
|
|
278
|
+
try:
|
|
279
|
+
frame = odbc.preview_query(self._profile(), self.query_edit.toPlainText(), self.limit_spin.value())
|
|
280
|
+
except Exception as exc:
|
|
281
|
+
QMessageBox.critical(self, "Preview failed", str(exc))
|
|
282
|
+
return
|
|
283
|
+
self.preview_table.clear()
|
|
284
|
+
self.preview_table.setRowCount(len(frame))
|
|
285
|
+
self.preview_table.setColumnCount(len(frame.columns))
|
|
286
|
+
self.preview_table.setHorizontalHeaderLabels([str(c) for c in frame.columns])
|
|
287
|
+
for row in range(len(frame)):
|
|
288
|
+
for col in range(len(frame.columns)):
|
|
289
|
+
value = frame.iat[row, col]
|
|
290
|
+
text = "" if pd.isna(value) else str(value)
|
|
291
|
+
self.preview_table.setItem(row, col, QTableWidgetItem(text))
|
|
292
|
+
self.preview_table.resizeColumnsToContents()
|
|
293
|
+
|
|
294
|
+
def _import(self) -> None:
|
|
295
|
+
query = self.query_edit.toPlainText().strip()
|
|
296
|
+
if not query:
|
|
297
|
+
QMessageBox.warning(self, "ODBC", "Enter a SQL query.")
|
|
298
|
+
return
|
|
299
|
+
profile = self._profile()
|
|
300
|
+
try:
|
|
301
|
+
table = odbc.import_query(profile, query, self.table_name_edit.text().strip() or "ODBC Query")
|
|
302
|
+
if profile.remember_password:
|
|
303
|
+
odbc.save_password(profile)
|
|
304
|
+
self.project.add_connection(profile.to_dict())
|
|
305
|
+
except Exception as exc:
|
|
306
|
+
QMessageBox.critical(self, "Import failed", str(exc))
|
|
307
|
+
return
|
|
308
|
+
self.result = table
|
|
309
|
+
self.import_profile = profile.to_dict()
|
|
310
|
+
self.import_query = query
|
|
311
|
+
self.accept()
|