""" ValutazioniExtraGemmaDialog — replica del form VBA "MyICR - Valutazioni Reti extra Gemma". Layout: Ambito + 12 reti in riga orizzontale unica, NO ICR + motivazione sotto. """ from PyQt6.QtWidgets import ( QDialog, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QComboBox, QLineEdit, QCheckBox, QPushButton, QFrame, QScrollArea, QWidget, ) from PyQt6.QtGui import QFont from PyQt6.QtCore import Qt _NETWORKS = ['C5', 'I1', 'R4', 'LA5', 'I2', 'IRIS', 'TOPCRIME', 'FOCUS', 'C20', 'CINE34', 'TWENTYS'] _NETWORK_KEYS = ['C5', 'I1', 'R4', 'LA5', 'I2', 'IRIS', 'TOPCRIME', 'FOCUS', 'C20', 'CINE34', 'TWENTYSEVEN'] _VALORI = [ '', '!', 'PT G', 'PT S', 'PT E', 'SS G', 'SS S', 'SS E', 'AP G', 'AP S', 'AP E', 'PO G', 'PO S', 'PO E', 'MA', 'DT', 'NOTTE', 'NO', 'VV PT', 'VV SS', 'VV AP', 'VV PO', 'VV MA', ] _FONT = QFont('Calibri', 10) _FONT_HDR = QFont('Calibri', 10, QFont.Weight.Bold) class ValutazioniExtraGemmaDialog(QDialog): def __init__(self, imdb: str, titolo: str, ambito: str, existing: dict | None, parent=None): super().__init__(parent) self._imdb = imdb self._ambito = ambito self._result: dict | None = None self.setWindowTitle('MyICR - Valutazioni Reti extra Gemma') self.setModal(True) root = QVBoxLayout(self) root.setSpacing(6) root.setContentsMargins(10, 8, 10, 8) # ── Titolo IMDB ──────────────────────────────────────────────── lbl_title = QLabel(f'{imdb} — {titolo}') lbl_title.setFont(QFont('Calibri', 11, QFont.Weight.Bold)) lbl_title.setStyleSheet('color: #1F4E79;') root.addWidget(lbl_title) # ── Riga header + combo reti ─────────────────────────────────── # Scroll orizzontale per adattarsi a schermi piccoli scroll = QScrollArea() scroll.setWidgetResizable(True) scroll.setFrameShape(QFrame.Shape.NoFrame) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) scroll.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) scroll.setFixedHeight(64) inner = QWidget() grid = QGridLayout(inner) grid.setHorizontalSpacing(4) grid.setVerticalSpacing(2) grid.setContentsMargins(0, 0, 0, 0) # Colonna 0: Ambito lbl_amb = QLabel('') # header vuoto sopra Ambito lbl_amb.setFont(_FONT_HDR) lbl_amb.setAlignment(Qt.AlignmentFlag.AlignHCenter) grid.addWidget(lbl_amb, 0, 0) self._cmb_ambito = QComboBox() self._cmb_ambito.setFont(_FONT) self._cmb_ambito.addItems(['OTT', 'Linker']) idx_a = self._cmb_ambito.findText(ambito) if idx_a >= 0: self._cmb_ambito.setCurrentIndex(idx_a) self._cmb_ambito.setFixedWidth(72) grid.addWidget(self._cmb_ambito, 1, 0) # Colonne 1..12: reti self._combos: dict[str, QComboBox] = {} for i, (label, key) in enumerate(zip(_NETWORKS, _NETWORK_KEYS)): col = i + 1 lbl = QLabel(label) lbl.setFont(_FONT_HDR) lbl.setAlignment(Qt.AlignmentFlag.AlignHCenter) grid.addWidget(lbl, 0, col) cmb = QComboBox() cmb.setFont(_FONT) cmb.addItems(_VALORI) cmb.setFixedWidth(60) if existing: val = existing.get(key) or '' idx = cmb.findText(val) if idx >= 0: cmb.setCurrentIndex(idx) self._combos[key] = cmb grid.addWidget(cmb, 1, col) scroll.setWidget(inner) root.addWidget(scroll) # ── Separatore ──────────────────────────────────────────────── sep = QFrame() sep.setFrameShape(QFrame.Shape.HLine) sep.setStyleSheet('color: #CCCCCC;') root.addWidget(sep) # ── NO ICR ──────────────────────────────────────────────────── row_noicr = QHBoxLayout() self._chk_noicr = QCheckBox('NO ICR - motivazione:') self._chk_noicr.setFont(_FONT) if existing: self._chk_noicr.setChecked(bool(existing.get('NoIcr'))) row_noicr.addWidget(self._chk_noicr) self._txt_motivazione = QLineEdit() self._txt_motivazione.setFont(_FONT) if existing: self._txt_motivazione.setText(existing.get('NoIcrMotivazione') or '') self._txt_motivazione.textChanged.connect( lambda t: self._chk_noicr.setChecked(bool(t.strip())) ) row_noicr.addWidget(self._txt_motivazione) root.addLayout(row_noicr) # ── Bottoni ─────────────────────────────────────────────────── btn_row = QHBoxLayout() btn_row.addStretch() btn_cancel = QPushButton('Annulla') btn_cancel.setFont(_FONT) btn_cancel.setFixedWidth(75) btn_cancel.setStyleSheet( 'QPushButton { background: #E0E0E0; border-radius: 3px; padding: 3px; }' 'QPushButton:hover { background: #C0C0C0; }' ) btn_cancel.clicked.connect(self.reject) btn_row.addWidget(btn_cancel) btn_save = QPushButton('Salva') btn_save.setFont(QFont('Calibri', 10, QFont.Weight.Bold)) btn_save.setFixedWidth(75) btn_save.setDefault(True) btn_save.setStyleSheet( 'QPushButton { background: #2E74B5; color: white; border-radius: 3px; padding: 3px; }' 'QPushButton:hover { background: #1F5C9A; }' ) btn_save.clicked.connect(self._on_save) btn_row.addWidget(btn_save) root.addLayout(btn_row) # larghezza minima per vedere tutte le reti senza scroll self.setMinimumWidth(860) def _on_save(self): data: dict = {} for key, cmb in self._combos.items(): v = cmb.currentText().strip() data[key] = v if v else None data['NoIcrMotivazione'] = self._txt_motivazione.text().strip() or None data['NoIcr'] = 1 if self._chk_noicr.isChecked() else 0 self._result = data self.accept() @property def result_data(self) -> dict | None: return self._result