-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_window.py
More file actions
670 lines (590 loc) · 25.9 KB
/
Copy pathmain_window.py
File metadata and controls
670 lines (590 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
"""
OVForge — Main Window
Layout: sidebar filtri | catalog table | detail/action panel
Theme: industriale-tecnico scuro, senza fronzoli Qt di default
"""
import time
from pathlib import Path
from PyQt6.QtWidgets import (
QMainWindow, QWidget, QHBoxLayout, QVBoxLayout, QSplitter,
QStatusBar, QLabel, QPushButton, QMessageBox, QProgressDialog,
QApplication
)
from PyQt6.QtCore import Qt, QThread, pyqtSignal, QTimer
from PyQt6.QtGui import QFont, QIcon
from catalog_panel import CatalogPanel
from detail_panel import DetailPanel
from filter_panel import FilterPanel
from job_panel import JobPanel
from settings_dialog import SettingsDialog
from hf_client import HFClient
from profile_resolver import ProfileResolver
# ── QSS Theme ─────────────────────────────────────────────────────────────────
QSS = """
* {
font-family: "JetBrains Mono", "Fira Mono", "Cascadia Code", "Courier New", monospace;
font-size: 12px;
color: #D4D4D4;
}
QMainWindow, QWidget {
background-color: #0F0F0F;
}
QSplitter::handle {
background: #222;
width: 2px;
height: 2px;
}
QTableView {
background-color: #111;
alternate-background-color: #141414;
border: 1px solid #222;
gridline-color: #1E1E1E;
selection-background-color: #0A2A4A;
selection-color: #5FB3FF;
}
QTableView::item { padding: 3px 6px; }
QTableView::item:selected { color: #5FB3FF; }
QHeaderView::section {
background: #161616;
border: none;
border-right: 1px solid #2A2A2A;
border-bottom: 1px solid #2A2A2A;
padding: 4px 8px;
color: #888;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
QPushButton {
background: #1A1A1A;
border: 1px solid #333;
padding: 6px 14px;
color: #CCC;
}
QPushButton:hover { background: #222; border-color: #555; color: #FFF; }
QPushButton:pressed { background: #0D0D0D; }
QPushButton:disabled { color: #444; border-color: #222; }
QPushButton#btn_primary {
background: #0A2A4A;
border: 1px solid #1A5A9A;
color: #5FB3FF;
font-weight: bold;
}
QPushButton#btn_primary:hover { background: #0D3560; border-color: #2A7ACC; }
QPushButton#btn_primary:disabled { background: #0A1520; color: #334; border-color: #1A2A3A; }
QPushButton#btn_danger {
background: #2A0A0A;
border: 1px solid #6A1A1A;
color: #FF6B6B;
}
QPushButton#btn_danger:hover { background: #3A0D0D; }
QLineEdit, QComboBox {
background: #141414;
border: 1px solid #2A2A2A;
padding: 4px 8px;
color: #CCC;
}
QLineEdit:focus, QComboBox:focus { border-color: #1A5A9A; }
QComboBox::drop-down { border: none; width: 20px; }
QComboBox QAbstractItemView {
background: #161616;
border: 1px solid #333;
selection-background-color: #0A2A4A;
}
QCheckBox {
spacing: 6px;
color: #AAA;
}
QCheckBox::indicator {
width: 13px; height: 13px;
border: 1px solid #444;
background: #111;
}
QCheckBox::indicator:checked {
background: #1A5A9A;
border-color: #5FB3FF;
}
QLabel { color: #C8C8C8; }
QLabel#label_title { color: #5FB3FF; font-size: 22px; font-weight: bold; }
QLabel#label_section { color: #888; font-size: 10px; letter-spacing: 0.1em; }
QLabel#badge_converted { color: #4CAF50; }
QLabel#badge_raw { color: #FF9800; }
QLabel#badge_unknown { color: #FF5252; }
QScrollBar:vertical {
background: #0F0F0F;
width: 8px;
border: none;
}
QScrollBar::handle:vertical { background: #2A2A2A; min-height: 20px; }
QScrollBar::handle:vertical:hover { background: #3A3A3A; }
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { height: 0; }
QProgressBar {
background: #141414;
border: 1px solid #2A2A2A;
height: 6px;
text-align: center;
color: transparent;
}
QProgressBar::chunk { background: #1A5A9A; }
QProgressBar#bar_done::chunk { background: #4CAF50; }
QProgressBar#bar_error::chunk { background: #FF5252; }
QStatusBar { background: #0A0A0A; border-top: 1px solid #1E1E1E; }
QStatusBar QLabel { color: #999; font-size: 10px; }
QGroupBox {
border: 1px solid #1E1E1E;
margin-top: 16px;
padding-top: 8px;
color: #555;
font-size: 10px;
letter-spacing: 0.08em;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 8px;
padding: 0 4px;
}
QSlider::groove:horizontal {
background: #1E1E1E;
height: 4px;
border-radius: 2px;
}
QSlider::handle:horizontal {
background: #1A5A9A;
width: 12px; height: 12px;
border-radius: 6px;
margin: -4px 0;
}
QSlider::sub-page:horizontal { background: #1A5A9A; border-radius: 2px; }
QSplitter::handle:horizontal { background: #1A1A1A; width: 3px; }
QSplitter::handle:horizontal:hover { background: #1A5A9A; }
"""
# ── Worker thread per refresh catalogo ────────────────────────────────────────
class CatalogRefreshWorker(QThread):
progress = pyqtSignal(int, int, str) # current, total, repo_id
finished = pyqtSignal(int) # count aggiornati
error = pyqtSignal(str)
def __init__(self, client: HFClient, force: bool = False):
super().__init__()
self._client = client
self._force = force
self._cancelled = False
def cancel(self):
"""Segnala al thread di fermarsi al prossimo checkpoint."""
self._cancelled = True
def run(self):
try:
def progress_cb(cur, tot, rid):
if self._cancelled:
raise InterruptedError("Refresh annullato dall'utente")
self.progress.emit(cur, tot, rid)
count = self._client.refresh_openvino_catalog(
force=self._force,
progress_cb=progress_cb,
)
self.finished.emit(count)
except InterruptedError:
self.finished.emit(0) # annullato — non è un errore
except Exception as e:
self.error.emit(str(e))
# ── Main Window ───────────────────────────────────────────────────────────────
class MainWindow(QMainWindow):
def __init__(self, client: HFClient, resolver: ProfileResolver,
data_dir: Path):
super().__init__()
self._client = client
self._resolver = resolver
self._data_dir = data_dir
self._refresh_worker: CatalogRefreshWorker | None = None
self.setWindowTitle("OVForge — OpenVINO Model Manager")
self.setMinimumSize(1280, 760)
self.resize(1440, 860)
self._build_ui()
self._apply_theme()
self._connect_signals()
self._update_status_bar()
# auto-refresh se il catalogo è vuoto o scaduto
counts = self._client.catalog_count()
if counts["converted"] == 0:
QTimer.singleShot(500, self._do_refresh_catalog)
# ── Build UI ──────────────────────────────────────────────────────────────
def _build_ui(self):
central = QWidget()
self.setCentralWidget(central)
root_layout = QVBoxLayout(central)
root_layout.setContentsMargins(0, 0, 0, 0)
root_layout.setSpacing(0)
# header bar
header = self._build_header()
root_layout.addWidget(header)
# splitter principale: filtri | catalogo | dettaglio
self._splitter = QSplitter(Qt.Orientation.Horizontal)
self._filter_panel = FilterPanel(self._resolver)
self._catalog_panel = CatalogPanel()
self._detail_panel = DetailPanel(self._resolver)
self._splitter.addWidget(self._filter_panel)
self._splitter.addWidget(self._catalog_panel)
self._splitter.addWidget(self._detail_panel)
self._splitter.setSizes([220, 680, 380])
self._splitter.setStretchFactor(0, 0)
self._splitter.setStretchFactor(1, 1)
self._splitter.setStretchFactor(2, 0)
root_layout.addWidget(self._splitter, stretch=1)
# job panel (bottom, collassabile)
self._job_panel = JobPanel()
root_layout.addWidget(self._job_panel)
# status bar
self._status_bar = QStatusBar()
self.setStatusBar(self._status_bar)
self._lbl_status = QLabel("")
self._lbl_catalog_info = QLabel("")
self._status_bar.addWidget(self._lbl_status)
self._status_bar.addPermanentWidget(self._lbl_catalog_info)
def _build_header(self) -> QWidget:
header = QWidget()
header.setFixedHeight(68)
header.setObjectName("header")
header.setStyleSheet("#header { background: #080808; border-bottom: 1px solid #1A1A1A; }")
layout = QHBoxLayout(header)
layout.setContentsMargins(16, 0, 16, 0)
layout.setSpacing(0)
# icona PNG se disponibile, altrimenti emoji
icon_path = Path(__file__).parent / "assets" / "ovforge_256.png"
if icon_path.exists():
from PyQt6.QtGui import QPixmap
lbl_icon = QLabel()
lbl_icon.setPixmap(
QPixmap(str(icon_path)).scaled(
40, 40,
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation,
)
)
lbl_icon.setFixedSize(40, 40)
layout.addWidget(lbl_icon)
layout.addSpacing(10)
# blocco testo: OVForge + sottotitolo
text_col = QVBoxLayout()
text_col.setSpacing(1)
text_col.setContentsMargins(0, 0, 0, 0)
lbl_logo = QLabel("OVForge")
lbl_logo.setObjectName("label_title")
lbl_logo.setFont(QFont("JetBrains Mono", 22, QFont.Weight.Bold))
lbl_logo.setStyleSheet(
"color: #5FB3FF; font-size: 22px; font-weight: bold;"
"text-shadow: 0px 0px 8px #1A5A9A;" # non supportato da Qt ma innocuo
)
lbl_sub = QLabel("OpenVINO Model Manager")
lbl_sub.setStyleSheet(
"color: #5f2485; font-size: 13px; font-weight: bold; letter-spacing: 0.04em;"
)
text_col.addWidget(lbl_logo)
text_col.addWidget(lbl_sub)
layout.addLayout(text_col)
layout.addStretch()
self._btn_refresh = QPushButton("↻ Aggiorna Catalogo")
self._btn_refresh.setFixedWidth(180)
self._btn_cache = QPushButton("📁 Cache Locale")
self._btn_cache.setFixedWidth(130)
self._btn_cache.setToolTip("Gestisci modelli scaricati e convertiti")
self._btn_settings = QPushButton("⚙")
self._btn_settings.setFixedWidth(36)
self._btn_settings.setToolTip("Impostazioni")
layout.addWidget(self._btn_refresh)
layout.addSpacing(6)
layout.addWidget(self._btn_cache)
layout.addSpacing(6)
layout.addWidget(self._btn_settings)
return header
def _apply_theme(self):
QApplication.instance().setStyleSheet(QSS)
# ── Signal connections ────────────────────────────────────────────────────
def _connect_signals(self):
self._btn_refresh.clicked.connect(lambda: self._do_refresh_catalog(force=True))
self._btn_settings.clicked.connect(self._open_settings)
self._btn_cache.clicked.connect(self._open_cache_panel)
# filtri → aggiorna query catalogo
self._filter_panel.filters_changed.connect(self._apply_filters)
# selezione riga catalogo → popola detail panel
self._catalog_panel.model_selected.connect(self._on_model_selected)
# doppio click catalogo → apre readme viewer
self._catalog_panel.model_readme_requested.connect(self._on_readme_requested)
# detail panel → avvia job
self._detail_panel.download_requested.connect(self._on_download_requested)
self._detail_panel.conversion_requested.connect(self._on_conversion_requested)
self._detail_panel.size_resolve_requested.connect(self._on_resolve_size)
self._job_panel.test_requested.connect(self._on_test_requested)
self._job_panel.conversion_active_changed.connect(
self._detail_panel.set_conversion_active
)
# propaga token HF e cartella base al detail panel subito
self._detail_panel.set_hf_token(self._client.get_hf_token())
self._detail_panel.set_base_dir(self._client.get_output_base_dir())
# applica env override al conversion engine
self._apply_env_settings()
# ── Refresh catalogo ──────────────────────────────────────────────────────
def _do_refresh_catalog(self, force: bool = False):
if self._refresh_worker and self._refresh_worker.isRunning():
return
dlg = QProgressDialog(
"Aggiornamento catalogo OpenVINO...", "Annulla", 0, 0, self
)
dlg.setWindowModality(Qt.WindowModality.WindowModal)
dlg.setMinimumDuration(0)
dlg.show()
self._btn_refresh.setEnabled(False)
self._refresh_worker = CatalogRefreshWorker(self._client, force=force)
def on_progress(cur, tot, rid):
if tot > 0:
dlg.setMaximum(tot)
dlg.setValue(cur)
dlg.setLabelText(f"Fetching {rid}…")
if dlg.wasCanceled():
self._refresh_worker.cancel() # cancelled flag — no terminate()
def on_finished(count):
dlg.close()
self._btn_refresh.setEnabled(True)
self._apply_filters()
self._update_status_bar()
if count > 0:
self._lbl_status.setText(f"Catalogo aggiornato — {count} modelli")
def on_error(msg):
dlg.close()
self._btn_refresh.setEnabled(True)
QMessageBox.warning(self, "Errore refresh", msg)
self._refresh_worker.progress.connect(on_progress)
self._refresh_worker.finished.connect(on_finished)
self._refresh_worker.error.connect(on_error)
self._refresh_worker.start()
# ── Filtri → query ────────────────────────────────────────────────────────
def _apply_filters(self):
f = self._filter_panel.current_filters()
is_converted = f.get("is_converted")
search_text = f.get("search_text", "")
# "Da convertire" + testo → ricerca live HF (transformers + onnx)
# "Da convertire" senza testo → mostra raw già in cache locale
# "IR OpenVINO" o "Tutti" → sempre e solo catalogo locale, qualunque cosa
if is_converted is False and search_text.strip():
self._do_raw_search(search_text.strip(), f)
return
entries = self._client.query_catalog(
is_converted = is_converted,
category = f.get("category"),
quant_formats = f.get("quant_formats") or None,
param_min = f.get("param_min", 0.0),
param_max = f.get("param_max", 1000.0),
size_min_gb = f.get("size_min_gb", 0.0),
size_max_gb = f.get("size_max_gb", 9999.0),
search_text = search_text,
)
self._catalog_panel.load_entries(entries)
src_label = {None: "modelli", True: "IR OpenVINO", False: "raw in cache"}
self._lbl_status.setText(f"{len(entries)} {src_label.get(is_converted, 'modelli')}")
def _do_raw_search(self, query: str, f: dict):
"""Ricerca live su HF per modelli raw. Gira in QThread."""
# cancella il worker precedente se ancora in esecuzione
if hasattr(self, "_raw_worker") and self._raw_worker.isRunning():
self._raw_worker._cancelled = True
# non aspettiamo: il vecchio risultato sarà ignorato dal guard sotto
self._raw_worker_query = query # traccia la query più recente
self._raw_worker_query = query
self._lbl_status.setText(f"Ricerca HF: '{query}'…")
class RawSearchWorker(QThread):
done = pyqtSignal(list, str) # entries, query emessa
def __init__(self, client, q):
super().__init__()
self._client = client
self._q = q
self._cancelled = False
def run(self):
results = self._client.search_raw_models(self._q, limit=80)
self.done.emit(results, self._q)
worker = RawSearchWorker(self._client, query)
def on_done(entries, emitted_query):
# scarta risultati stale se nel frattempo è partita una nuova ricerca
if emitted_query != self._raw_worker_query:
return
filtered = [e for e in entries if self._apply_local_filters(e, f)]
self._catalog_panel.load_entries(filtered)
self._lbl_status.setText(f"{len(filtered)} modelli raw (da HF)")
worker.done.connect(on_done)
worker.start()
self._raw_worker = worker # keepalive + riferimento per prossima cancellazione
def _apply_local_filters(self, e, f: dict) -> bool:
"""Filtra un ModelEntry con i criteri locali (categoria, param, size)."""
cat = f.get("category")
if cat and e.category != cat:
return False
qf = f.get("quant_formats")
if qf and e.quant_format not in qf:
return False
p_min = f.get("param_min", 0.0)
p_max = f.get("param_max", 1000.0)
if p_min > 0 or p_max < 1000.0:
b = e.param_billions
if b >= 0 and not (p_min <= b <= p_max):
return False
# filtro size: modelli senza size risolta (-1.0) passano sempre
# (non abbiamo i dati per escluderli)
s_min = f.get("size_min_gb", 0.0)
s_max = f.get("size_max_gb", 9999.0)
if e.size_gb > 0:
if s_min > 0 and e.size_gb < s_min:
return False
if s_max < 9999.0 and e.size_gb > s_max:
return False
return True
# ── Selezione modello ─────────────────────────────────────────────────────
def _on_model_selected(self, repo_id: str):
entry = self._client.get_model(repo_id)
if not entry:
return
profile = self._resolver.resolve(entry.architecture, entry.repo_id)
self._detail_panel.load(entry, profile)
# size resolve automatico al click — se non già in cache
if entry.size_gb <= 0:
self._on_resolve_size(repo_id)
# ── Size resolve lazy ─────────────────────────────────────────────────────
def _on_resolve_size(self, repo_id: str):
"""Risolve size in un thread separato, aggiorna il catalogo."""
class SizeWorker(QThread):
done = pyqtSignal(str, float)
def __init__(self, client, rid):
super().__init__()
self._client = client
self._rid = rid
def run(self):
gb = self._client.resolve_size(self._rid)
self.done.emit(self._rid, gb)
w = SizeWorker(self._client, repo_id)
w.done.connect(lambda rid, gb: self._on_size_resolved(rid, gb))
w.start()
# keepalive: accumula worker attivi, pulisce quelli terminati
if not hasattr(self, "_size_workers"):
self._size_workers = []
self._size_workers = [x for x in self._size_workers if x.isRunning()]
self._size_workers.append(w)
def _on_size_resolved(self, repo_id: str, gb: float):
entry = self._client.get_model(repo_id)
if entry:
entry.size_gb = gb
self._detail_panel.update_size(gb)
self._catalog_panel.update_size(repo_id, gb)
# ── Download / Conversione ────────────────────────────────────────────────
def _on_download_requested(self, repo_id: str, output_dir: str):
token = self._client.get_hf_token()
self._job_panel.add_download_job(repo_id, Path(output_dir), token)
# persisti la cartella base (parent di output_dir)
base = str(Path(output_dir).parent)
self._client.set_output_base_dir(base)
def _on_conversion_requested(self, repo_id: str, cli_args: list, output_dir: str):
import uuid
from conversion_engine import ConversionJob
job = ConversionJob(
job_id = str(uuid.uuid4())[:8],
repo_id = repo_id,
output_dir = Path(output_dir),
cli_args = cli_args,
)
self._job_panel.add_conversion_job(job)
# persisti la cartella base (parent di output_dir)
base = str(Path(output_dir).parent)
self._client.set_output_base_dir(base)
def _on_test_requested(self, output_dir: str, repo_id: str):
from inference_tester import InferenceTestDialog
entry = self._client.get_model(repo_id)
category = entry.category if entry else "llm_chat"
dlg = InferenceTestDialog(output_dir, repo_id, category, parent=self)
dlg.exec()
# ── Cache Panel ───────────────────────────────────────────────────────────
def _open_cache_panel(self):
from cache_panel import CachePanel
last_dir = self._client.get_cache_scan_dir()
dlg = CachePanel(
hf_token = self._client.get_hf_token(),
last_dir = last_dir,
parent = self,
)
dlg.test_requested.connect(self._on_test_requested)
dlg.download_requested.connect(self._on_download_requested)
dlg.convert_requested.connect(self._on_convert_local_requested)
dlg.exec()
# persiste la cartella scansionata
self._client.set_cache_scan_dir(dlg.get_scan_dir())
def _on_convert_local_requested(self, local_path: str, repo_id: str):
"""
Dal CachePanel: apre il detail panel con il modello locale.
Se repo_id è noto cerca il profilo, altrimenti usa profilo generico.
Il CLI userà --model /path/locale invece di repo_id HF.
"""
from hf_client import ModelEntry
from pathlib import Path as _Path
import json
path = _Path(local_path)
# leggi config.json per architettura e categoria
cfg = {}
cfg_path = path / "config.json"
if cfg_path.exists():
try:
with open(cfg_path) as f:
cfg = json.load(f)
except Exception:
pass
archs = cfg.get("architectures") or []
arch = archs[0] if archs else ""
# costruisci un ModelEntry sintetico per il detail panel
entry = self._client.get_model(repo_id) if repo_id else None
if not entry:
from cache_manager import _guess_category
entry = ModelEntry(
repo_id = local_path, # path locale come repo_id
author = "locale",
model_name = path.name,
is_converted = False,
architecture = arch,
category = _guess_category(cfg),
quant_format = "safetensors",
param_billions = -1.0,
size_gb = -1.0,
)
profile = self._resolver.resolve(arch, repo_id or path.name)
self._detail_panel.load(entry, profile)
# sovrascrive il repo_id nell'entry con il path locale
# così build_cli_args userà --model /path/locale
entry.repo_id = local_path
# ── Settings ──────────────────────────────────────────────────────────────
def _apply_env_settings(self):
"""Legge i path env da SQLite e li propaga al conversion engine."""
from conversion_engine import set_env_override
set_env_override(
cli_path = self._client.get_env_cli_path() or None,
py_path = self._client.get_env_python_path() or None,
)
def _open_settings(self):
dlg = SettingsDialog(self._client, self)
dlg.exec()
self._detail_panel.set_hf_token(self._client.get_hf_token())
self._detail_panel.set_base_dir(self._client.get_output_base_dir())
# riapplica eventuali nuovi path env
self._apply_env_settings()
# ── README viewer (da doppio click o context menu catalogo) ──────────────
def _on_readme_requested(self, repo_id: str):
from readme_viewer import ReadmeViewer
token = self._client.get_hf_token() or None
dlg = ReadmeViewer(repo_id, hf_token=token, parent=self)
dlg.show()
# ── Status bar ────────────────────────────────────────────────────────────
def _update_status_bar(self):
counts = self._client.catalog_count()
last_ts = self._client.last_refresh_ts()
if last_ts:
age_h = (time.time() - last_ts) / 3600
age_str = f"{age_h:.1f}h fa"
else:
age_str = "mai"
self._lbl_catalog_info.setText(
f"Catalogo: {counts['converted']} convertiti | "
f"{counts['raw']} raw · Aggiornato {age_str}"
)
def closeEvent(self, event):
self._client.close()
event.accept()