Hồi quy đã vá
-------------
F-12 Kéo–thả hoặc dán tệp vào ô chat ném NameError. R08 tách `_Input` sang
`chat_input_box.py` nhưng để `_paths_from_mime()` ở lại
`composer_widget.py`, nên hai hàm sự kiện Qt gọi một cái tên không tồn
tại. Bốn hàm dùng chung chuyển sang `composer_mime.py` — module thứ ba
là chỗ duy nhất không lặp lại được lỗi này. Đo lại: cả thả lẫn dán đều
gắn 1 tệp, khớp bản trước refactor.
F-01 Đổi provider thì bộ chọn model AI-Edit không làm gì. Hook cũ kiểm
`folder.ai_model_combo`, thuộc tính R08-T12 đã dời sang
`ai_panel.resolver`. Làm mới vô điều kiện, đúng như tab cũ: lần lấy đầu
tiên hỏng thì đổi provider chính là lúc phải thử lại.
F-07 Hàng chọn kỳ của Dashboard bị đẩy xuống dưới các thẻ số liệu. Hàng này
lọc CẢ BA thẻ con chứ không riêng biểu đồ, nên để nó nằm dưới là bắt
người dùng đọc con số trước khi thấy con số đó tính cho kỳ nào. Kèm
theo: `TokenUsageCardWidget` bị bỏ sót `setContentsMargins(0,0,0,0)`
mà hai thẻ con còn lại đã có, đẩy cả hàng thẻ lệch 9px.
`check_layout_geometry` nay khớp TỪNG BYTE với bản trước refactor.
F-11 Hai lớp khai trùng tên phương thức; Python giữ bản sau nên bản đầu là
mã chết. `co4e_tab.py::showEvent` bản đầu gọi `_narrow_guard.attach()`
và không bao giờ chạy.
Tách file (F-09)
----------------
Bốn file chạm trần 400 dòng, mỗi lần cắt ra một trách nhiệm thật:
graph_renderer.py -> graph_scene_builder.py + graph_export.py
co4e_workflow_service.py -> co4e_run_history.py
json_config_repository.py -> config_sections.py
agents_admin_tab.py -> shared/agent_kind_visuals.py
File cuối còn xoá 3 bản sao của hàm đã có trong `shared/formatters.py`,
giống hệt đến từng dòng — nay định dạng thời gian và avatar không lệch nhau
giữa các bảng Giám sát nữa.
Docstring
---------
41,6% -> 100% (3.478/3.478 định nghĩa production), kể cả module dormant và
phương thức dunder. Toàn bộ phần bổ sung viết bằng tiếng Việt; comment tiếng
Anh có sẵn giữ nguyên — dịch ngược là một đợt riêng.
Seam chưa nối dây (F-05)
------------------------
9 seam mang nhãn `SEAM · dựng <ngày>` kèm hai câu: được nối khi nào, và để
dormant thì hỏng gì. Ngày lấy từ lịch sử git, không phải hạn tự đặt. Gate O
đọc nhãn đó và nhắc khi quá 30 ngày.
859 test xanh · 4/4 cổng CASAN · 19/24 checker khớp từng byte bản cũ.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
170 lines
7.0 KiB
Python
170 lines
7.0 KiB
Python
"""Icons — a Monitoring sub-tab to browse the built-in icon set and add custom
|
|
icons for agents / flows.
|
|
|
|
Shows the built-in glyphs (the names usable in a Co4E step/agent ``icon`` field)
|
|
and the user's own imported SVG icons, with Add / Delete. Custom icons are saved
|
|
via ``core/custom_icons.py`` and become usable by name immediately.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from PySide6.QtCore import QSize, Qt
|
|
from PySide6.QtWidgets import (
|
|
QHBoxLayout, QInputDialog, QLabel, QLineEdit, QListWidget, QListWidgetItem,
|
|
QMessageBox, QPushButton, QVBoxLayout, QWidget,
|
|
)
|
|
|
|
from ..core import custom_icons
|
|
from ..i18n import on_language_changed, tr
|
|
from ..state import AppContext
|
|
from . import icons as icons_mod
|
|
from .icons import icon
|
|
|
|
|
|
def _grid() -> QListWidget:
|
|
"""Dựng lưới hiển thị icon dạng ô vuông có nhãn."""
|
|
g = QListWidget()
|
|
g.setObjectName("iconGrid") # accent border on hover/selection, see theme.py
|
|
g.setViewMode(QListWidget.IconMode)
|
|
g.setResizeMode(QListWidget.Adjust)
|
|
g.setMovement(QListWidget.Static)
|
|
g.setIconSize(QSize(28, 28))
|
|
g.setGridSize(QSize(96, 74))
|
|
g.setSpacing(4)
|
|
return g
|
|
|
|
|
|
class IconsAdminTab(QWidget):
|
|
"""Tab "Icon" trong màn Giám sát: xem bộ icon hệ thống và thay icon bằng ảnh riêng."""
|
|
def __init__(self, ctx: AppContext):
|
|
"""Tab quản trị biểu tượng: bộ dựng sẵn và bộ tự thêm.
|
|
|
|
Ba nút thao tác nằm cạnh tiêu đề chứ không nằm dưới hai lưới — đặt dưới thì
|
|
chúng trông như chỉ áp cho lưới tự thêm.
|
|
"""
|
|
super().__init__()
|
|
self.ctx = ctx
|
|
root = QVBoxLayout(self)
|
|
# Header row: the three actions sit beside the title, where the drawing
|
|
# puts them, instead of in a strip below the two grids where they read
|
|
# as belonging to the custom grid alone.
|
|
head = QHBoxLayout()
|
|
self._title = QLabel()
|
|
self._title.setObjectName("monTitle")
|
|
head.addWidget(self._title)
|
|
head.addStretch(1)
|
|
self.add_btn = QPushButton(); self.add_btn.setIcon(icon("plus"))
|
|
self.add_btn.clicked.connect(self._add_icon)
|
|
self.paste_btn = QPushButton()
|
|
self.paste_btn.clicked.connect(self._add_from_svg_text)
|
|
self.del_btn = QPushButton(); self.del_btn.setIcon(icon("trash"))
|
|
self.del_btn.clicked.connect(self._delete_icon)
|
|
for b in (self.add_btn, self.paste_btn, self.del_btn):
|
|
head.addWidget(b)
|
|
root.addLayout(head)
|
|
|
|
self._hint = QLabel(); self._hint.setObjectName("hint"); self._hint.setWordWrap(True)
|
|
root.addWidget(self._hint)
|
|
|
|
# search over built-in names, with the magnifier the drawing asks for
|
|
self.search = QLineEdit()
|
|
self.search.addAction(icon("search"), QLineEdit.LeadingPosition)
|
|
self.search.textChanged.connect(self._reload_builtin)
|
|
root.addWidget(self.search)
|
|
|
|
self._builtin_lbl = QLabel()
|
|
self._builtin_lbl.setObjectName("navSectionHdr") # quiet caps heading
|
|
root.addWidget(self._builtin_lbl)
|
|
self.builtin_grid = _grid()
|
|
root.addWidget(self.builtin_grid, 2)
|
|
|
|
self._custom_lbl = QLabel()
|
|
self._custom_lbl.setObjectName("navSectionHdr")
|
|
root.addWidget(self._custom_lbl)
|
|
self.custom_grid = _grid()
|
|
root.addWidget(self.custom_grid, 1)
|
|
|
|
on_language_changed(self._retranslate)
|
|
self._retranslate()
|
|
|
|
# ---- rendering --------------------------------------------------------
|
|
def _reload_builtin(self, *_a) -> None:
|
|
"""Nạp lại lưới icon dựng sẵn, lọc theo ô tìm kiếm."""
|
|
q = self.search.text().strip().lower()
|
|
self.builtin_grid.clear()
|
|
for name in sorted(icons_mod._PATHS):
|
|
if q and q not in name:
|
|
continue
|
|
it = QListWidgetItem(icon(name), name)
|
|
it.setToolTip(name)
|
|
it.setTextAlignment(Qt.AlignHCenter | Qt.AlignBottom)
|
|
self.builtin_grid.addItem(it)
|
|
|
|
def _reload_custom(self) -> None:
|
|
"""Nạp lại lưới icon do người dùng thêm."""
|
|
self.custom_grid.clear()
|
|
for name in custom_icons.list_custom():
|
|
it = QListWidgetItem(icon(name), name)
|
|
it.setToolTip(name)
|
|
it.setData(Qt.UserRole, name)
|
|
it.setTextAlignment(Qt.AlignHCenter | Qt.AlignBottom)
|
|
self.custom_grid.addItem(it)
|
|
|
|
# ---- actions ----------------------------------------------------------
|
|
def _add_icon(self) -> None:
|
|
"""Thêm icon mới từ một tệp SVG."""
|
|
from PySide6.QtWidgets import QFileDialog
|
|
path, _ = QFileDialog.getOpenFileName(self, tr("icons_admin.add"), "", "SVG (*.svg)")
|
|
if not path:
|
|
return
|
|
name, ok = QInputDialog.getText(self, tr("icons_admin.name_prompt"),
|
|
tr("icons_admin.name_prompt"))
|
|
if not ok:
|
|
return
|
|
try:
|
|
custom_icons.add_from_file(path, name.strip())
|
|
except (OSError, ValueError) as exc:
|
|
QMessageBox.warning(self, tr("icons_admin.title"), str(exc))
|
|
return
|
|
self._reload_custom()
|
|
|
|
def _add_from_svg_text(self) -> None:
|
|
"""Thêm icon bằng cách dán thẳng mã SVG."""
|
|
name, ok = QInputDialog.getText(self, tr("icons_admin.name_prompt"),
|
|
tr("icons_admin.name_prompt"))
|
|
if not ok or not name.strip():
|
|
return
|
|
svg, ok = QInputDialog.getMultiLineText(self, tr("icons_admin.paste"),
|
|
tr("icons_admin.paste_prompt"))
|
|
if not ok:
|
|
return
|
|
try:
|
|
custom_icons.add_svg(name.strip(), svg)
|
|
except ValueError as exc:
|
|
QMessageBox.warning(self, tr("icons_admin.title"), str(exc))
|
|
return
|
|
self._reload_custom()
|
|
|
|
def _delete_icon(self) -> None:
|
|
"""Xoá icon tự thêm đang chọn; chưa chọn gì thì nhắc người dùng."""
|
|
item = self.custom_grid.currentItem()
|
|
if item is None:
|
|
QMessageBox.information(self, tr("icons_admin.title"), tr("icons_admin.select_custom"))
|
|
return
|
|
custom_icons.delete_custom(item.data(Qt.UserRole))
|
|
self._reload_custom()
|
|
|
|
def _retranslate(self) -> None:
|
|
"""Áp lại chữ theo ngôn ngữ đang chọn."""
|
|
self._title.setText(tr("monitoring.tab_icons"))
|
|
self._hint.setText(tr("icons_admin.hint"))
|
|
self.search.setPlaceholderText(tr("icons_admin.search"))
|
|
# ICON TÍCH HỢP / ICON TÙY CHỈNH — caps, like every other section
|
|
# heading the audit page draws.
|
|
self._builtin_lbl.setText(tr("icons_admin.builtin").upper())
|
|
self._custom_lbl.setText(tr("icons_admin.custom").upper())
|
|
self.add_btn.setText(tr("icons_admin.add"))
|
|
self.paste_btn.setText(tr("icons_admin.paste"))
|
|
self.del_btn.setText(tr("icons_admin.delete"))
|
|
self._reload_builtin()
|
|
self._reload_custom()
|