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
|
from __future__ import annotations
from PyQt6.QtWidgets import (
QWidget, QVBoxLayout, QHBoxLayout, QTabWidget,
QListWidget, QListWidgetItem, QLabel, QPushButton,
)
from PyQt6.QtCore import Qt, pyqtSignal
from PyQt6.QtGui import QColor
from core.models import Article
class ArticleItem(QListWidgetItem):
def __init__(self, article: Article):
super().__init__()
self.article = article
lang_other = "EN" if article.lang == "it" else "IT"
if article.has_translation:
badge = f"🇬🇧 ✓" if article.lang == "it" else "🇮🇹 ✓"
status = f"{article.slug} [{badge}]"
else:
badge = f"🇬🇧 ✗" if article.lang == "it" else "🇮🇹 ✗"
status = f"{article.slug} [{badge}]"
self.setText(status)
if not article.has_translation:
self.setForeground(QColor("#ff6b6b"))
class ArticlesView(QWidget):
article_selected = pyqtSignal(object) # Article
translate_requested = pyqtSignal(object) # Article
def __init__(self, parent=None):
super().__init__(parent)
self._articles: list[Article] = []
self._build_ui()
def _build_ui(self):
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
self._tabs = QTabWidget()
self._tabs.setStyleSheet("QTabBar::tab { padding: 6px 16px; }")
self._list_it = QListWidget()
self._list_en = QListWidget()
self._tabs.addTab(self._list_it, "🇮🇹 Italiano")
self._tabs.addTab(self._list_en, "🇬🇧 English")
layout.addWidget(self._tabs)
self._list_it.itemClicked.connect(lambda item: self.article_selected.emit(item.article))
self._list_en.itemClicked.connect(lambda item: self.article_selected.emit(item.article))
def set_articles(self, articles: list[Article]):
self._articles = articles
self._list_it.clear()
self._list_en.clear()
for a in articles:
item = ArticleItem(a)
if a.lang == "it":
self._list_it.addItem(item)
else:
self._list_en.addItem(item)
class MissingTranslationView(QWidget):
article_selected = pyqtSignal(object) # Article
translate_requested = pyqtSignal(object) # Article
def __init__(self, parent=None):
super().__init__(parent)
self._build_ui()
def _build_ui(self):
layout = QVBoxLayout(self)
header = QLabel("⚠️ Articoli senza traduzione")
header.setStyleSheet("color: #ff6b6b; font-weight: bold; font-size: 13px; padding: 10px;")
layout.addWidget(header)
self._list = QListWidget()
layout.addWidget(self._list)
self._list.itemClicked.connect(lambda item: self.article_selected.emit(item.article))
def set_articles(self, articles: list[Article]):
self._list.clear()
missing = [a for a in articles if not a.has_translation]
for a in missing:
lang_other = "🇬🇧" if a.lang == "it" else "🇮🇹"
item = ArticleItem(a)
item.setText(f"{a.slug} [manca {lang_other}] ({a.lang.upper()})")
self._list.addItem(item)
|