robert 2.2.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.
- robert/__init__.py +9 -0
- robert/__main__.py +20 -0
- robert/_version.py +3 -0
- robert/api.py +646 -0
- robert/aqme.py +280 -0
- robert/argument_parser.py +98 -0
- robert/checkml.py +433 -0
- robert/checkml_score.py +50 -0
- robert/curate.py +217 -0
- robert/evaluate_bot_retrieval.py +125 -0
- robert/evaluate_bot_support.py +102 -0
- robert/evaluate_workflow_summaries.py +87 -0
- robert/export_bot_docs_knowledge.py +1632 -0
- robert/generate.py +249 -0
- robert/generate_utils.py +311 -0
- robert/gui_easyrob/__init__.py +0 -0
- robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
- robert/gui_easyrob/bot/__init__.py +47 -0
- robert/gui_easyrob/bot/answer_metadata.py +198 -0
- robert/gui_easyrob/bot/bot_context.py +679 -0
- robert/gui_easyrob/bot/bot_engine.py +1100 -0
- robert/gui_easyrob/bot/bot_panel.py +1231 -0
- robert/gui_easyrob/bot/bot_rag.py +1178 -0
- robert/gui_easyrob/bot/bot_window.py +39 -0
- robert/gui_easyrob/bot/bot_worker.py +149 -0
- robert/gui_easyrob/bot/credential_store.py +143 -0
- robert/gui_easyrob/bot/error_parser.py +105 -0
- robert/gui_easyrob/bot/evidence_policy.py +164 -0
- robert/gui_easyrob/bot/heuristics.py +859 -0
- robert/gui_easyrob/bot/icons.py +56 -0
- robert/gui_easyrob/bot/input_csv_audit.py +212 -0
- robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
- robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
- robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
- robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
- robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
- robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
- robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
- robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
- robert/gui_easyrob/bot/llm_providers.py +1573 -0
- robert/gui_easyrob/bot/online_docs.py +105 -0
- robert/gui_easyrob/bot/prompt_policy.py +575 -0
- robert/gui_easyrob/bot/question_intent.py +562 -0
- robert/gui_easyrob/bot/response_quality.py +104 -0
- robert/gui_easyrob/bot/result_insights.py +225 -0
- robert/gui_easyrob/bot/token_usage.py +75 -0
- robert/gui_easyrob/bot/workflow_results.py +1396 -0
- robert/gui_easyrob/checkml_launcher.py +15 -0
- robert/gui_easyrob/easyrob.py +29 -0
- robert/gui_easyrob/easyrob_launcher.py +113 -0
- robert/gui_easyrob/main/__init__.py +9 -0
- robert/gui_easyrob/main/window.py +5152 -0
- robert/gui_easyrob/result_navigation.py +14 -0
- robert/gui_easyrob/tabs/__init__.py +23 -0
- robert/gui_easyrob/tabs/advanced_options.py +370 -0
- robert/gui_easyrob/tabs/aqme.py +1234 -0
- robert/gui_easyrob/tabs/checkml.py +898 -0
- robert/gui_easyrob/tabs/images.py +427 -0
- robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
- robert/gui_easyrob/tabs/molssi.py +447 -0
- robert/gui_easyrob/tabs/predictions.py +484 -0
- robert/gui_easyrob/tabs/result_catalog.py +170 -0
- robert/gui_easyrob/tabs/results.py +490 -0
- robert/gui_easyrob/tabs/results_workspace.py +120 -0
- robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
- robert/gui_easyrob/test_bot_question_routing.py +383 -0
- robert/gui_easyrob/test_bot_result_analysis.py +356 -0
- robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
- robert/gui_easyrob/test_bot_ui_integration.py +278 -0
- robert/gui_easyrob/test_checkml_app_mode.py +124 -0
- robert/gui_easyrob/test_checkml_completion.py +57 -0
- robert/gui_easyrob/test_checkml_defaults.py +37 -0
- robert/gui_easyrob/test_checkml_result_summary.py +113 -0
- robert/gui_easyrob/test_checkml_web_mode.py +57 -0
- robert/gui_easyrob/test_dialog_layout.py +33 -0
- robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
- robert/gui_easyrob/test_molssi_auto.py +569 -0
- robert/gui_easyrob/test_tutorial_view.py +215 -0
- robert/gui_easyrob/tutorials/check_model.md +25 -0
- robert/gui_easyrob/tutorials/chemdraw.md +49 -0
- robert/gui_easyrob/tutorials/csv.md +53 -0
- robert/gui_easyrob/tutorials/descriptors.md +21 -0
- robert/gui_easyrob/tutorials/overview.md +65 -0
- robert/gui_easyrob/tutorials/predictions.md +25 -0
- robert/gui_easyrob/tutorials/robbot.md +29 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
- robert/gui_easyrob/utils/__init__.py +0 -0
- robert/gui_easyrob/utils/aqme_utils.py +238 -0
- robert/gui_easyrob/utils/molssi_utils.py +584 -0
- robert/gui_easyrob/utils/predictions_utils.py +985 -0
- robert/gui_easyrob/utils/utils_gui.py +738 -0
- robert/gui_easyrob/version.py +68 -0
- robert/gui_easyrob/web/app.css +484 -0
- robert/gui_easyrob/web/app.html +134 -0
- robert/gui_easyrob/web/app.js +764 -0
- robert/gui_easyrob/web/checkml_brand.png +0 -0
- robert/gui_easyrob/web/easyrob_background.gif +0 -0
- robert/gui_easyrob/web/easyrob_background.png +0 -0
- robert/gui_easyrob/web/images.css +89 -0
- robert/gui_easyrob/web/images.html +39 -0
- robert/gui_easyrob/web/images.js +101 -0
- robert/gui_easyrob/web/results.js +499 -0
- robert/gui_easyrob/web/robert_brand.png +0 -0
- robert/gui_easyrob/web_dialogs.py +64 -0
- robert/gui_easyrob/web_results.py +253 -0
- robert/gui_easyrob/web_shell.py +684 -0
- robert/gui_easyrob/workflow_progress.py +89 -0
- robert/gui_easyrob/workflow_run_lock.py +27 -0
- robert/icons/CheckML_icon.png +0 -0
- robert/icons/Robert_icon.png +0 -0
- robert/icons/Robert_logo.jpg +0 -0
- robert/icons/Robert_logo_transparent.png +0 -0
- robert/icons/documentation_icon.png +0 -0
- robert/icons/info_icon.png +0 -0
- robert/icons/pdf_icon.png +0 -0
- robert/icons/play_icon.png +0 -0
- robert/icons/stop_icon.png +0 -0
- robert/icons/youtube_icon.ico +0 -0
- robert/predict.py +193 -0
- robert/predict_utils.py +410 -0
- robert/report/CheckML_logo.jpg +0 -0
- robert/report/GENERATE.png +0 -0
- robert/report/Robert_icon.ico +0 -0
- robert/report/Robert_logo.jpg +0 -0
- robert/report/Robert_logo1.jpg +0 -0
- robert/report/abbrev.png +0 -0
- robert/report/adv_anal.png +0 -0
- robert/report/checkml_pass.svg +3 -0
- robert/report/checkml_unclear.svg +3 -0
- robert/report/checkml_warning.svg +3 -0
- robert/report/features.png +0 -0
- robert/report/outliers.png +0 -0
- robert/report/pred.png +0 -0
- robert/report/repro.png +0 -0
- robert/report/robust_x.png +0 -0
- robert/report/robust_y_high.png +0 -0
- robert/report/robust_y_low.png +0 -0
- robert/report/score.png +0 -0
- robert/report/score_0.jpg +0 -0
- robert/report/score_1.jpg +0 -0
- robert/report/score_10.jpg +0 -0
- robert/report/score_2.jpg +0 -0
- robert/report/score_3.jpg +0 -0
- robert/report/score_4.jpg +0 -0
- robert/report/score_5.jpg +0 -0
- robert/report/score_6.jpg +0 -0
- robert/report/score_7.jpg +0 -0
- robert/report/score_8.jpg +0 -0
- robert/report/score_9.jpg +0 -0
- robert/report/score_gray_0.jpg +0 -0
- robert/report/score_gray_1.jpg +0 -0
- robert/report/score_gray_10.jpg +0 -0
- robert/report/score_gray_2.jpg +0 -0
- robert/report/score_gray_3.jpg +0 -0
- robert/report/score_gray_4.jpg +0 -0
- robert/report/score_gray_5.jpg +0 -0
- robert/report/score_gray_6.jpg +0 -0
- robert/report/score_gray_7.jpg +0 -0
- robert/report/score_gray_8.jpg +0 -0
- robert/report/score_gray_9.jpg +0 -0
- robert/report/score_w_1_0.jpg +0 -0
- robert/report/score_w_1_1.jpg +0 -0
- robert/report/score_w_2_0.jpg +0 -0
- robert/report/score_w_2_1.jpg +0 -0
- robert/report/score_w_2_2.jpg +0 -0
- robert/report/score_w_2_gray_0.jpg +0 -0
- robert/report/score_w_2_gray_1.jpg +0 -0
- robert/report/score_w_2_gray_2.jpg +0 -0
- robert/report/score_w_3_0.jpg +0 -0
- robert/report/score_w_3_1.jpg +0 -0
- robert/report/score_w_3_2.jpg +0 -0
- robert/report/score_w_3_3.jpg +0 -0
- robert/report/score_w_4_0.jpg +0 -0
- robert/report/score_w_4_1.JPG +0 -0
- robert/report/score_w_4_2.jpg +0 -0
- robert/report/score_w_4_3.jpg +0 -0
- robert/report/score_w_4_4.jpg +0 -0
- robert/report/transpa.png +0 -0
- robert/report/y_distrib.png +0 -0
- robert/report.py +2880 -0
- robert/report_utils.py +2270 -0
- robert/robert.py +181 -0
- robert/utils.py +4763 -0
- robert/verify.py +606 -0
- robert-2.2.0.dist-info/METADATA +55 -0
- robert-2.2.0.dist-info/RECORD +261 -0
- robert-2.2.0.dist-info/WHEEL +5 -0
- robert-2.2.0.dist-info/entry_points.txt +3 -0
- robert-2.2.0.dist-info/licenses/LICENSE +21 -0
- robert-2.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core infrastructure and shared utilities for easyROB.
|
|
3
|
+
|
|
4
|
+
This module provides the foundational layer used across the entire GUI,
|
|
5
|
+
including Qt abstractions, process management, shared widgets, and
|
|
6
|
+
cross-cutting utilities.
|
|
7
|
+
|
|
8
|
+
Responsibilities:
|
|
9
|
+
- Centralize common Qt classes and third-party imports used throughout the GUI
|
|
10
|
+
- Provide reusable widgets (e.g., drag-and-drop inputs, combo boxes)
|
|
11
|
+
- Manage long-running subprocesses with real-time output streaming
|
|
12
|
+
- Offer utility helpers for file handling, CSV parsing, and asset resolution
|
|
13
|
+
- Handle platform-specific behavior (e.g., process control, frozen builds)
|
|
14
|
+
|
|
15
|
+
Architecture:
|
|
16
|
+
- Acts as a shared dependency layer for all GUI modules
|
|
17
|
+
- Exposes commonly used classes to reduce repetitive imports
|
|
18
|
+
- Integrates threading (QThread) and subprocess control for async workflows
|
|
19
|
+
- Provides asset resolution compatible with both development and frozen apps
|
|
20
|
+
|
|
21
|
+
Notes:
|
|
22
|
+
- This module intentionally groups cross-project infrastructure
|
|
23
|
+
- Domain-specific logic is delegated to specialized modules
|
|
24
|
+
(e.g., predictions_utils, molssi_utils, aqme_utils)
|
|
25
|
+
- Should remain focused on generic, reusable functionality
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
# ------------------------------------------------------------
|
|
30
|
+
# Standard library
|
|
31
|
+
# ------------------------------------------------------------
|
|
32
|
+
import csv
|
|
33
|
+
import glob
|
|
34
|
+
import html
|
|
35
|
+
import os
|
|
36
|
+
import platform
|
|
37
|
+
import re
|
|
38
|
+
import shlex
|
|
39
|
+
import shutil
|
|
40
|
+
import subprocess
|
|
41
|
+
import sys
|
|
42
|
+
import threading
|
|
43
|
+
from functools import partial
|
|
44
|
+
from io import BytesIO
|
|
45
|
+
from pathlib import Path
|
|
46
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
47
|
+
from importlib.resources import as_file, files
|
|
48
|
+
|
|
49
|
+
# ------------------------------------------------------------
|
|
50
|
+
# Third-party libraries
|
|
51
|
+
# ------------------------------------------------------------
|
|
52
|
+
import pandas as pd
|
|
53
|
+
import matplotlib.pyplot as plt
|
|
54
|
+
import psutil
|
|
55
|
+
import pymupdf as fitz
|
|
56
|
+
|
|
57
|
+
import rdkit
|
|
58
|
+
from rdkit import Chem
|
|
59
|
+
from rdkit.Chem import Draw, rdDepictor, rdFMCS
|
|
60
|
+
from rdkit.Chem.Draw import rdMolDraw2D
|
|
61
|
+
from rdkit.Chem.rdmolfiles import MolsFromCDXMLFile
|
|
62
|
+
from rdkit.Chem.rdmolops import GetMolFrags
|
|
63
|
+
|
|
64
|
+
from ansi2html import Ansi2HTMLConverter
|
|
65
|
+
|
|
66
|
+
# ------------------------------------------------------------
|
|
67
|
+
# Qt (PySide6)
|
|
68
|
+
# ------------------------------------------------------------
|
|
69
|
+
from PySide6.QtCore import (
|
|
70
|
+
QByteArray,
|
|
71
|
+
QEventLoop,
|
|
72
|
+
QAbstractTableModel,
|
|
73
|
+
QModelIndex,
|
|
74
|
+
QObject,
|
|
75
|
+
QRunnable,
|
|
76
|
+
QRect,
|
|
77
|
+
QSize,
|
|
78
|
+
QSortFilterProxyModel,
|
|
79
|
+
QThread,
|
|
80
|
+
QThreadPool,
|
|
81
|
+
QTimer,
|
|
82
|
+
Qt,
|
|
83
|
+
Signal,
|
|
84
|
+
Slot,
|
|
85
|
+
QUrl,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
from PySide6.QtGui import (
|
|
89
|
+
QDesktopServices,
|
|
90
|
+
QFontMetrics,
|
|
91
|
+
QIcon,
|
|
92
|
+
QImage,
|
|
93
|
+
QMouseEvent,
|
|
94
|
+
QPalette,
|
|
95
|
+
QPixmap,
|
|
96
|
+
QWheelEvent,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
from PySide6.QtWebEngineCore import QWebEngineDownloadRequest
|
|
100
|
+
from PySide6.QtWebEngineWidgets import QWebEngineView
|
|
101
|
+
|
|
102
|
+
from PySide6.QtWidgets import (
|
|
103
|
+
QApplication,
|
|
104
|
+
QButtonGroup,
|
|
105
|
+
QCheckBox,
|
|
106
|
+
QComboBox,
|
|
107
|
+
QDialog,
|
|
108
|
+
QFileDialog,
|
|
109
|
+
QFormLayout,
|
|
110
|
+
QFrame,
|
|
111
|
+
QGridLayout,
|
|
112
|
+
QGroupBox,
|
|
113
|
+
QHBoxLayout,
|
|
114
|
+
QHeaderView,
|
|
115
|
+
QInputDialog,
|
|
116
|
+
QLabel,
|
|
117
|
+
QLineEdit,
|
|
118
|
+
QListWidget,
|
|
119
|
+
QListWidgetItem,
|
|
120
|
+
QMainWindow,
|
|
121
|
+
QMenu,
|
|
122
|
+
QMessageBox as QtMessageBox,
|
|
123
|
+
QProgressBar,
|
|
124
|
+
QPushButton,
|
|
125
|
+
QScrollArea,
|
|
126
|
+
QSizePolicy,
|
|
127
|
+
QSlider,
|
|
128
|
+
QSplitter,
|
|
129
|
+
QSpinBox,
|
|
130
|
+
QStackedWidget,
|
|
131
|
+
QStatusBar,
|
|
132
|
+
QStyle,
|
|
133
|
+
QStyleOptionHeader,
|
|
134
|
+
QTabWidget,
|
|
135
|
+
QTableView,
|
|
136
|
+
QTableWidget,
|
|
137
|
+
QTableWidgetItem,
|
|
138
|
+
QTextEdit,
|
|
139
|
+
QToolButton,
|
|
140
|
+
QVBoxLayout,
|
|
141
|
+
QWidget,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class QMessageBox(QtMessageBox):
|
|
146
|
+
"""Window-modal message box wrapper so floating helper windows stay usable."""
|
|
147
|
+
|
|
148
|
+
def __init__(self, *args, **kwargs):
|
|
149
|
+
super().__init__(*args, **kwargs)
|
|
150
|
+
self.setWindowModality(Qt.WindowModal)
|
|
151
|
+
|
|
152
|
+
@classmethod
|
|
153
|
+
def _build_box(
|
|
154
|
+
cls,
|
|
155
|
+
parent,
|
|
156
|
+
icon,
|
|
157
|
+
title,
|
|
158
|
+
text,
|
|
159
|
+
buttons=QtMessageBox.Ok,
|
|
160
|
+
default_button=QtMessageBox.NoButton,
|
|
161
|
+
):
|
|
162
|
+
box = cls(parent)
|
|
163
|
+
box.setIcon(icon)
|
|
164
|
+
box.setWindowTitle(str(title or ""))
|
|
165
|
+
box.setText(str(text or ""))
|
|
166
|
+
box.setStandardButtons(buttons)
|
|
167
|
+
if default_button != QtMessageBox.NoButton:
|
|
168
|
+
box.setDefaultButton(default_button)
|
|
169
|
+
return box
|
|
170
|
+
|
|
171
|
+
@classmethod
|
|
172
|
+
def information(
|
|
173
|
+
cls,
|
|
174
|
+
parent,
|
|
175
|
+
title,
|
|
176
|
+
text,
|
|
177
|
+
buttons=QtMessageBox.Ok,
|
|
178
|
+
default_button=QtMessageBox.NoButton,
|
|
179
|
+
):
|
|
180
|
+
return cls._build_box(
|
|
181
|
+
parent,
|
|
182
|
+
cls.Information,
|
|
183
|
+
title,
|
|
184
|
+
text,
|
|
185
|
+
buttons=buttons,
|
|
186
|
+
default_button=default_button,
|
|
187
|
+
).exec()
|
|
188
|
+
|
|
189
|
+
@classmethod
|
|
190
|
+
def warning(
|
|
191
|
+
cls,
|
|
192
|
+
parent,
|
|
193
|
+
title,
|
|
194
|
+
text,
|
|
195
|
+
buttons=QtMessageBox.Ok,
|
|
196
|
+
default_button=QtMessageBox.NoButton,
|
|
197
|
+
):
|
|
198
|
+
return cls._build_box(
|
|
199
|
+
parent,
|
|
200
|
+
cls.Warning,
|
|
201
|
+
title,
|
|
202
|
+
text,
|
|
203
|
+
buttons=buttons,
|
|
204
|
+
default_button=default_button,
|
|
205
|
+
).exec()
|
|
206
|
+
|
|
207
|
+
@classmethod
|
|
208
|
+
def critical(
|
|
209
|
+
cls,
|
|
210
|
+
parent,
|
|
211
|
+
title,
|
|
212
|
+
text,
|
|
213
|
+
buttons=QtMessageBox.Ok,
|
|
214
|
+
default_button=QtMessageBox.NoButton,
|
|
215
|
+
):
|
|
216
|
+
return cls._build_box(
|
|
217
|
+
parent,
|
|
218
|
+
cls.Critical,
|
|
219
|
+
title,
|
|
220
|
+
text,
|
|
221
|
+
buttons=buttons,
|
|
222
|
+
default_button=default_button,
|
|
223
|
+
).exec()
|
|
224
|
+
|
|
225
|
+
@classmethod
|
|
226
|
+
def question(
|
|
227
|
+
cls,
|
|
228
|
+
parent,
|
|
229
|
+
title,
|
|
230
|
+
text,
|
|
231
|
+
buttons=QtMessageBox.StandardButton.Yes | QtMessageBox.StandardButton.No,
|
|
232
|
+
default_button=QtMessageBox.NoButton,
|
|
233
|
+
):
|
|
234
|
+
return cls._build_box(
|
|
235
|
+
parent,
|
|
236
|
+
cls.Question,
|
|
237
|
+
title,
|
|
238
|
+
text,
|
|
239
|
+
buttons=buttons,
|
|
240
|
+
default_button=default_button,
|
|
241
|
+
).exec()
|
|
242
|
+
|
|
243
|
+
class DropLabel(QFrame):
|
|
244
|
+
"""Frame-based drop target with an optional file dialog button."""
|
|
245
|
+
|
|
246
|
+
def __init__(self, text, parent=None, file_filter="CSV Files (*.csv)", extensions=(".csv",)):
|
|
247
|
+
super().__init__(parent)
|
|
248
|
+
self.file_filter = file_filter
|
|
249
|
+
self.valid_extensions = extensions
|
|
250
|
+
self.setAcceptDrops(True)
|
|
251
|
+
self.callback = None
|
|
252
|
+
self.full_file_path = None
|
|
253
|
+
|
|
254
|
+
self.setStyleSheet("font-size: 14px; border: none;")
|
|
255
|
+
self.layout = QVBoxLayout(self)
|
|
256
|
+
self.setLayout(self.layout)
|
|
257
|
+
|
|
258
|
+
self.label = QLabel(text, self)
|
|
259
|
+
self.label.setAlignment(Qt.AlignCenter)
|
|
260
|
+
self.label.setStyleSheet(
|
|
261
|
+
"""
|
|
262
|
+
font-size: 11px;
|
|
263
|
+
font-style: italic;
|
|
264
|
+
color: gray;
|
|
265
|
+
font-weight: bold;
|
|
266
|
+
border: 2px dashed gray;
|
|
267
|
+
padding: 5px;
|
|
268
|
+
border-radius: 5px;
|
|
269
|
+
"""
|
|
270
|
+
)
|
|
271
|
+
self.layout.addWidget(self.label, alignment=Qt.AlignCenter)
|
|
272
|
+
|
|
273
|
+
self.browse_button = QPushButton("Browse", self)
|
|
274
|
+
self.browse_button.clicked.connect(self.open_file_dialog)
|
|
275
|
+
self.browse_button.setFixedSize(120, 30)
|
|
276
|
+
self.browse_button.setStyleSheet(
|
|
277
|
+
"padding: 6px 12px; font-size: 14px; border-radius: 5px; "
|
|
278
|
+
"background-color: #555; color: white; border: 1px solid #777;"
|
|
279
|
+
)
|
|
280
|
+
self.layout.addWidget(self.browse_button, alignment=Qt.AlignCenter)
|
|
281
|
+
|
|
282
|
+
def set_callback(self, callback):
|
|
283
|
+
"""Set the callback function to be called when a file is selected."""
|
|
284
|
+
self.callback = callback
|
|
285
|
+
|
|
286
|
+
def set_file_type(self, file_filter, extensions):
|
|
287
|
+
"""Set the file type filter and valid extensions."""
|
|
288
|
+
self.file_filter = file_filter
|
|
289
|
+
self.valid_extensions = extensions
|
|
290
|
+
|
|
291
|
+
def open_file_dialog(self):
|
|
292
|
+
"""Open a file dialog to select a file."""
|
|
293
|
+
file_path, _ = QFileDialog.getOpenFileName(self, "Select File", "", self.file_filter)
|
|
294
|
+
if file_path and self.callback:
|
|
295
|
+
self.set_file_path(file_path)
|
|
296
|
+
|
|
297
|
+
def dragEnterEvent(self, event):
|
|
298
|
+
"""Allow dropping of files."""
|
|
299
|
+
if event.mimeData().hasUrls():
|
|
300
|
+
event.accept()
|
|
301
|
+
else:
|
|
302
|
+
event.ignore()
|
|
303
|
+
|
|
304
|
+
def dropEvent(self, event):
|
|
305
|
+
"""Handle dropped files."""
|
|
306
|
+
urls = event.mimeData().urls()
|
|
307
|
+
if urls:
|
|
308
|
+
file_path = urls[0].toLocalFile()
|
|
309
|
+
if file_path.lower().endswith(self.valid_extensions):
|
|
310
|
+
if self.set_file_path(file_path):
|
|
311
|
+
event.acceptProposedAction()
|
|
312
|
+
else:
|
|
313
|
+
event.ignore()
|
|
314
|
+
else:
|
|
315
|
+
extensions = ", ".join(self.valid_extensions)
|
|
316
|
+
QMessageBox.warning(
|
|
317
|
+
self, "Invalid file format", f"Please select a file ending in {extensions}."
|
|
318
|
+
)
|
|
319
|
+
event.ignore()
|
|
320
|
+
|
|
321
|
+
def set_file_path(self, file_path):
|
|
322
|
+
"""Set the file path and update the label."""
|
|
323
|
+
if self.callback and self.callback(file_path) is False:
|
|
324
|
+
return False
|
|
325
|
+
self.full_file_path = file_path
|
|
326
|
+
file_name = Path(file_path).name
|
|
327
|
+
self.label.setText(f"Selected: {file_name}")
|
|
328
|
+
self.label.setToolTip(file_path)
|
|
329
|
+
return True
|
|
330
|
+
|
|
331
|
+
def setText(self, text):
|
|
332
|
+
"""Set the text of the label."""
|
|
333
|
+
self.label.setText(text)
|
|
334
|
+
|
|
335
|
+
class RobertWorker(QThread):
|
|
336
|
+
"""QThread that runs a subprocess asynchronously and streams real-time output."""
|
|
337
|
+
|
|
338
|
+
output_received = Signal(str)
|
|
339
|
+
error_received = Signal(str)
|
|
340
|
+
process_finished = Signal(int)
|
|
341
|
+
request_stop = Signal()
|
|
342
|
+
|
|
343
|
+
def __init__(self, command, working_dir=None):
|
|
344
|
+
super().__init__()
|
|
345
|
+
self.command = command
|
|
346
|
+
self.working_dir = working_dir
|
|
347
|
+
self.process = None
|
|
348
|
+
self._stop_requested = False
|
|
349
|
+
self.is_windows = platform.system() == "Windows"
|
|
350
|
+
self.request_stop.connect(self._handle_stop)
|
|
351
|
+
|
|
352
|
+
@staticmethod
|
|
353
|
+
def _strip_ansi(text: str) -> str:
|
|
354
|
+
"""Remove ANSI escape sequences from process output."""
|
|
355
|
+
|
|
356
|
+
return re.sub(r"\x1B\[[0-?]*[ -/]*[@-~]", "", text)
|
|
357
|
+
|
|
358
|
+
def _format_console_line(self, text: str, color: str = "white") -> str:
|
|
359
|
+
"""Format one console line with an explicit color and escaped content."""
|
|
360
|
+
|
|
361
|
+
clean_text = self._strip_ansi(text.rstrip("\r\n"))
|
|
362
|
+
return f'<span style="color:{color};">{html.escape(clean_text)}</span>'
|
|
363
|
+
|
|
364
|
+
def run(self):
|
|
365
|
+
"""Run the subprocess and stream output in real-time."""
|
|
366
|
+
try:
|
|
367
|
+
process_env = os.environ.copy()
|
|
368
|
+
process_env["PYTHONIOENCODING"] = "utf-8"
|
|
369
|
+
if self.is_windows:
|
|
370
|
+
startupinfo = subprocess.STARTUPINFO()
|
|
371
|
+
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
372
|
+
startupinfo.wShowWindow = subprocess.SW_HIDE
|
|
373
|
+
|
|
374
|
+
self.process = subprocess.Popen(
|
|
375
|
+
shlex.split(self.command),
|
|
376
|
+
cwd=self.working_dir,
|
|
377
|
+
stdout=subprocess.PIPE,
|
|
378
|
+
stderr=subprocess.PIPE,
|
|
379
|
+
text=True,
|
|
380
|
+
# Keep both reader threads alive when child output contains invalid bytes.
|
|
381
|
+
encoding="utf-8",
|
|
382
|
+
errors="replace",
|
|
383
|
+
env=process_env,
|
|
384
|
+
bufsize=1,
|
|
385
|
+
universal_newlines=True,
|
|
386
|
+
startupinfo=startupinfo,
|
|
387
|
+
creationflags=(
|
|
388
|
+
subprocess.CREATE_NEW_PROCESS_GROUP
|
|
389
|
+
| subprocess.CREATE_NEW_CONSOLE
|
|
390
|
+
),
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
else:
|
|
394
|
+
self.process = subprocess.Popen(
|
|
395
|
+
shlex.split(self.command),
|
|
396
|
+
cwd=self.working_dir,
|
|
397
|
+
stdout=subprocess.PIPE,
|
|
398
|
+
stderr=subprocess.PIPE,
|
|
399
|
+
text=True,
|
|
400
|
+
encoding="utf-8",
|
|
401
|
+
errors="replace",
|
|
402
|
+
env=process_env,
|
|
403
|
+
bufsize=1,
|
|
404
|
+
universal_newlines=True,
|
|
405
|
+
preexec_fn=os.setsid,
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
def read_stdout():
|
|
409
|
+
"""Read stdout in real-time and emit formatted output."""
|
|
410
|
+
try:
|
|
411
|
+
for line in self.process.stdout:
|
|
412
|
+
if self._stop_requested:
|
|
413
|
+
break
|
|
414
|
+
formatted_line = self._format_console_line(line, color="white")
|
|
415
|
+
self.output_received.emit(formatted_line)
|
|
416
|
+
except Exception as exc:
|
|
417
|
+
self.error_received.emit(f"Error reading stdout: {exc}")
|
|
418
|
+
|
|
419
|
+
def read_stderr():
|
|
420
|
+
"""Read stderr in real-time and emit formatted output."""
|
|
421
|
+
try:
|
|
422
|
+
for line in self.process.stderr:
|
|
423
|
+
if self._stop_requested:
|
|
424
|
+
break
|
|
425
|
+
formatted_line = self._format_console_line(line, color="red")
|
|
426
|
+
self.error_received.emit(formatted_line)
|
|
427
|
+
except Exception as exc:
|
|
428
|
+
self.error_received.emit(f"Error reading stderr: {exc}")
|
|
429
|
+
|
|
430
|
+
stdout_thread = threading.Thread(target=read_stdout, daemon=True)
|
|
431
|
+
stderr_thread = threading.Thread(target=read_stderr, daemon=True)
|
|
432
|
+
stdout_thread.start()
|
|
433
|
+
stderr_thread.start()
|
|
434
|
+
|
|
435
|
+
exit_code = self.process.wait() if self.process else -1
|
|
436
|
+
stdout_thread.join()
|
|
437
|
+
stderr_thread.join()
|
|
438
|
+
|
|
439
|
+
self.process = None
|
|
440
|
+
self.process_finished.emit(-1 if self._stop_requested else exit_code)
|
|
441
|
+
except Exception as exc:
|
|
442
|
+
import traceback
|
|
443
|
+
|
|
444
|
+
tb = traceback.format_exc()
|
|
445
|
+
self.error_received.emit(f"Error in run(): {exc}\n{tb}")
|
|
446
|
+
self.process_finished.emit(1)
|
|
447
|
+
|
|
448
|
+
def stop(self):
|
|
449
|
+
"""Stop the subprocess and emit a stop signal."""
|
|
450
|
+
self.request_stop.emit()
|
|
451
|
+
|
|
452
|
+
def _handle_stop(self):
|
|
453
|
+
"""Handle the stop signal and terminate the subprocess."""
|
|
454
|
+
self._stop_requested = True
|
|
455
|
+
if not self.process:
|
|
456
|
+
return
|
|
457
|
+
|
|
458
|
+
try:
|
|
459
|
+
parent = psutil.Process(self.process.pid)
|
|
460
|
+
procs = parent.children(recursive=True)
|
|
461
|
+
procs.append(parent)
|
|
462
|
+
|
|
463
|
+
for proc in procs:
|
|
464
|
+
try:
|
|
465
|
+
proc.terminate()
|
|
466
|
+
except Exception:
|
|
467
|
+
pass
|
|
468
|
+
|
|
469
|
+
_, alive = psutil.wait_procs(procs, timeout=2)
|
|
470
|
+
for proc in alive:
|
|
471
|
+
try:
|
|
472
|
+
proc.kill()
|
|
473
|
+
except Exception:
|
|
474
|
+
pass
|
|
475
|
+
except Exception as exc:
|
|
476
|
+
self.error_received.emit(f"Error stopping process: {exc}")
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
class CSVPreflightWorker(QThread):
|
|
480
|
+
"""QThread that validates CSV accessibility before launching ROBERT."""
|
|
481
|
+
|
|
482
|
+
validation_finished = Signal(dict)
|
|
483
|
+
|
|
484
|
+
def __init__(self, csv_entries):
|
|
485
|
+
super().__init__()
|
|
486
|
+
self.csv_entries = list(csv_entries or [])
|
|
487
|
+
|
|
488
|
+
@staticmethod
|
|
489
|
+
def _resolve_path(path_value: str) -> str:
|
|
490
|
+
try:
|
|
491
|
+
return str(Path(path_value).expanduser().resolve(strict=False))
|
|
492
|
+
except OSError:
|
|
493
|
+
return os.path.abspath(path_value)
|
|
494
|
+
|
|
495
|
+
def run(self):
|
|
496
|
+
"""Check CSV paths for long-path and permission-denied conditions."""
|
|
497
|
+
for csv_label, csv_path in self.csv_entries:
|
|
498
|
+
if not csv_path:
|
|
499
|
+
continue
|
|
500
|
+
|
|
501
|
+
resolved_path = self._resolve_path(csv_path)
|
|
502
|
+
|
|
503
|
+
if len(resolved_path) > 200:
|
|
504
|
+
self.validation_finished.emit(
|
|
505
|
+
{
|
|
506
|
+
"ok": False,
|
|
507
|
+
"title": "WARNING!",
|
|
508
|
+
"message": (
|
|
509
|
+
f"The path of your {csv_label} is longer than 200 characters:\n\n"
|
|
510
|
+
f"{resolved_path}\n\n"
|
|
511
|
+
"To avoid problems in the workflow, move the file to a shorter path and try again."
|
|
512
|
+
),
|
|
513
|
+
}
|
|
514
|
+
)
|
|
515
|
+
return
|
|
516
|
+
|
|
517
|
+
try:
|
|
518
|
+
with open(resolved_path, "r", encoding="utf-8"):
|
|
519
|
+
pass
|
|
520
|
+
except PermissionError:
|
|
521
|
+
self.validation_finished.emit(
|
|
522
|
+
{
|
|
523
|
+
"ok": False,
|
|
524
|
+
"title": "WARNING!",
|
|
525
|
+
"message": (
|
|
526
|
+
f"ROBERT could not access your {csv_label}:\n\n"
|
|
527
|
+
f"{resolved_path}\n\n"
|
|
528
|
+
"Close the CSV file, pause OneDrive, or close any app that might be using the file, and try again."
|
|
529
|
+
),
|
|
530
|
+
}
|
|
531
|
+
)
|
|
532
|
+
return
|
|
533
|
+
except OSError:
|
|
534
|
+
continue
|
|
535
|
+
|
|
536
|
+
self.validation_finished.emit({"ok": True})
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
def warn_if_csv_name_has_spaces(parent, file_path, what="CSV", title="WARNING!"):
|
|
540
|
+
"""ROBERT can't use CSV files with spaces in their name (spaces in the folders are fine) and
|
|
541
|
+
it exits with code 0 when it stops for that reason, so the user is warned as soon as the file
|
|
542
|
+
is picked. Returns True if the name has spaces."""
|
|
543
|
+
file_name = os.path.basename(file_path)
|
|
544
|
+
if " " not in file_name:
|
|
545
|
+
return False
|
|
546
|
+
QMessageBox.warning(
|
|
547
|
+
parent, title,
|
|
548
|
+
f"The {what} file name contains spaces:\n{file_name}\n\n"
|
|
549
|
+
"ROBERT can't use CSV files with spaces in their name. Please rename it "
|
|
550
|
+
"(i.e., 'my_data.csv' instead of 'my data.csv') and select it again."
|
|
551
|
+
)
|
|
552
|
+
return True
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def smart_read_csv(filepath):
|
|
556
|
+
"""Read a CSV file with automatic delimiter detection."""
|
|
557
|
+
try:
|
|
558
|
+
with open(filepath, "r", encoding="utf-8") as file_obj:
|
|
559
|
+
first_line = file_obj.readline()
|
|
560
|
+
delimiter = ";" if first_line.count(";") > first_line.count(",") else ","
|
|
561
|
+
|
|
562
|
+
return pd.read_csv(filepath, encoding="utf-8", delimiter=delimiter)
|
|
563
|
+
except (OSError, UnicodeError, pd.errors.EmptyDataError, pd.errors.ParserError):
|
|
564
|
+
return None
|
|
565
|
+
|
|
566
|
+
class NoScrollComboBox(QComboBox):
|
|
567
|
+
"""Combo box that ignores wheel events while the popup is closed."""
|
|
568
|
+
|
|
569
|
+
def wheelEvent(self, event: QWheelEvent):
|
|
570
|
+
if self.view().isVisible():
|
|
571
|
+
super().wheelEvent(event)
|
|
572
|
+
else:
|
|
573
|
+
event.ignore()
|
|
574
|
+
|
|
575
|
+
class SegmentedButtonGroup(QWidget):
|
|
576
|
+
"""
|
|
577
|
+
A grid of mutually-exclusive checkable buttons, used instead of a QComboBox dropdown
|
|
578
|
+
for choices that should always be visible at a glance (a dropdown hides every option but
|
|
579
|
+
the current one behind a click, which is easy to miss or mis-select).
|
|
580
|
+
|
|
581
|
+
Exposes the same currentText()/setCurrentText() surface a QComboBox does, so it's a
|
|
582
|
+
drop-in replacement for call sites that only ever read/set the selection as a string -
|
|
583
|
+
the widget itself doesn't need to know about them.
|
|
584
|
+
"""
|
|
585
|
+
|
|
586
|
+
def __init__(self, options, columns=3, parent=None):
|
|
587
|
+
super().__init__(parent)
|
|
588
|
+
|
|
589
|
+
self._group = QButtonGroup(self)
|
|
590
|
+
self._group.setExclusive(True)
|
|
591
|
+
self._buttons = {}
|
|
592
|
+
self._options = list(options)
|
|
593
|
+
|
|
594
|
+
layout = QGridLayout(self)
|
|
595
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
596
|
+
layout.setSpacing(4)
|
|
597
|
+
|
|
598
|
+
# the checked state uses a neutral light-gray highlight (not the purple "Run ROBERT"
|
|
599
|
+
# uses) so this selection marker doesn't visually compete with that actual action button
|
|
600
|
+
button_style = """
|
|
601
|
+
QPushButton {
|
|
602
|
+
border: 1px solid palette(mid);
|
|
603
|
+
border-radius: 4px;
|
|
604
|
+
padding: 3px 2px;
|
|
605
|
+
font-size: 12px;
|
|
606
|
+
background: palette(base);
|
|
607
|
+
}
|
|
608
|
+
QPushButton:hover {
|
|
609
|
+
background: palette(light);
|
|
610
|
+
}
|
|
611
|
+
QPushButton:checked {
|
|
612
|
+
background-color: #D6D6D6;
|
|
613
|
+
color: palette(text);
|
|
614
|
+
font-weight: bold;
|
|
615
|
+
border: 1px solid #999999;
|
|
616
|
+
}
|
|
617
|
+
"""
|
|
618
|
+
|
|
619
|
+
for i, option in enumerate(options):
|
|
620
|
+
button = QPushButton(option)
|
|
621
|
+
button.setCheckable(True)
|
|
622
|
+
button.setFixedHeight(26)
|
|
623
|
+
button.setStyleSheet(button_style)
|
|
624
|
+
self._group.addButton(button)
|
|
625
|
+
self._buttons[option] = button
|
|
626
|
+
row, col = divmod(i, columns)
|
|
627
|
+
layout.addWidget(button, row, col)
|
|
628
|
+
|
|
629
|
+
if options:
|
|
630
|
+
self._buttons[options[0]].setChecked(True)
|
|
631
|
+
|
|
632
|
+
def currentText(self):
|
|
633
|
+
checked = self._group.checkedButton()
|
|
634
|
+
return checked.text() if checked else ""
|
|
635
|
+
|
|
636
|
+
def setCurrentText(self, text):
|
|
637
|
+
button = self._buttons.get(text)
|
|
638
|
+
if button is not None:
|
|
639
|
+
button.setChecked(True)
|
|
640
|
+
|
|
641
|
+
def count(self):
|
|
642
|
+
return len(self._options)
|
|
643
|
+
|
|
644
|
+
def itemText(self, index):
|
|
645
|
+
return self._options[index]
|
|
646
|
+
|
|
647
|
+
class YesNoToggle(QWidget):
|
|
648
|
+
"""
|
|
649
|
+
An explicit "No"/"Yes" segmented pair for a boolean choice, used instead of a single
|
|
650
|
+
checkable button whose on/off state isn't obvious at a glance (is it a toggle? does
|
|
651
|
+
clicking it run something right away?). Exposes the same isChecked()/setChecked() surface
|
|
652
|
+
a QCheckBox/checkable QPushButton does, plus a toggled(bool) signal, so it's a drop-in
|
|
653
|
+
replacement for call sites built around that API.
|
|
654
|
+
"""
|
|
655
|
+
|
|
656
|
+
toggled = Signal(bool)
|
|
657
|
+
|
|
658
|
+
def __init__(self, checked=False, parent=None):
|
|
659
|
+
super().__init__(parent)
|
|
660
|
+
|
|
661
|
+
self._group = QButtonGroup(self)
|
|
662
|
+
self._group.setExclusive(True)
|
|
663
|
+
|
|
664
|
+
layout = QHBoxLayout(self)
|
|
665
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
666
|
+
layout.setSpacing(4)
|
|
667
|
+
|
|
668
|
+
button_style = """
|
|
669
|
+
QPushButton {
|
|
670
|
+
border: 1px solid palette(mid);
|
|
671
|
+
border-radius: 4px;
|
|
672
|
+
padding: 3px 2px;
|
|
673
|
+
font-size: 12px;
|
|
674
|
+
background: palette(base);
|
|
675
|
+
}
|
|
676
|
+
QPushButton:hover {
|
|
677
|
+
background: palette(light);
|
|
678
|
+
}
|
|
679
|
+
QPushButton:checked {
|
|
680
|
+
background-color: #D6D6D6;
|
|
681
|
+
color: palette(text);
|
|
682
|
+
font-weight: bold;
|
|
683
|
+
border: 1px solid #999999;
|
|
684
|
+
}
|
|
685
|
+
"""
|
|
686
|
+
|
|
687
|
+
self._no_button = QPushButton("No")
|
|
688
|
+
self._yes_button = QPushButton("Yes")
|
|
689
|
+
for button in (self._no_button, self._yes_button):
|
|
690
|
+
button.setCheckable(True)
|
|
691
|
+
button.setFixedHeight(26)
|
|
692
|
+
button.setStyleSheet(button_style)
|
|
693
|
+
self._group.addButton(button)
|
|
694
|
+
layout.addWidget(button)
|
|
695
|
+
|
|
696
|
+
self._no_button.setChecked(not checked)
|
|
697
|
+
self._yes_button.setChecked(checked)
|
|
698
|
+
self._yes_button.toggled.connect(self.toggled.emit)
|
|
699
|
+
|
|
700
|
+
def isChecked(self):
|
|
701
|
+
return self._yes_button.isChecked()
|
|
702
|
+
|
|
703
|
+
def setChecked(self, checked):
|
|
704
|
+
self._yes_button.setChecked(checked)
|
|
705
|
+
self._no_button.setChecked(not checked)
|
|
706
|
+
|
|
707
|
+
class AssetPath:
|
|
708
|
+
"""Resolve asset paths both in development and in frozen distributions."""
|
|
709
|
+
|
|
710
|
+
def __init__(self, filename):
|
|
711
|
+
self._filename = filename
|
|
712
|
+
|
|
713
|
+
def get_path(self):
|
|
714
|
+
if getattr(sys, "frozen", False):
|
|
715
|
+
return (
|
|
716
|
+
Path.cwd()
|
|
717
|
+
/ "_internal"
|
|
718
|
+
/ "robert_env"
|
|
719
|
+
/ "Lib"
|
|
720
|
+
/ "site-packages"
|
|
721
|
+
/ "robert"
|
|
722
|
+
/ "icons"
|
|
723
|
+
/ self._filename
|
|
724
|
+
)
|
|
725
|
+
return as_file(files("robert") / "icons" / self._filename)
|
|
726
|
+
|
|
727
|
+
class AssetLibrary:
|
|
728
|
+
"""Central registry of asset files used by the GUI."""
|
|
729
|
+
|
|
730
|
+
Info_icon = AssetPath("info_icon.png")
|
|
731
|
+
Robert_logo_transparent = AssetPath("Robert_logo_transparent.png")
|
|
732
|
+
Robert_icon = AssetPath("Robert_icon.png")
|
|
733
|
+
CheckML_icon = AssetPath("CheckML_icon.png")
|
|
734
|
+
Play_icon = AssetPath("play_icon.png")
|
|
735
|
+
Stop_icon = AssetPath("stop_icon.png")
|
|
736
|
+
Youtube_icon = AssetPath("youtube_icon.ico")
|
|
737
|
+
Documentation_icon = AssetPath("documentation_icon.png")
|
|
738
|
+
Pdf_icon = AssetPath("pdf_icon.png")
|