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,490 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Results PDF viewer for ROBERT reports.
|
|
3
|
+
|
|
4
|
+
This module provides a responsive interface to explore generated PDF reports
|
|
5
|
+
within the GUI. It avoids blocking the UI by loading metadata and rendering
|
|
6
|
+
pages asynchronously.
|
|
7
|
+
|
|
8
|
+
Responsibilities:
|
|
9
|
+
- Discover and manage PDF reports generated by the workflow
|
|
10
|
+
- Create lightweight tab placeholders for each report
|
|
11
|
+
- Load PDF metadata (page count, sizes) in background threads
|
|
12
|
+
- Render only visible pages on demand (lazy rendering)
|
|
13
|
+
- Cache rendered pages and discard outdated renders on zoom changes
|
|
14
|
+
|
|
15
|
+
Architecture:
|
|
16
|
+
- Uses QRunnable tasks (RenderTask, MetaTask) executed via QThreadPool
|
|
17
|
+
- Applies a generation-based system to cancel stale render operations
|
|
18
|
+
- Computes visible page ranges to minimize unnecessary rendering
|
|
19
|
+
|
|
20
|
+
Import strategy:
|
|
21
|
+
- Supports dual execution modes:
|
|
22
|
+
1. Local (portable execution)
|
|
23
|
+
2. Installed package (environment / entry point)
|
|
24
|
+
|
|
25
|
+
- Imports use a try/except fallback to ensure compatibility.
|
|
26
|
+
|
|
27
|
+
Notes:
|
|
28
|
+
- Designed for performance with large PDF files
|
|
29
|
+
- Rendering is viewport-driven to avoid excessive memory and CPU usage
|
|
30
|
+
- Acts as a self-contained viewer independent from the main application logic
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
# ------------------------------------------------------------
|
|
34
|
+
# Import resolution (local vs installed package)
|
|
35
|
+
# ------------------------------------------------------------
|
|
36
|
+
try:
|
|
37
|
+
from utils.utils_gui import (
|
|
38
|
+
QImage,
|
|
39
|
+
QLabel,
|
|
40
|
+
QObject,
|
|
41
|
+
QPixmap,
|
|
42
|
+
QRunnable,
|
|
43
|
+
QScrollArea,
|
|
44
|
+
QSizePolicy,
|
|
45
|
+
QSlider,
|
|
46
|
+
QTabWidget,
|
|
47
|
+
QThreadPool,
|
|
48
|
+
QTimer,
|
|
49
|
+
QVBoxLayout,
|
|
50
|
+
QWidget,
|
|
51
|
+
Qt,
|
|
52
|
+
Signal,
|
|
53
|
+
Slot,
|
|
54
|
+
fitz,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
except ImportError as e:
|
|
58
|
+
from robert.gui_easyrob.utils.utils_gui import (
|
|
59
|
+
QImage,
|
|
60
|
+
QLabel,
|
|
61
|
+
QObject,
|
|
62
|
+
QPixmap,
|
|
63
|
+
QRunnable,
|
|
64
|
+
QScrollArea,
|
|
65
|
+
QSizePolicy,
|
|
66
|
+
QSlider,
|
|
67
|
+
QTabWidget,
|
|
68
|
+
QThreadPool,
|
|
69
|
+
QTimer,
|
|
70
|
+
QVBoxLayout,
|
|
71
|
+
QWidget,
|
|
72
|
+
Qt,
|
|
73
|
+
Signal,
|
|
74
|
+
Slot,
|
|
75
|
+
fitz,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# ------------------------------------------------------------
|
|
79
|
+
# Standard library
|
|
80
|
+
# ------------------------------------------------------------
|
|
81
|
+
import os
|
|
82
|
+
import glob
|
|
83
|
+
|
|
84
|
+
class ResultsTab(QWidget):
|
|
85
|
+
"""PDF viewer for ROBERT reports."""
|
|
86
|
+
def __init__(self, main_tab_widget, file_path):
|
|
87
|
+
super().__init__()
|
|
88
|
+
|
|
89
|
+
self.main_tab_widget = main_tab_widget
|
|
90
|
+
self.base_path = os.path.dirname(file_path)
|
|
91
|
+
self.report_paths = None
|
|
92
|
+
self.pdf_tabs = {} # {pdf_path: PDFViewer|None} None => placeholder not materialized
|
|
93
|
+
self.title_to_path = {} # {basename: full path}
|
|
94
|
+
|
|
95
|
+
# Shared thread pool for all PDF viewers
|
|
96
|
+
self.shared_pool = QThreadPool()
|
|
97
|
+
# Tune according to CPU cores; 4–6 is a good start
|
|
98
|
+
self.shared_pool.setMaxThreadCount(4)
|
|
99
|
+
|
|
100
|
+
# Internal tab widget for PDF files
|
|
101
|
+
self.pdf_tab_widget = QTabWidget()
|
|
102
|
+
layout = QVBoxLayout(self)
|
|
103
|
+
layout.addWidget(self.pdf_tab_widget)
|
|
104
|
+
self.setLayout(layout)
|
|
105
|
+
|
|
106
|
+
self.pdf_tab_widget.currentChanged.connect(self._maybe_materialize_tab)
|
|
107
|
+
|
|
108
|
+
# Initial discover
|
|
109
|
+
self.check_for_pdfs()
|
|
110
|
+
|
|
111
|
+
# ----------------- Public API -----------------
|
|
112
|
+
def refresh_with_new_path(self, file_path, report_paths=None):
|
|
113
|
+
"""Updates the path and reloads PDF tabs."""
|
|
114
|
+
self.base_path = os.path.dirname(file_path)
|
|
115
|
+
self.report_paths = report_paths
|
|
116
|
+
self.clear_pdf_tabs()
|
|
117
|
+
self.check_for_pdfs()
|
|
118
|
+
|
|
119
|
+
def clear_pdf_tabs(self):
|
|
120
|
+
"""Remove all existing PDF tabs."""
|
|
121
|
+
# Disable updates for batch UI operations
|
|
122
|
+
self.pdf_tab_widget.setUpdatesEnabled(False)
|
|
123
|
+
try:
|
|
124
|
+
for path, viewer in list(self.pdf_tabs.items()):
|
|
125
|
+
if viewer:
|
|
126
|
+
index = self.pdf_tab_widget.indexOf(viewer)
|
|
127
|
+
else:
|
|
128
|
+
index = self._index_of_title(os.path.basename(path))
|
|
129
|
+
if index != -1:
|
|
130
|
+
page = self.pdf_tab_widget.widget(index)
|
|
131
|
+
self.pdf_tab_widget.removeTab(index)
|
|
132
|
+
page.deleteLater()
|
|
133
|
+
del self.pdf_tabs[path]
|
|
134
|
+
self.title_to_path.pop(os.path.basename(path), None)
|
|
135
|
+
finally:
|
|
136
|
+
self.pdf_tab_widget.setUpdatesEnabled(True)
|
|
137
|
+
|
|
138
|
+
def check_for_pdfs(self):
|
|
139
|
+
"""Checks for new PDFs and updates the UI dynamically (fast path: sync glob)."""
|
|
140
|
+
if self.report_paths is None:
|
|
141
|
+
pdf_pattern = os.path.join(self.base_path, "ROBERT_report*.pdf")
|
|
142
|
+
pdf_files = sorted(glob.glob(pdf_pattern))
|
|
143
|
+
else:
|
|
144
|
+
pdf_files = [str(path) for path in self.report_paths if os.path.isfile(path)]
|
|
145
|
+
|
|
146
|
+
# Remove missing
|
|
147
|
+
to_remove = [p for p in self.pdf_tabs.keys() if p not in pdf_files]
|
|
148
|
+
if to_remove:
|
|
149
|
+
self.pdf_tab_widget.setUpdatesEnabled(False)
|
|
150
|
+
try:
|
|
151
|
+
for pdf in to_remove:
|
|
152
|
+
viewer = self.pdf_tabs[pdf]
|
|
153
|
+
if viewer:
|
|
154
|
+
idx = self.pdf_tab_widget.indexOf(viewer)
|
|
155
|
+
else:
|
|
156
|
+
idx = self._index_of_title(os.path.basename(pdf))
|
|
157
|
+
if idx != -1:
|
|
158
|
+
page = self.pdf_tab_widget.widget(idx)
|
|
159
|
+
self.pdf_tab_widget.removeTab(idx)
|
|
160
|
+
page.deleteLater()
|
|
161
|
+
del self.pdf_tabs[pdf]
|
|
162
|
+
self.title_to_path.pop(os.path.basename(pdf), None)
|
|
163
|
+
finally:
|
|
164
|
+
self.pdf_tab_widget.setUpdatesEnabled(True)
|
|
165
|
+
|
|
166
|
+
# Add placeholders for new PDFs
|
|
167
|
+
for pdf in pdf_files:
|
|
168
|
+
if pdf not in self.pdf_tabs:
|
|
169
|
+
self.add_pdf_tab(pdf)
|
|
170
|
+
|
|
171
|
+
# ----------------- Internal helpers -----------------
|
|
172
|
+
def add_pdf_tab(self, pdf_path: str):
|
|
173
|
+
"""Create a lightweight placeholder tab; real viewer is built on demand."""
|
|
174
|
+
placeholder = QWidget()
|
|
175
|
+
lay = QVBoxLayout(placeholder)
|
|
176
|
+
lab = QLabel("Loading PDF…")
|
|
177
|
+
lab.setAlignment(Qt.AlignCenter)
|
|
178
|
+
lay.addWidget(lab)
|
|
179
|
+
|
|
180
|
+
title = os.path.basename(pdf_path)
|
|
181
|
+
index = self.pdf_tab_widget.addTab(placeholder, title)
|
|
182
|
+
|
|
183
|
+
self.pdf_tabs[pdf_path] = None
|
|
184
|
+
self.title_to_path[title] = pdf_path
|
|
185
|
+
|
|
186
|
+
# Optional: eagerly materialize the very first tab, after UI breathes
|
|
187
|
+
if self.pdf_tab_widget.count() == 1:
|
|
188
|
+
QTimer.singleShot(0, lambda: self._materialize_pdf_viewer(index, pdf_path))
|
|
189
|
+
|
|
190
|
+
def _maybe_materialize_tab(self, index: int):
|
|
191
|
+
"""Materialize a PDF viewer if it hasn't been materialized yet."""
|
|
192
|
+
if index < 0:
|
|
193
|
+
return
|
|
194
|
+
title = self.pdf_tab_widget.tabText(index)
|
|
195
|
+
pdf_path = self.title_to_path.get(title)
|
|
196
|
+
if not pdf_path:
|
|
197
|
+
return
|
|
198
|
+
if self.pdf_tabs.get(pdf_path) is None:
|
|
199
|
+
self._materialize_pdf_viewer(index, pdf_path)
|
|
200
|
+
|
|
201
|
+
def _materialize_pdf_viewer(self, index: int, pdf_path: str):
|
|
202
|
+
"""Materialize a PDF viewer."""
|
|
203
|
+
if pdf_path not in self.pdf_tabs or self.pdf_tab_widget.tabText(index) != os.path.basename(pdf_path):
|
|
204
|
+
return
|
|
205
|
+
viewer = PDFViewer(pdf_path, thread_pool=self.shared_pool)
|
|
206
|
+
self.pdf_tabs[pdf_path] = viewer
|
|
207
|
+
placeholder = self.pdf_tab_widget.widget(index)
|
|
208
|
+
self.pdf_tab_widget.removeTab(index)
|
|
209
|
+
placeholder.deleteLater()
|
|
210
|
+
self.pdf_tab_widget.insertTab(index, viewer, os.path.basename(pdf_path))
|
|
211
|
+
self.pdf_tab_widget.setCurrentIndex(index)
|
|
212
|
+
|
|
213
|
+
def _index_of_title(self, title: str) -> int:
|
|
214
|
+
"""Returns the index of a tab by title."""
|
|
215
|
+
for i in range(self.pdf_tab_widget.count()):
|
|
216
|
+
if self.pdf_tab_widget.tabText(i) == title:
|
|
217
|
+
return i
|
|
218
|
+
return -1
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# ------------------------- Worker signals -------------------------
|
|
222
|
+
|
|
223
|
+
class RenderSignals(QObject):
|
|
224
|
+
"""Signals for page rendering."""
|
|
225
|
+
finished = Signal(int, float, int, QPixmap) # page_num, zoom, generation, pixmap
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class MetaSignals(QObject):
|
|
229
|
+
"""Signals for PDF metadata loading."""
|
|
230
|
+
done = Signal(int, list) # page_count, page_sizes
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
# ------------------------- Worker tasks -------------------------
|
|
234
|
+
|
|
235
|
+
class RenderTask(QRunnable):
|
|
236
|
+
"""Background render task for a single PDF page (open by path; no big upfront I/O)."""
|
|
237
|
+
def __init__(self, pdf_path: str, page_num: int, zoom: float, generation: int):
|
|
238
|
+
super().__init__()
|
|
239
|
+
self.pdf_path = pdf_path
|
|
240
|
+
self.page_num = page_num
|
|
241
|
+
self.zoom = zoom
|
|
242
|
+
self.generation = generation
|
|
243
|
+
self.signals = RenderSignals()
|
|
244
|
+
|
|
245
|
+
@Slot()
|
|
246
|
+
def run(self):
|
|
247
|
+
"""Render the specified page and emit the result."""
|
|
248
|
+
try:
|
|
249
|
+
# Open by path. Let OS cache/mmap do the heavy lifting.
|
|
250
|
+
with fitz.open(self.pdf_path) as doc:
|
|
251
|
+
page = doc.load_page(self.page_num)
|
|
252
|
+
mat = fitz.Matrix(self.zoom, self.zoom)
|
|
253
|
+
pix = page.get_pixmap(matrix=mat, alpha=False)
|
|
254
|
+
qimg = QImage(pix.samples, pix.width, pix.height, pix.stride, QImage.Format_RGB888).copy()
|
|
255
|
+
qp = QPixmap.fromImage(qimg)
|
|
256
|
+
self.signals.finished.emit(self.page_num, self.zoom, self.generation, qp)
|
|
257
|
+
except Exception:
|
|
258
|
+
self.signals.finished.emit(self.page_num, self.zoom, self.generation, QPixmap())
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
class MetaTask(QRunnable):
|
|
262
|
+
"""Load page count and page sizes off the UI thread."""
|
|
263
|
+
def __init__(self, pdf_path: str):
|
|
264
|
+
super().__init__()
|
|
265
|
+
self.pdf_path = pdf_path
|
|
266
|
+
self.signals = MetaSignals()
|
|
267
|
+
|
|
268
|
+
@Slot()
|
|
269
|
+
def run(self):
|
|
270
|
+
"""Load page count and page sizes off the UI thread."""
|
|
271
|
+
try:
|
|
272
|
+
with fitz.open(self.pdf_path) as doc:
|
|
273
|
+
count = len(doc)
|
|
274
|
+
sizes = [tuple(doc.load_page(i).rect.br) for i in range(count)] # (w_pts, h_pts)
|
|
275
|
+
except Exception:
|
|
276
|
+
count, sizes = 1, [(595, 842)] # Fallback to A4 portrait in points
|
|
277
|
+
self.signals.done.emit(count, sizes)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
# ------------------------- PDFViewer (async metadata + visible-only render) -------------------------
|
|
281
|
+
|
|
282
|
+
class PDFViewer(QWidget):
|
|
283
|
+
"""Widget to display a PDF inside a scrollable area with zoom control and threading."""
|
|
284
|
+
def __init__(self, pdf_path: str, thread_pool: QThreadPool):
|
|
285
|
+
super().__init__()
|
|
286
|
+
self.pdf_path = pdf_path
|
|
287
|
+
self.current_zoom = 1.2
|
|
288
|
+
|
|
289
|
+
self.thread_pool = thread_pool # shared
|
|
290
|
+
self.image_cache = {} # {(page_num, zoom): QPixmap}
|
|
291
|
+
self.labels = [] # one QLabel per page
|
|
292
|
+
self.page_sizes = None # [(width_pts, height_pts)]
|
|
293
|
+
self.page_count = None
|
|
294
|
+
self._renderGeneration = 0 # cancel stale renders
|
|
295
|
+
self._zoomPending = False
|
|
296
|
+
self._scrollPending = False
|
|
297
|
+
|
|
298
|
+
# UI skeleton first (fast)
|
|
299
|
+
layout = QVBoxLayout(self)
|
|
300
|
+
|
|
301
|
+
# Zoom slider (live, coalesced)
|
|
302
|
+
self.zoom_slider = QSlider(Qt.Orientation.Horizontal)
|
|
303
|
+
self.zoom_slider.setRange(10, 60)
|
|
304
|
+
self.zoom_slider.setValue(int(self.current_zoom * 10))
|
|
305
|
+
self.zoom_slider.setTracking(True)
|
|
306
|
+
self.zoom_slider.valueChanged.connect(self._schedule_apply_zoom)
|
|
307
|
+
layout.addWidget(self.zoom_slider)
|
|
308
|
+
|
|
309
|
+
# Scroll area
|
|
310
|
+
self.scroll_area = QScrollArea(self)
|
|
311
|
+
self.scroll_area.setWidgetResizable(True)
|
|
312
|
+
layout.addWidget(self.scroll_area)
|
|
313
|
+
|
|
314
|
+
self.container = QWidget()
|
|
315
|
+
self.scroll_area.setWidget(self.container)
|
|
316
|
+
self.vbox = QVBoxLayout(self.container)
|
|
317
|
+
|
|
318
|
+
# Temporary "loading…" label until metadata arrives
|
|
319
|
+
self.loading_label = QLabel("Loading pages…")
|
|
320
|
+
self.loading_label.setAlignment(Qt.AlignCenter)
|
|
321
|
+
self.vbox.addWidget(self.loading_label)
|
|
322
|
+
|
|
323
|
+
# Load metadata off the UI thread
|
|
324
|
+
self._load_metadata_async()
|
|
325
|
+
|
|
326
|
+
# ---------- Async metadata ----------
|
|
327
|
+
def _load_metadata_async(self):
|
|
328
|
+
"""Load page count and page sizes off the UI thread."""
|
|
329
|
+
task = MetaTask(self.pdf_path)
|
|
330
|
+
task.signals.done.connect(self._apply_metadata, Qt.QueuedConnection)
|
|
331
|
+
self.thread_pool.start(task)
|
|
332
|
+
|
|
333
|
+
@Slot(int, list)
|
|
334
|
+
def _apply_metadata(self, page_count: int, page_sizes: list):
|
|
335
|
+
"""Load page count and page sizes on the UI thread."""
|
|
336
|
+
self.page_count = page_count
|
|
337
|
+
self.page_sizes = page_sizes
|
|
338
|
+
|
|
339
|
+
# Replace loading label with real page placeholders
|
|
340
|
+
if self.loading_label is not None:
|
|
341
|
+
self.vbox.removeWidget(self.loading_label)
|
|
342
|
+
self.loading_label.deleteLater()
|
|
343
|
+
self.loading_label = None
|
|
344
|
+
|
|
345
|
+
self._build_placeholders_for_zoom(self.current_zoom)
|
|
346
|
+
|
|
347
|
+
# Now that we know page geometry, hook scroll coalescing
|
|
348
|
+
self.scroll_area.verticalScrollBar().valueChanged.connect(self._schedule_visible_render)
|
|
349
|
+
|
|
350
|
+
# Initial render: only what's visible + tiny warm
|
|
351
|
+
self._kick_off_visible_render(force=True, warm=1)
|
|
352
|
+
|
|
353
|
+
# ---------- Event coalescing ----------
|
|
354
|
+
def _schedule_apply_zoom(self, _value: int):
|
|
355
|
+
"""Coalesce zoom changes."""
|
|
356
|
+
if self._zoomPending:
|
|
357
|
+
return
|
|
358
|
+
self._zoomPending = True
|
|
359
|
+
QTimer.singleShot(0, self._apply_zoom_now)
|
|
360
|
+
|
|
361
|
+
def _apply_zoom_now(self):
|
|
362
|
+
"""Apply zoom change."""
|
|
363
|
+
self._zoomPending = False
|
|
364
|
+
new_zoom = self.zoom_slider.value() / 10.0
|
|
365
|
+
if new_zoom == self.current_zoom:
|
|
366
|
+
return
|
|
367
|
+
self.current_zoom = new_zoom
|
|
368
|
+
# Bump generation to discard in-flight renders
|
|
369
|
+
self._renderGeneration += 1
|
|
370
|
+
# Keep only current-zoom cache
|
|
371
|
+
self.image_cache = {k: v for k, v in self.image_cache.items() if k[1] == self.current_zoom}
|
|
372
|
+
# Recompute placeholder heights and clear labels
|
|
373
|
+
self._build_placeholders_for_zoom(self.current_zoom)
|
|
374
|
+
# Kick minimal warm-up
|
|
375
|
+
self._kick_off_visible_render(force=True, warm=1)
|
|
376
|
+
|
|
377
|
+
def _schedule_visible_render(self, _):
|
|
378
|
+
"""Coalesce scroll events."""
|
|
379
|
+
if self._scrollPending:
|
|
380
|
+
return
|
|
381
|
+
self._scrollPending = True
|
|
382
|
+
QTimer.singleShot(0, self._do_visible_render)
|
|
383
|
+
|
|
384
|
+
def _do_visible_render(self):
|
|
385
|
+
"""Render visible pages."""
|
|
386
|
+
self._scrollPending = False
|
|
387
|
+
self._kick_off_visible_render()
|
|
388
|
+
|
|
389
|
+
# ---------- Layout helpers ----------
|
|
390
|
+
def _logical_height_for_page(self, page_index: int, zoom: float) -> int:
|
|
391
|
+
"""Convert page index to logical height in pixels."""
|
|
392
|
+
# PDF user space: 72 dpi. Height in pixels ~ points * zoom
|
|
393
|
+
if self.page_sizes and 0 <= page_index < len(self.page_sizes):
|
|
394
|
+
_, h_pt = self.page_sizes[page_index]
|
|
395
|
+
else:
|
|
396
|
+
h_pt = 842 # A4 portrait fallback in points
|
|
397
|
+
return max(1, int(h_pt * zoom))
|
|
398
|
+
|
|
399
|
+
def _build_placeholders_for_zoom(self, zoom: float):
|
|
400
|
+
"""Create placeholder labels for all pages."""
|
|
401
|
+
if self.page_count is None:
|
|
402
|
+
# No metadata yet; keep simple loading label
|
|
403
|
+
return
|
|
404
|
+
|
|
405
|
+
# Create labels once
|
|
406
|
+
if not self.labels:
|
|
407
|
+
for _ in range(self.page_count):
|
|
408
|
+
lbl = QLabel("Rendering…")
|
|
409
|
+
lbl.setAlignment(Qt.AlignCenter)
|
|
410
|
+
lbl.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
|
411
|
+
self.vbox.addWidget(lbl)
|
|
412
|
+
self.labels.append(lbl)
|
|
413
|
+
self.vbox.addStretch(1)
|
|
414
|
+
|
|
415
|
+
# Fix heights up-front to avoid layout jumps
|
|
416
|
+
for i, lbl in enumerate(self.labels):
|
|
417
|
+
h = self._logical_height_for_page(i, zoom)
|
|
418
|
+
lbl.setMinimumHeight(h)
|
|
419
|
+
lbl.setMaximumHeight(h)
|
|
420
|
+
lbl.setPixmap(QPixmap())
|
|
421
|
+
lbl.setText("Rendering…")
|
|
422
|
+
|
|
423
|
+
def _visible_window(self) -> tuple[int, int]:
|
|
424
|
+
"""Compute first/last visible page indices by scanning cumulative heights."""
|
|
425
|
+
if not self.labels:
|
|
426
|
+
return (0, 0)
|
|
427
|
+
|
|
428
|
+
vp = self.scroll_area.viewport()
|
|
429
|
+
top = self.scroll_area.verticalScrollBar().value()
|
|
430
|
+
bottom = top + vp.height()
|
|
431
|
+
|
|
432
|
+
# Find first visible
|
|
433
|
+
acc = 0
|
|
434
|
+
first = 0
|
|
435
|
+
for i, lbl in enumerate(self.labels):
|
|
436
|
+
acc_next = acc + lbl.height()
|
|
437
|
+
if acc_next >= top:
|
|
438
|
+
first = i
|
|
439
|
+
break
|
|
440
|
+
acc = acc_next
|
|
441
|
+
|
|
442
|
+
# Find last visible
|
|
443
|
+
acc = 0
|
|
444
|
+
last = len(self.labels) - 1
|
|
445
|
+
for j, lbl in enumerate(self.labels):
|
|
446
|
+
acc += lbl.height()
|
|
447
|
+
if acc >= bottom:
|
|
448
|
+
last = j
|
|
449
|
+
break
|
|
450
|
+
|
|
451
|
+
# Prefetch a little around the viewport
|
|
452
|
+
return max(0, first - 1), min(len(self.labels) - 1, last + 1)
|
|
453
|
+
|
|
454
|
+
# ---------- Rendering orchestration ----------
|
|
455
|
+
def _kick_off_visible_render(self, force: bool = False, warm: int = 0):
|
|
456
|
+
"""Render visible pages."""
|
|
457
|
+
if self.page_count is None:
|
|
458
|
+
return
|
|
459
|
+
|
|
460
|
+
first, last = self._visible_window()
|
|
461
|
+
if warm:
|
|
462
|
+
first = max(0, first - warm)
|
|
463
|
+
last = min(self.page_count - 1, last + warm)
|
|
464
|
+
|
|
465
|
+
gen = self._renderGeneration
|
|
466
|
+
for page_num in range(first, last + 1):
|
|
467
|
+
key = (page_num, self.current_zoom)
|
|
468
|
+
if key in self.image_cache and not force:
|
|
469
|
+
# Ensure label shows cached pixmap
|
|
470
|
+
if self.labels[page_num].pixmap() is None:
|
|
471
|
+
self.labels[page_num].setPixmap(self.image_cache[key])
|
|
472
|
+
self.labels[page_num].setText("")
|
|
473
|
+
continue
|
|
474
|
+
|
|
475
|
+
task = RenderTask(self.pdf_path, page_num, self.current_zoom, gen)
|
|
476
|
+
task.signals.finished.connect(self.on_page_rendered, Qt.QueuedConnection)
|
|
477
|
+
self.thread_pool.start(task)
|
|
478
|
+
|
|
479
|
+
# ---------- Render completion ----------
|
|
480
|
+
@Slot(int, float, int, QPixmap)
|
|
481
|
+
def on_page_rendered(self, page_num: int, zoom: float, generation: int, pixmap: QPixmap):
|
|
482
|
+
"""Handle rendered page: update cache and label if still relevant."""
|
|
483
|
+
# Discard outdated renders (other zoom or older generation) or failed pixmaps
|
|
484
|
+
if generation != self._renderGeneration or zoom != self.current_zoom or pixmap.isNull():
|
|
485
|
+
return
|
|
486
|
+
key = (page_num, zoom)
|
|
487
|
+
self.image_cache[key] = pixmap
|
|
488
|
+
lbl = self.labels[page_num]
|
|
489
|
+
lbl.setPixmap(pixmap)
|
|
490
|
+
lbl.setText("")
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Navigation container for report, prediction, image, and interactive results."""
|
|
2
|
+
|
|
3
|
+
from PySide6.QtCore import Signal
|
|
4
|
+
from PySide6.QtWidgets import (
|
|
5
|
+
QComboBox, QFrame, QHBoxLayout, QLabel, QPushButton, QStackedWidget,
|
|
6
|
+
QVBoxLayout, QWidget,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
# dual execution mode (see main/window.py's own import strategy): local/portable first,
|
|
10
|
+
# installed package as fallback
|
|
11
|
+
try:
|
|
12
|
+
from result_navigation import choose_available_result_view
|
|
13
|
+
except ImportError:
|
|
14
|
+
from robert.gui_easyrob.result_navigation import choose_available_result_view
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ResultsWorkspace(QWidget):
|
|
18
|
+
"""Show one result view at a time while keeping each view alive."""
|
|
19
|
+
|
|
20
|
+
availabilityChanged = Signal(bool)
|
|
21
|
+
modelChanged = Signal(object)
|
|
22
|
+
|
|
23
|
+
def __init__(self, report, predictions, images, interactive_plots, parent=None):
|
|
24
|
+
super().__init__(parent)
|
|
25
|
+
layout = QVBoxLayout(self)
|
|
26
|
+
layout.setContentsMargins(10, 10, 10, 10)
|
|
27
|
+
self.model_bar = QWidget()
|
|
28
|
+
model_layout = QHBoxLayout(self.model_bar)
|
|
29
|
+
model_layout.setContentsMargins(0, 0, 0, 0)
|
|
30
|
+
model_layout.addWidget(QLabel("Model"))
|
|
31
|
+
self.model_selector = QComboBox()
|
|
32
|
+
self.model_selector.setMinimumWidth(190)
|
|
33
|
+
self.model_selector.currentIndexChanged.connect(
|
|
34
|
+
lambda index: self.modelChanged.emit(self.current_model())
|
|
35
|
+
)
|
|
36
|
+
model_layout.addWidget(self.model_selector)
|
|
37
|
+
model_layout.addStretch()
|
|
38
|
+
self.model_bar.hide()
|
|
39
|
+
layout.addWidget(self.model_bar)
|
|
40
|
+
selector = QHBoxLayout()
|
|
41
|
+
selector.setSpacing(8)
|
|
42
|
+
self.content = QStackedWidget()
|
|
43
|
+
self.content.setFrameShape(QFrame.StyledPanel)
|
|
44
|
+
self.buttons = {}
|
|
45
|
+
self._available = {}
|
|
46
|
+
for name, widget in (
|
|
47
|
+
("Report", report),
|
|
48
|
+
("Predictions", predictions),
|
|
49
|
+
("Images", images),
|
|
50
|
+
("Interactive plots", interactive_plots),
|
|
51
|
+
):
|
|
52
|
+
button = QPushButton(name)
|
|
53
|
+
button.setCheckable(True)
|
|
54
|
+
button.setEnabled(False)
|
|
55
|
+
button.setMinimumWidth(100)
|
|
56
|
+
button.setStyleSheet(
|
|
57
|
+
"QPushButton:checked { background-color: #4559d8; color: white; "
|
|
58
|
+
"font-weight: 600; }"
|
|
59
|
+
)
|
|
60
|
+
button.clicked.connect(lambda checked=False, view=name: self.show_view(view))
|
|
61
|
+
self.buttons[name] = button
|
|
62
|
+
self._available[name] = False
|
|
63
|
+
selector.addWidget(button)
|
|
64
|
+
self.content.addWidget(widget)
|
|
65
|
+
selector.addStretch()
|
|
66
|
+
layout.addLayout(selector)
|
|
67
|
+
layout.addWidget(self.content, 1)
|
|
68
|
+
|
|
69
|
+
def current_model(self):
|
|
70
|
+
"""Return a model name, or None for ROBERT's best models."""
|
|
71
|
+
return self.model_selector.currentData()
|
|
72
|
+
|
|
73
|
+
def set_models(self, models, preferred=None):
|
|
74
|
+
"""Offer one shared model selector only when additional models exist."""
|
|
75
|
+
models = tuple(models)
|
|
76
|
+
self.model_selector.blockSignals(True)
|
|
77
|
+
self.model_selector.clear()
|
|
78
|
+
if models:
|
|
79
|
+
self.model_selector.addItem("Best models", None)
|
|
80
|
+
for model in models:
|
|
81
|
+
self.model_selector.addItem(model, model)
|
|
82
|
+
if preferred in models:
|
|
83
|
+
self.model_selector.setCurrentIndex(models.index(preferred) + 1)
|
|
84
|
+
self.model_selector.blockSignals(False)
|
|
85
|
+
self.model_bar.setVisible(bool(models))
|
|
86
|
+
|
|
87
|
+
def has_available_views(self):
|
|
88
|
+
"""Whether any result source can be opened."""
|
|
89
|
+
return any(self._available.values())
|
|
90
|
+
|
|
91
|
+
def set_available(self, view, available):
|
|
92
|
+
"""Update a view's availability and select a valid fallback if needed."""
|
|
93
|
+
button = self.buttons[view]
|
|
94
|
+
available = bool(available)
|
|
95
|
+
if self._available[view] == available:
|
|
96
|
+
return
|
|
97
|
+
self._available[view] = available
|
|
98
|
+
button.setEnabled(available)
|
|
99
|
+
selected_name = tuple(self.buttons)[self.content.currentIndex()]
|
|
100
|
+
next_view = choose_available_result_view(
|
|
101
|
+
self._available,
|
|
102
|
+
selected_name,
|
|
103
|
+
any(candidate.isChecked() for candidate in self.buttons.values()),
|
|
104
|
+
)
|
|
105
|
+
if next_view is not None:
|
|
106
|
+
self.show_view(next_view)
|
|
107
|
+
else:
|
|
108
|
+
for candidate in self.buttons.values():
|
|
109
|
+
candidate.setChecked(False)
|
|
110
|
+
self.availabilityChanged.emit(self.has_available_views())
|
|
111
|
+
|
|
112
|
+
def show_view(self, view):
|
|
113
|
+
"""Select an available view; return whether the switch happened."""
|
|
114
|
+
if not self._available[view]:
|
|
115
|
+
return False
|
|
116
|
+
index = list(self.buttons).index(view)
|
|
117
|
+
self.content.setCurrentIndex(index)
|
|
118
|
+
for name, button in self.buttons.items():
|
|
119
|
+
button.setChecked(name == view)
|
|
120
|
+
return True
|