feat: simplify secondary pages with contextual controls and advanced options
This commit is contained in:
1 parent
d6df3f99fb
commit
717129c844
8 files changed
+350
-161
No files matched your search
@@ -9,6 +9,7 @@ from PySide6.QtWidgets import (
|
||||
QComboBox,
|
||||
QFileDialog,
|
||||
QHBoxLayout,
|
||||
QHeaderView,
|
||||
QLabel,
|
||||
QPushButton,
|
||||
QRadioButton,
|
||||
@@ -18,6 +19,7 @@ from PySide6.QtWidgets import (
|
||||
)
|
||||
|
||||
from dx_productivity.features.bom import BOMResult, BOMSettings
|
||||
from dx_productivity.ui.collapsible_section import CollapsibleSection
|
||||
|
||||
|
||||
class BomPage(QWidget):
|
||||
@@ -30,16 +32,8 @@ class BomPage(QWidget):
|
||||
|
||||
def _build_ui(self) -> None:
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(20, 16, 20, 16)
|
||||
layout.setSpacing(10)
|
||||
|
||||
hint = QLabel(
|
||||
"BOM 导出:按页分组、合并同料号、NC 过滤与创维料号校验全部在本地完成;"
|
||||
"点击导出后由 DxDesigner 宿主调用 Excel 按模板输出。"
|
||||
)
|
||||
hint.setObjectName("secondaryLabel")
|
||||
hint.setWordWrap(True)
|
||||
layout.addWidget(hint)
|
||||
layout.setContentsMargins(12, 10, 12, 10)
|
||||
layout.setSpacing(8)
|
||||
|
||||
options = QHBoxLayout()
|
||||
options.addWidget(QLabel("范围"))
|
||||
@@ -53,15 +47,21 @@ class BomPage(QWidget):
|
||||
self.selected_button,
|
||||
):
|
||||
options.addWidget(button)
|
||||
options.addWidget(QLabel("描述来源"))
|
||||
options.addStretch(1)
|
||||
layout.addLayout(options)
|
||||
|
||||
self.advanced_section = CollapsibleSection("高级选项")
|
||||
advanced_options = QHBoxLayout()
|
||||
advanced_options.addWidget(QLabel("描述来源"))
|
||||
self.description_combo = QComboBox()
|
||||
self.description_combo.addItem("Value", "value")
|
||||
self.description_combo.addItem("Part Label", "part-label")
|
||||
options.addWidget(self.description_combo)
|
||||
advanced_options.addWidget(self.description_combo)
|
||||
self.nc_checkbox = QCheckBox("剔除 NC 器件")
|
||||
options.addWidget(self.nc_checkbox)
|
||||
options.addStretch(1)
|
||||
layout.addLayout(options)
|
||||
advanced_options.addWidget(self.nc_checkbox)
|
||||
advanced_options.addStretch(1)
|
||||
self.advanced_section.content_layout.addLayout(advanced_options)
|
||||
layout.addWidget(self.advanced_section)
|
||||
|
||||
self.model = QStandardItemModel(0, 6, self)
|
||||
self.model.setHorizontalHeaderLabels(
|
||||
@@ -69,8 +69,15 @@ class BomPage(QWidget):
|
||||
)
|
||||
self.table = QTableView()
|
||||
self.table.setModel(self.model)
|
||||
self.table.setMinimumHeight(200)
|
||||
self.table.setMinimumHeight(160)
|
||||
self.table.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
|
||||
self.table.setAlternatingRowColors(True)
|
||||
self.table.verticalHeader().hide()
|
||||
header = self.table.horizontalHeader()
|
||||
header.setSectionResizeMode(QHeaderView.ResizeMode.Interactive)
|
||||
for column, width in ((0, 70), (1, 48), (2, 125), (3, 125), (5, 100)):
|
||||
self.table.setColumnWidth(column, width)
|
||||
header.setSectionResizeMode(4, QHeaderView.ResizeMode.Stretch)
|
||||
layout.addWidget(self.table, 1)
|
||||
|
||||
self.summary_label = QLabel("")
|
||||
@@ -83,6 +90,7 @@ class BomPage(QWidget):
|
||||
self.export_button = QPushButton("导出 Excel…")
|
||||
self.export_button.setObjectName("primaryButton")
|
||||
self.export_button.setEnabled(False)
|
||||
self.export_button.setToolTip("由 DxDesigner 调用 Excel,按模板导出预览中的 BOM")
|
||||
self.export_button.clicked.connect(self._emit_export)
|
||||
actions.addWidget(self.export_button)
|
||||
layout.addLayout(actions)
|
||||
@@ -91,6 +99,13 @@ class BomPage(QWidget):
|
||||
button.toggled.connect(self.settings_changed)
|
||||
self.description_combo.currentIndexChanged.connect(self.settings_changed)
|
||||
self.nc_checkbox.toggled.connect(self.settings_changed)
|
||||
self.description_combo.currentIndexChanged.connect(self._update_advanced_summary)
|
||||
self.nc_checkbox.toggled.connect(self._update_advanced_summary)
|
||||
self._update_advanced_summary()
|
||||
|
||||
def _update_advanced_summary(self) -> None:
|
||||
nc = "剔除 NC" if self.nc_checkbox.isChecked() else "保留 NC"
|
||||
self.advanced_section.set_summary(f"描述:{self.description_combo.currentText()} · {nc}")
|
||||
|
||||
def _emit_export(self) -> None:
|
||||
path, _ = QFileDialog.getSaveFileName(
|
||||
@@ -150,9 +165,11 @@ class BomPage(QWidget):
|
||||
if result.excluded_count:
|
||||
summary += f";NC 剔除:{result.excluded_count} 个器件"
|
||||
self.summary_label.setText(summary)
|
||||
self.summary_label.setToolTip(summary)
|
||||
|
||||
def set_summary(self, text: str) -> None:
|
||||
self.summary_label.setText(text)
|
||||
self.summary_label.setToolTip(text)
|
||||
|
||||
def set_can_export(self, enabled: bool) -> None:
|
||||
self.export_button.setEnabled(enabled)
|
||||
@@ -161,4 +178,5 @@ class BomPage(QWidget):
|
||||
def _read_only(text: str) -> QStandardItem:
|
||||
item = QStandardItem(text)
|
||||
item.setEditable(False)
|
||||
item.setToolTip(text)
|
||||
return item
|
||||
@@ -16,6 +16,7 @@ from PySide6.QtWidgets import (
|
||||
)
|
||||
|
||||
from dx_productivity.domain.models import HistoryEntry
|
||||
from dx_productivity.ui.collapsible_section import CollapsibleSection
|
||||
from dx_productivity.ui.theme import Theme, themed_icon
|
||||
|
||||
|
||||
@@ -43,6 +44,7 @@ class HistoryPage(QWidget):
|
||||
items = [QStandardItem(value) for value in values]
|
||||
for item in items:
|
||||
item.setEditable(False)
|
||||
item.setToolTip(f"操作:{entry.run_id}\n设计:{entry.design_id}\n备份:{values[4]}")
|
||||
self.model.appendRow(items)
|
||||
if self._entries:
|
||||
self.table.selectRow(0)
|
||||
@@ -62,22 +64,15 @@ class HistoryPage(QWidget):
|
||||
|
||||
def _build_ui(self) -> None:
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(20, 18, 20, 18)
|
||||
layout.setSpacing(12)
|
||||
layout.setContentsMargins(12, 10, 12, 10)
|
||||
layout.setSpacing(8)
|
||||
|
||||
toolbar = QHBoxLayout()
|
||||
title = QLabel("操作历史")
|
||||
title.setObjectName("pageTitle")
|
||||
toolbar.addWidget(title)
|
||||
toolbar.addStretch(1)
|
||||
self.restore_button = QPushButton("恢复所选操作")
|
||||
self.restore_button.setIcon(
|
||||
themed_icon("fa6s.clock-rotate-left", Theme.LIGHT)
|
||||
)
|
||||
self.restore_button.setEnabled(False)
|
||||
self.restore_button.clicked.connect(self.restore_requested)
|
||||
toolbar.addWidget(self.restore_button)
|
||||
layout.addLayout(toolbar)
|
||||
|
||||
self.model = QStandardItemModel(0, 5, self)
|
||||
self.model.setHorizontalHeaderLabels(
|
||||
@@ -97,16 +92,35 @@ class HistoryPage(QWidget):
|
||||
header.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
|
||||
header.setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
|
||||
header.setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
|
||||
header.setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)
|
||||
header.setSectionResizeMode(4, QHeaderView.ResizeMode.Stretch)
|
||||
header.setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
|
||||
self.table.setColumnHidden(4, True)
|
||||
self.table.setMinimumHeight(160)
|
||||
self.table.selectionModel().selectionChanged.connect(
|
||||
self._update_restore_state
|
||||
)
|
||||
layout.addWidget(self.table, 1)
|
||||
|
||||
self.details_section = CollapsibleSection("所选操作详情")
|
||||
self.details_label = QLabel("未选择操作")
|
||||
self.details_label.setWordWrap(True)
|
||||
self.details_label.setTextFormat(Qt.TextFormat.PlainText)
|
||||
self.details_label.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
|
||||
self.details_section.content_layout.addWidget(self.details_label)
|
||||
layout.addWidget(self.details_section)
|
||||
actions = QHBoxLayout()
|
||||
actions.addStretch(1)
|
||||
actions.addWidget(self.restore_button)
|
||||
layout.addLayout(actions)
|
||||
|
||||
def _update_restore_state(self, *_args) -> None:
|
||||
entry = self.selected_entry()
|
||||
self.restore_button.setEnabled(entry is not None and entry.backup_path is not None)
|
||||
if entry is None:
|
||||
self.details_label.setText("未选择操作")
|
||||
else:
|
||||
backup = str(entry.backup_path) if entry.backup_path is not None else "无备份"
|
||||
self.details_label.setText(f"操作:{entry.run_id}\n设计:{entry.design_id}\n备份:{backup}")
|
||||
self.details_label.setToolTip(self.details_label.text())
|
||||
|
||||
|
||||
def _state_text(state: str) -> str:
|
||||
|
||||
@@ -6,7 +6,9 @@ from PySide6.QtCore import Signal
|
||||
from PySide6.QtGui import QStandardItem, QStandardItemModel
|
||||
from PySide6.QtWidgets import (
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QHBoxLayout,
|
||||
QHeaderView,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QPushButton,
|
||||
@@ -35,79 +37,87 @@ class InspectionPage(QWidget):
|
||||
|
||||
def _build_ui(self) -> None:
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(20, 16, 20, 16)
|
||||
layout.setSpacing(10)
|
||||
layout.setContentsMargins(12, 10, 12, 10)
|
||||
layout.setSpacing(8)
|
||||
|
||||
hint = QLabel(
|
||||
("网络检查:孤立网络、网络列表与跨页查询。"
|
||||
if self.network_only else "只读设计检查:孤立网络、网络列表、属性遗漏。")
|
||||
+ "双击结果行可在原理图中定位。"
|
||||
)
|
||||
hint.setObjectName("secondaryLabel")
|
||||
hint.setWordWrap(True)
|
||||
layout.addWidget(hint)
|
||||
|
||||
buttons_row = QHBoxLayout()
|
||||
self.solitary_button = QPushButton("孤立网络检查")
|
||||
self.net_list_button = QPushButton("全部网络列表")
|
||||
self.value_miss_button = QPushButton("Value 遗漏")
|
||||
self.value1_miss_button = QPushButton("Value1 遗漏")
|
||||
for button in (self.solitary_button, self.net_list_button):
|
||||
buttons_row.addWidget(button)
|
||||
for button in (self.value_miss_button, self.value1_miss_button):
|
||||
if self.network_only:
|
||||
button.hide()
|
||||
else:
|
||||
buttons_row.addWidget(button)
|
||||
self.include_missing_checkbox = QCheckBox("属性缺失也算遗漏")
|
||||
controls = QHBoxLayout()
|
||||
controls.addWidget(QLabel("查询类型" if self.network_only else "检查类型"))
|
||||
self.check_type_combo = QComboBox()
|
||||
self.check_type_combo.setAccessibleName("检查类型")
|
||||
self.check_type_combo.addItem("孤立网络", "solitary")
|
||||
self.check_type_combo.addItem("全部网络", "list")
|
||||
if not self.network_only:
|
||||
self.check_type_combo.addItem("Value 遗漏", "Value")
|
||||
self.check_type_combo.addItem("Value1 遗漏", "Value1")
|
||||
self.check_type_combo.addItem("跨页查询", "cross")
|
||||
if self.network_only:
|
||||
self.include_missing_checkbox.hide()
|
||||
else:
|
||||
buttons_row.addWidget(self.include_missing_checkbox)
|
||||
buttons_row.addStretch(1)
|
||||
layout.addLayout(buttons_row)
|
||||
|
||||
search_row = QHBoxLayout()
|
||||
search_row.addWidget(QLabel("跨页互动"))
|
||||
self.check_type_combo.setCurrentIndex(self.check_type_combo.findData("list"))
|
||||
controls.addWidget(self.check_type_combo)
|
||||
self.include_missing_checkbox = QCheckBox("属性缺失也算遗漏")
|
||||
controls.addWidget(self.include_missing_checkbox)
|
||||
self.net_name_edit = QLineEdit()
|
||||
self.net_name_edit.setPlaceholderText("输入网络名,查看其所有页分布")
|
||||
search_row.addWidget(self.net_name_edit, 1)
|
||||
self.cross_page_button = QPushButton("查询")
|
||||
search_row.addWidget(self.cross_page_button)
|
||||
layout.addLayout(search_row)
|
||||
self.net_name_edit.setPlaceholderText("网络名")
|
||||
self.net_name_edit.setToolTip("输入网络名,查询其所有页分布")
|
||||
controls.addWidget(self.net_name_edit, 1)
|
||||
controls.addStretch(1)
|
||||
self.run_button = QPushButton("运行")
|
||||
self.run_button.setAccessibleName("运行检查")
|
||||
self.run_button.setObjectName("primaryButton")
|
||||
self.run_button.clicked.connect(self._run_selected_check)
|
||||
self.net_name_edit.returnPressed.connect(self._run_selected_check)
|
||||
controls.addWidget(self.run_button)
|
||||
layout.addLayout(controls)
|
||||
|
||||
self.model = QStandardItemModel(0, 4, self)
|
||||
self.model.setHorizontalHeaderLabels(("检查项", "名称", "页号", "说明"))
|
||||
self.table = QTableView()
|
||||
self.table.setModel(self.model)
|
||||
self.table.setMinimumHeight(200)
|
||||
self.table.setMinimumHeight(160)
|
||||
self.table.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
|
||||
self.table.setToolTip("双击结果行可在原理图中定位")
|
||||
self.table.setAlternatingRowColors(True)
|
||||
self.table.verticalHeader().hide()
|
||||
header = self.table.horizontalHeader()
|
||||
header.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
|
||||
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
|
||||
header.setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
|
||||
header.setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
|
||||
self.table.doubleClicked.connect(self._on_double_click)
|
||||
layout.addWidget(self.table, 1)
|
||||
|
||||
self.summary_label = QLabel("")
|
||||
self.summary_label.setObjectName("secondaryLabel")
|
||||
self.summary_label.setWordWrap(True)
|
||||
layout.addWidget(self.summary_label)
|
||||
|
||||
self.solitary_button.clicked.connect(self.solitary_requested)
|
||||
self.net_list_button.clicked.connect(self.net_list_requested)
|
||||
self.value_miss_button.clicked.connect(
|
||||
lambda: self.value_miss_requested.emit("Value")
|
||||
)
|
||||
self.value1_miss_button.clicked.connect(
|
||||
lambda: self.value_miss_requested.emit("Value1")
|
||||
)
|
||||
self.cross_page_button.clicked.connect(
|
||||
lambda: self.cross_page_requested.emit(self.net_name_edit.text())
|
||||
)
|
||||
self.check_type_combo.currentIndexChanged.connect(self._update_check_fields)
|
||||
self._update_check_fields()
|
||||
|
||||
def _update_check_fields(self) -> None:
|
||||
kind = self.check_type_combo.currentData()
|
||||
self.net_name_edit.setVisible(kind == "cross")
|
||||
self.include_missing_checkbox.setVisible(kind in ("Value", "Value1"))
|
||||
self.run_button.setText("查询" if kind == "cross" else "运行")
|
||||
|
||||
def _run_selected_check(self) -> None:
|
||||
if not self.run_button.isEnabled():
|
||||
return
|
||||
kind = self.check_type_combo.currentData()
|
||||
if kind == "solitary":
|
||||
self.solitary_requested.emit()
|
||||
elif kind == "list":
|
||||
self.net_list_requested.emit()
|
||||
elif kind in ("Value", "Value1"):
|
||||
self.value_miss_requested.emit(kind)
|
||||
elif kind == "cross":
|
||||
self.cross_page_requested.emit(self.net_name_edit.text())
|
||||
|
||||
def include_missing(self) -> bool:
|
||||
return self.include_missing_checkbox.isChecked()
|
||||
|
||||
def set_snapshot_available(self, available: bool) -> None:
|
||||
for control in (
|
||||
self.solitary_button, self.net_list_button, self.value_miss_button,
|
||||
self.value1_miss_button, self.cross_page_button, self.net_name_edit,
|
||||
self.run_button, self.check_type_combo, self.net_name_edit,
|
||||
self.include_missing_checkbox,
|
||||
):
|
||||
control.setEnabled(available)
|
||||
@@ -138,8 +148,11 @@ class InspectionPage(QWidget):
|
||||
page_item.setEditable(False)
|
||||
detail_item = QStandardItem(row.detail)
|
||||
detail_item.setEditable(False)
|
||||
for item in (kind_item, name_item, page_item, detail_item):
|
||||
item.setToolTip(item.text())
|
||||
self.model.appendRow((kind_item, name_item, page_item, detail_item))
|
||||
self.summary_label.setText(summary)
|
||||
self.summary_label.setToolTip(summary)
|
||||
|
||||
def show_no_net_data(self) -> None:
|
||||
self.set_rows(
|
||||
|
||||
@@ -7,6 +7,7 @@ from PySide6.QtGui import QStandardItem, QStandardItemModel
|
||||
from PySide6.QtWidgets import (
|
||||
QComboBox,
|
||||
QHBoxLayout,
|
||||
QHeaderView,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QPushButton,
|
||||
@@ -31,20 +32,13 @@ class PropertyChangePage(QWidget):
|
||||
|
||||
def _build_ui(self) -> None:
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(20, 16, 20, 16)
|
||||
layout.setSpacing(10)
|
||||
|
||||
hint = QLabel(
|
||||
"修改选中器件的属性值。先在 DxDesigner 中选中器件,"
|
||||
"再为每个器件填写新值;没有该属性的器件会被跳过并在下方提示。"
|
||||
)
|
||||
hint.setObjectName("secondaryLabel")
|
||||
hint.setWordWrap(True)
|
||||
layout.addWidget(hint)
|
||||
layout.setContentsMargins(12, 10, 12, 10)
|
||||
layout.setSpacing(8)
|
||||
|
||||
selector_row = QHBoxLayout()
|
||||
selector_row.addWidget(QLabel("属性"))
|
||||
self.property_combo = QComboBox()
|
||||
self.property_combo.setToolTip("先在 DxDesigner 选中器件,再填写表格中的新值;缺失属性会被跳过并提示")
|
||||
for name in SUPPORTED_PROPERTIES:
|
||||
self.property_combo.addItem(name)
|
||||
self.property_combo.addItem("自定义…")
|
||||
@@ -59,12 +53,20 @@ class PropertyChangePage(QWidget):
|
||||
self.model.setHorizontalHeaderLabels(("位号", "当前值", "新值"))
|
||||
self.table = QTableView()
|
||||
self.table.setModel(self.model)
|
||||
self.table.setMinimumHeight(200)
|
||||
self.table.setMinimumHeight(160)
|
||||
self.table.setAlternatingRowColors(True)
|
||||
self.table.verticalHeader().hide()
|
||||
header = self.table.horizontalHeader()
|
||||
header.setSectionResizeMode(0, QHeaderView.ResizeMode.Interactive)
|
||||
self.table.setColumnWidth(0, 110)
|
||||
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
|
||||
header.setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
|
||||
layout.addWidget(self.table, 1)
|
||||
|
||||
self.issue_label = QLabel("")
|
||||
self.issue_label.setObjectName("secondaryLabel")
|
||||
self.issue_label.setWordWrap(True)
|
||||
self.issue_label.hide()
|
||||
layout.addWidget(self.issue_label)
|
||||
|
||||
actions = QHBoxLayout()
|
||||
@@ -123,11 +125,15 @@ class PropertyChangePage(QWidget):
|
||||
current_item.setEditable(False)
|
||||
new_item = QStandardItem(current)
|
||||
new_item.setEditable(editable)
|
||||
ref_item.setToolTip(refdes)
|
||||
current_item.setToolTip(current)
|
||||
self.model.appendRow((ref_item, current_item, new_item))
|
||||
self.model.blockSignals(False)
|
||||
|
||||
def set_issue_text(self, text: str) -> None:
|
||||
self.issue_label.setText(text)
|
||||
self.issue_label.setToolTip(text)
|
||||
self.issue_label.setVisible(bool(text))
|
||||
|
||||
def set_can_apply(self, enabled: bool) -> None:
|
||||
self.apply_button.setEnabled(enabled)
|
||||
@@ -7,6 +7,7 @@ from PySide6.QtGui import QStandardItem, QStandardItemModel
|
||||
from PySide6.QtWidgets import (
|
||||
QComboBox,
|
||||
QHBoxLayout,
|
||||
QHeaderView,
|
||||
QLabel,
|
||||
QPushButton,
|
||||
QRadioButton,
|
||||
@@ -31,41 +32,39 @@ class PropertyVisibilityPage(QWidget):
|
||||
|
||||
def _build_ui(self) -> None:
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(20, 16, 20, 16)
|
||||
layout.setSpacing(10)
|
||||
|
||||
hint = QLabel(
|
||||
"批量切换选中器件的属性显示状态。先在 DxDesigner 中选中器件,"
|
||||
"选择属性与目标状态后生成预览。"
|
||||
)
|
||||
hint.setObjectName("secondaryLabel")
|
||||
hint.setWordWrap(True)
|
||||
layout.addWidget(hint)
|
||||
layout.setContentsMargins(12, 10, 12, 10)
|
||||
layout.setSpacing(8)
|
||||
|
||||
selector_row = QHBoxLayout()
|
||||
selector_row.addWidget(QLabel("属性"))
|
||||
self.property_combo = QComboBox()
|
||||
self.property_combo.setToolTip("在 DxDesigner 选中器件后,选择要显示或隐藏的属性;下表同步预览")
|
||||
for name in SUPPORTED_PROPERTIES:
|
||||
self.property_combo.addItem(name)
|
||||
selector_row.addWidget(self.property_combo)
|
||||
selector_row.addStretch(1)
|
||||
layout.addLayout(selector_row)
|
||||
|
||||
direction_row = QHBoxLayout()
|
||||
direction_row.addWidget(QLabel("目标状态"))
|
||||
selector_row.addSpacing(16)
|
||||
selector_row.addWidget(QLabel("目标状态"))
|
||||
self.hide_button = QRadioButton("隐藏")
|
||||
self.hide_button.setChecked(True)
|
||||
self.show_button = QRadioButton("显示")
|
||||
direction_row.addWidget(self.hide_button)
|
||||
direction_row.addWidget(self.show_button)
|
||||
direction_row.addStretch(1)
|
||||
layout.addLayout(direction_row)
|
||||
selector_row.addWidget(self.hide_button)
|
||||
selector_row.addWidget(self.show_button)
|
||||
selector_row.addStretch(1)
|
||||
layout.addLayout(selector_row)
|
||||
|
||||
self.model = QStandardItemModel(0, 3, self)
|
||||
self.model.setHorizontalHeaderLabels(("位号", "属性值", "当前状态"))
|
||||
self.table = QTableView()
|
||||
self.table.setModel(self.model)
|
||||
self.table.setMinimumHeight(200)
|
||||
self.table.setMinimumHeight(160)
|
||||
self.table.setAlternatingRowColors(True)
|
||||
self.table.verticalHeader().hide()
|
||||
header = self.table.horizontalHeader()
|
||||
header.setSectionResizeMode(0, QHeaderView.ResizeMode.Interactive)
|
||||
self.table.setColumnWidth(0, 110)
|
||||
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
|
||||
header.setSectionResizeMode(2, QHeaderView.ResizeMode.Interactive)
|
||||
self.table.setColumnWidth(2, 110)
|
||||
self.table.setEditTriggers(
|
||||
QTableView.EditTrigger.NoEditTriggers
|
||||
)
|
||||
@@ -74,6 +73,7 @@ class PropertyVisibilityPage(QWidget):
|
||||
self.issue_label = QLabel("")
|
||||
self.issue_label.setObjectName("secondaryLabel")
|
||||
self.issue_label.setWordWrap(True)
|
||||
self.issue_label.hide()
|
||||
layout.addWidget(self.issue_label)
|
||||
|
||||
actions = QHBoxLayout()
|
||||
@@ -106,10 +106,14 @@ class PropertyVisibilityPage(QWidget):
|
||||
{"1": "显示", "0": "隐藏"}.get(visibility, "属性缺失")
|
||||
)
|
||||
state_item.setEditable(False)
|
||||
for item in (ref_item, value_item, state_item):
|
||||
item.setToolTip(item.text())
|
||||
self.model.appendRow((ref_item, value_item, state_item))
|
||||
|
||||
def set_issue_text(self, text: str) -> None:
|
||||
self.issue_label.setText(text)
|
||||
self.issue_label.setToolTip(text)
|
||||
self.issue_label.setVisible(bool(text))
|
||||
|
||||
def set_can_apply(self, enabled: bool) -> None:
|
||||
self.apply_button.setEnabled(enabled)
|
||||
|
||||
@@ -4,12 +4,11 @@ from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QSize, Signal
|
||||
from PySide6.QtCore import Signal
|
||||
from PySide6.QtWidgets import (
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QFormLayout,
|
||||
QFrame,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
@@ -22,6 +21,7 @@ from PySide6.QtWidgets import (
|
||||
|
||||
from dx_productivity.update.models import UpdateManifest
|
||||
from dx_productivity.update.service import UpdateCheckResult
|
||||
from dx_productivity.ui.collapsible_section import CollapsibleSection
|
||||
from dx_productivity.ui.theme import Theme, themed_icon
|
||||
|
||||
|
||||
@@ -93,38 +93,30 @@ class SettingsPage(QWidget):
|
||||
|
||||
def _build_ui(self) -> None:
|
||||
root = QVBoxLayout(self)
|
||||
root.setContentsMargins(20, 18, 20, 18)
|
||||
root.setSpacing(14)
|
||||
root.setContentsMargins(12, 10, 12, 10)
|
||||
root.setSpacing(8)
|
||||
|
||||
header = QFrame()
|
||||
header.setObjectName("settingsIntro")
|
||||
header_layout = QVBoxLayout(header)
|
||||
header_layout.setContentsMargins(16, 12, 16, 12)
|
||||
title = QLabel("设置")
|
||||
title.setObjectName("pageTitle")
|
||||
header_layout.addWidget(title)
|
||||
subtitle = QLabel("在线更新默认只检查,不会静默安装或覆盖正在运行的程序")
|
||||
subtitle.setObjectName("secondaryLabel")
|
||||
header_layout.addWidget(subtitle)
|
||||
root.addWidget(header)
|
||||
self.auto_check_checkbox = QCheckBox("启动后每天自动检查一次")
|
||||
self.auto_check_checkbox.setChecked(True)
|
||||
self.auto_check_checkbox.setToolTip("自动检查仅提示新版本;下载和安装分别需要确认")
|
||||
root.addWidget(self.auto_check_checkbox)
|
||||
|
||||
form_frame = QFrame()
|
||||
form_frame.setObjectName("settingsPanel")
|
||||
form = QFormLayout(form_frame)
|
||||
form.setContentsMargins(16, 14, 16, 14)
|
||||
form.setHorizontalSpacing(16)
|
||||
form.setVerticalSpacing(12)
|
||||
self.advanced_section = CollapsibleSection("高级更新选项")
|
||||
form = QFormLayout()
|
||||
form.setHorizontalSpacing(12)
|
||||
form.setVerticalSpacing(8)
|
||||
self.source_input = QLineEdit()
|
||||
self.source_input.setPlaceholderText("https://.../manifest.json 或 file://...")
|
||||
self.channel_combo = QComboBox()
|
||||
self.channel_combo.addItem("稳定版", "stable")
|
||||
self.channel_combo.addItem("开发版", "development")
|
||||
self.auto_check_checkbox = QCheckBox("启动后每天自动检查一次")
|
||||
self.auto_check_checkbox.setChecked(True)
|
||||
form.addRow("更新源", self.source_input)
|
||||
form.addRow("频道", self.channel_combo)
|
||||
form.addRow("检查策略", self.auto_check_checkbox)
|
||||
root.addWidget(form_frame)
|
||||
self.advanced_section.content_layout.addLayout(form)
|
||||
root.addWidget(self.advanced_section)
|
||||
self.source_input.textChanged.connect(self._update_advanced_summary)
|
||||
self.channel_combo.currentIndexChanged.connect(self._update_advanced_summary)
|
||||
self._update_advanced_summary()
|
||||
|
||||
actions = QHBoxLayout()
|
||||
self.check_button = QPushButton("检查更新")
|
||||
@@ -143,20 +135,30 @@ class SettingsPage(QWidget):
|
||||
self.version_label.setObjectName("secondaryLabel")
|
||||
self.status_label = QLabel("尚未检查")
|
||||
self.status_label.setObjectName("settingsStatus")
|
||||
self.status_label.setWordWrap(True)
|
||||
status_row.addWidget(self.version_label)
|
||||
status_row.addStretch(1)
|
||||
status_row.addWidget(self.status_label)
|
||||
root.addLayout(status_row)
|
||||
|
||||
notes_title = QLabel("版本说明")
|
||||
notes_title.setObjectName("moduleCardTitle")
|
||||
root.addWidget(notes_title)
|
||||
self.notes_section = CollapsibleSection("版本说明")
|
||||
self.release_notes_view = QTextEdit()
|
||||
self.release_notes_view.setReadOnly(True)
|
||||
self.release_notes_view.setPlaceholderText("检查到新版本后显示版本说明")
|
||||
root.addWidget(self.release_notes_view, 1)
|
||||
self.release_notes_view.setMinimumHeight(80)
|
||||
self.notes_section.content_layout.addWidget(self.release_notes_view)
|
||||
root.addWidget(self.notes_section)
|
||||
root.addStretch(1)
|
||||
self.refresh_icons(Theme.LIGHT)
|
||||
|
||||
def _update_advanced_summary(self) -> None:
|
||||
source = self.source_input.text().strip()
|
||||
source_hint = (source[:45] + "…") if len(source) > 45 else source
|
||||
summary = f"频道:{self.channel_combo.currentText()} · 更新源:{source_hint or '未配置'}"
|
||||
self.advanced_section.set_summary(summary)
|
||||
self.advanced_section.summary_label.setToolTip(source or "未配置更新源")
|
||||
self.source_input.setToolTip(source)
|
||||
|
||||
def _check(self) -> None:
|
||||
self.set_checking()
|
||||
self.check_requested.emit(self.source_input.text().strip(), self.channel_combo.currentData())
|
||||
|
||||
@@ -15,21 +15,28 @@ def _controller(qtbot, tmp_path, snapshot):
|
||||
return controller, page, paths
|
||||
|
||||
|
||||
def _run_check(page, kind):
|
||||
index = page.check_type_combo.findData(kind)
|
||||
assert index >= 0
|
||||
page.check_type_combo.setCurrentIndex(index)
|
||||
page.run_button.click()
|
||||
|
||||
|
||||
def test_network_buttons_and_cross_page_rows_publish_location_without_writes(
|
||||
qtbot, tmp_path, snapshot_factory
|
||||
):
|
||||
snapshot = snapshot_factory(nets=(NetRecord("N1", (1,)), NetRecord("N2", (1, 2))))
|
||||
controller, page, paths = _controller(qtbot, tmp_path, snapshot)
|
||||
|
||||
page.solitary_button.click()
|
||||
_run_check(page, "solitary")
|
||||
assert page.model.rowCount() == 1
|
||||
assert page.model.item(0, 1).text() == "N1"
|
||||
page.table.doubleClicked.emit(page.model.index(0, 1))
|
||||
assert paths.locate.read_text(encoding="utf-8") == "net|N1|1\n"
|
||||
page.net_list_button.click()
|
||||
_run_check(page, "list")
|
||||
assert page.model.rowCount() == 2
|
||||
page.net_name_edit.setText(" n2 ")
|
||||
page.cross_page_button.click()
|
||||
_run_check(page, "cross")
|
||||
assert page.model.rowCount() == 2
|
||||
assert page.model.item(1, 2).text() == "2"
|
||||
page.table.doubleClicked.emit(page.model.index(1, 1))
|
||||
@@ -38,21 +45,19 @@ def test_network_buttons_and_cross_page_rows_publish_location_without_writes(
|
||||
assert not paths.apply_request.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("button_name,attribute_name", [
|
||||
("value_miss_button", "Value"), ("value1_miss_button", "Value1"),
|
||||
])
|
||||
@pytest.mark.parametrize("attribute_name", ["Value", "Value1"])
|
||||
def test_attribute_omission_buttons_and_include_missing_filter(
|
||||
qtbot, tmp_path, component_factory, snapshot_factory, button_name, attribute_name
|
||||
qtbot, tmp_path, component_factory, snapshot_factory, attribute_name
|
||||
):
|
||||
empty = component_factory(refdes="R1", attributes=(AttributeRecord(attribute_name, "", True),))
|
||||
absent = component_factory(bridge_id="c0002", stable_uid="uid-c2", full_path="ROOT\\C2", refdes="C1")
|
||||
controller, page, paths = _controller(qtbot, tmp_path, snapshot_factory(components=(empty, absent)))
|
||||
|
||||
getattr(page, button_name).click()
|
||||
_run_check(page, attribute_name)
|
||||
assert page.model.rowCount() == 1
|
||||
assert page.model.item(0, 1).text() == f"R1 {attribute_name}"
|
||||
page.include_missing_checkbox.setChecked(True)
|
||||
getattr(page, button_name).click()
|
||||
_run_check(page, attribute_name)
|
||||
assert page.model.rowCount() == 2
|
||||
page.table.doubleClicked.emit(page.model.index(1, 1))
|
||||
assert paths.locate.read_text(encoding="utf-8") == "c0002\n"
|
||||
@@ -61,13 +66,13 @@ def test_attribute_omission_buttons_and_include_missing_filter(
|
||||
|
||||
def test_cross_page_empty_and_unknown_query_clear_old_results(qtbot, tmp_path, snapshot_factory):
|
||||
controller, page, paths = _controller(qtbot, tmp_path, snapshot_factory(nets=(NetRecord("N2", (1, 2)),)))
|
||||
page.net_list_button.click()
|
||||
_run_check(page, "list")
|
||||
|
||||
page.cross_page_button.click()
|
||||
_run_check(page, "cross")
|
||||
assert page.model.rowCount() == 0
|
||||
assert "请输入" in page.summary_label.text()
|
||||
page.net_name_edit.setText("missing")
|
||||
page.cross_page_button.click()
|
||||
_run_check(page, "cross")
|
||||
assert page.model.rowCount() == 0
|
||||
assert "missing" in page.summary_label.text()
|
||||
|
||||
@@ -75,7 +80,7 @@ def test_cross_page_empty_and_unknown_query_clear_old_results(qtbot, tmp_path, s
|
||||
def test_missing_network_data_reports_limitation(qtbot, tmp_path, snapshot_factory):
|
||||
controller, page, paths = _controller(qtbot, tmp_path, snapshot_factory())
|
||||
|
||||
page.solitary_button.click()
|
||||
_run_check(page, "solitary")
|
||||
|
||||
assert page.model.rowCount() == 0
|
||||
assert "未包含网络数据" in page.summary_label.text()
|
||||
@@ -87,13 +92,15 @@ def test_inspection_actions_wait_for_a_design_snapshot(qtbot, snapshot_factory):
|
||||
qtbot.addWidget(page)
|
||||
controller = InspectionController(page)
|
||||
|
||||
assert not page.solitary_button.isEnabled()
|
||||
assert not page.value_miss_button.isEnabled()
|
||||
assert not page.cross_page_button.isEnabled()
|
||||
assert not page.run_button.isEnabled()
|
||||
assert not page.check_type_combo.isEnabled()
|
||||
assert not page.net_name_edit.isEnabled()
|
||||
assert not page.include_missing_checkbox.isEnabled()
|
||||
controller.load_snapshot(snapshot_factory())
|
||||
assert page.solitary_button.isEnabled()
|
||||
assert page.value_miss_button.isEnabled()
|
||||
assert page.cross_page_button.isEnabled()
|
||||
assert page.run_button.isEnabled()
|
||||
assert page.check_type_combo.isEnabled()
|
||||
assert page.net_name_edit.isEnabled()
|
||||
assert page.include_missing_checkbox.isEnabled()
|
||||
|
||||
|
||||
def test_network_navigation_has_live_list_and_locator(qtbot, tmp_path, fixture_path, monkeypatch):
|
||||
@@ -112,11 +119,11 @@ def test_network_navigation_has_live_list_and_locator(qtbot, tmp_path, fixture_p
|
||||
page = window.pages.currentWidget()
|
||||
assert isinstance(page, InspectionPage)
|
||||
assert page.model.rowCount() == 2
|
||||
assert page.value_miss_button.isHidden()
|
||||
page.solitary_button.click()
|
||||
assert page.check_type_combo.findData("Value") == -1
|
||||
_run_check(page, "solitary")
|
||||
assert page.model.rowCount() == 1
|
||||
page.net_name_edit.setText("N2")
|
||||
page.cross_page_button.click()
|
||||
_run_check(page, "cross")
|
||||
assert page.model.rowCount() == 2
|
||||
page.table.doubleClicked.emit(page.model.index(1, 1))
|
||||
assert (tmp_path / "locate.tsv").read_text(encoding="utf-8") == "net|N2|2\n"
|
||||
@@ -125,7 +132,7 @@ def test_network_navigation_has_live_list_and_locator(qtbot, tmp_path, fixture_p
|
||||
|
||||
def test_refresh_recomputes_the_visible_inspection(qtbot, tmp_path, snapshot_factory):
|
||||
controller, page, paths = _controller(qtbot, tmp_path, snapshot_factory(nets=(NetRecord("old", (1,)),)))
|
||||
page.net_list_button.click()
|
||||
_run_check(page, "list")
|
||||
|
||||
controller.load_snapshot(snapshot_factory(snapshot_id="new", nets=(NetRecord("new", (2,)),)))
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from PySide6.QtWidgets import QHeaderView, QLabel
|
||||
|
||||
from dx_productivity.domain.models import HistoryEntry
|
||||
from dx_productivity.ui.bom_page import BomPage
|
||||
from dx_productivity.ui.history_page import HistoryPage
|
||||
from dx_productivity.ui.inspection_page import InspectionPage
|
||||
from dx_productivity.ui.property_change_page import PropertyChangePage
|
||||
from dx_productivity.ui.property_visibility_page import PropertyVisibilityPage
|
||||
from dx_productivity.ui.settings_page import SettingsPage
|
||||
|
||||
|
||||
@pytest.mark.parametrize("network_only", [False, True])
|
||||
def test_inspection_type_reveals_only_relevant_fields_and_runs_existing_signal(qtbot, network_only):
|
||||
page = InspectionPage(network_only=network_only)
|
||||
qtbot.addWidget(page)
|
||||
page.show()
|
||||
assert not page.run_button.isEnabled()
|
||||
assert not page.net_name_edit.isVisible()
|
||||
assert not page.include_missing_checkbox.isVisible()
|
||||
page.set_snapshot_available(True)
|
||||
page.check_type_combo.setCurrentIndex(page.check_type_combo.findData("cross"))
|
||||
assert page.net_name_edit.isVisible()
|
||||
page.net_name_edit.setText("N2")
|
||||
with qtbot.waitSignal(page.cross_page_requested) as signal:
|
||||
page.run_button.click()
|
||||
assert signal.args == ["N2"]
|
||||
page.check_type_combo.setCurrentIndex(page.check_type_combo.findData("solitary"))
|
||||
assert not page.net_name_edit.isVisible()
|
||||
assert page.net_name_edit.text() == "N2"
|
||||
with qtbot.waitSignal(page.solitary_requested):
|
||||
page.run_button.click()
|
||||
if network_only:
|
||||
assert page.check_type_combo.findData("Value") == -1
|
||||
else:
|
||||
page.check_type_combo.setCurrentIndex(page.check_type_combo.findData("Value"))
|
||||
assert page.include_missing_checkbox.isVisible()
|
||||
assert not page.net_name_edit.isVisible()
|
||||
page.include_missing_checkbox.setChecked(True)
|
||||
with qtbot.waitSignal(page.value_miss_requested) as signal:
|
||||
page.run_button.click()
|
||||
assert signal.args == ["Value"]
|
||||
assert page.include_missing()
|
||||
|
||||
|
||||
def test_bom_collapsed_options_show_effective_description_and_nc_settings(qtbot):
|
||||
page = BomPage()
|
||||
qtbot.addWidget(page)
|
||||
page.show()
|
||||
assert not page.advanced_section.is_expanded
|
||||
assert not page.description_combo.isVisible()
|
||||
assert "Value" in page.advanced_section.summary_label.text()
|
||||
assert "保留 NC" in page.advanced_section.summary_label.text()
|
||||
page.description_combo.setCurrentIndex(1)
|
||||
page.nc_checkbox.setChecked(True)
|
||||
assert page.settings().description_source == "part-label"
|
||||
assert page.settings().exclude_nc
|
||||
assert "Part Label" in page.advanced_section.summary_label.text()
|
||||
assert "剔除 NC" in page.advanced_section.summary_label.text()
|
||||
page.advanced_section.set_expanded(True)
|
||||
assert page.description_combo.isVisible()
|
||||
page.advanced_section.set_expanded(False)
|
||||
assert page.settings().exclude_nc
|
||||
|
||||
|
||||
def test_settings_options_and_release_notes_fold_without_losing_check_values(qtbot):
|
||||
page = SettingsPage(current_version="1.0.0")
|
||||
qtbot.addWidget(page)
|
||||
page.show()
|
||||
assert not page.advanced_section.is_expanded
|
||||
assert not page.notes_section.is_expanded
|
||||
assert not page.source_input.isVisible()
|
||||
assert page.auto_check_checkbox.isVisible()
|
||||
page.source_input.setText("https://example.com/manifest.json")
|
||||
page.channel_combo.setCurrentIndex(1)
|
||||
assert "开发版" in page.advanced_section.summary_label.text()
|
||||
assert page.source_input.text() in page.advanced_section.summary_label.toolTip()
|
||||
with qtbot.waitSignal(page.check_requested) as signal:
|
||||
page.check_button.click()
|
||||
assert signal.args == ["https://example.com/manifest.json", "development"]
|
||||
page.release_notes_view.setPlainText("版本说明内容")
|
||||
page.notes_section.set_expanded(True)
|
||||
assert page.release_notes_view.isVisible()
|
||||
assert page.release_notes_view.toPlainText() == "版本说明内容"
|
||||
|
||||
|
||||
def test_history_backup_path_is_accessible_in_folded_details_and_tooltips(qtbot):
|
||||
page = HistoryPage()
|
||||
qtbot.addWidget(page)
|
||||
page.show()
|
||||
entry = HistoryEntry(datetime.now(timezone.utc), "run1", "design-test",
|
||||
Path("C:/very-long-backup-path/run1.json"), "applied", 3)
|
||||
page.set_entries((entry,))
|
||||
assert page.table.isColumnHidden(4)
|
||||
assert str(entry.backup_path) in page.model.item(0, 0).toolTip()
|
||||
assert not page.details_section.is_expanded
|
||||
page.details_section.set_expanded(True)
|
||||
assert str(entry.backup_path) in page.details_label.text()
|
||||
with qtbot.waitSignal(page.restore_requested):
|
||||
page.restore_button.click()
|
||||
page.set_entries(())
|
||||
assert not page.restore_button.isEnabled()
|
||||
assert str(entry.backup_path) not in page.details_label.text()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("factory", [PropertyChangePage, PropertyVisibilityPage, HistoryPage,
|
||||
lambda: SettingsPage(current_version="1.0.0")])
|
||||
def test_secondary_pages_use_shell_title_and_keep_main_content_readable(qtbot, factory):
|
||||
page = factory()
|
||||
qtbot.addWidget(page)
|
||||
page.resize(720, 360)
|
||||
page.show()
|
||||
assert not page.findChildren(QLabel, "pageTitle")
|
||||
if hasattr(page, "issue_label"):
|
||||
assert not page.issue_label.isVisible()
|
||||
page.set_issue_text("属性缺失,不能应用")
|
||||
assert page.issue_label.isVisible()
|
||||
assert page.issue_label.toolTip() == "属性缺失,不能应用"
|
||||
assert page.table.horizontalHeader().sectionResizeMode(1) == QHeaderView.ResizeMode.Stretch
|
||||
assert page.table.width() > 600
|
||||
assert page.apply_button.isVisible()
|
||||
assert not page.apply_button.isEnabled()
|
||||
Reference in new issue
Block a user