fix(gui,gcode): 无数据时格式化显示0s和0.00g替代未知
format_duration/format_filament 接收 None 时返回零值字符串而非未知, GUI 初始合计标签同步更新。
This commit is contained in:
@@ -120,7 +120,7 @@ def format_duration(seconds: float | None) -> str:
|
||||
格式化后的时间字符串,如 "2h 30m"、"5m 20s"、"45s",未知则返回 "未知"。
|
||||
"""
|
||||
if seconds is None:
|
||||
return "未知"
|
||||
return "0s"
|
||||
total = max(0, int(round(seconds)))
|
||||
hours, rem = divmod(total, 3600)
|
||||
minutes, secs = divmod(rem, 60)
|
||||
@@ -142,7 +142,7 @@ def format_filament(weight_grams: float | None, used_m: float | None = None) ->
|
||||
格式化后的耗材信息字符串,未知则返回 "未知"。
|
||||
"""
|
||||
if weight_grams is None and used_m is None:
|
||||
return "未知"
|
||||
return "0.00 g"
|
||||
parts: list[str] = []
|
||||
if weight_grams is not None:
|
||||
parts.append(f"{weight_grams:.2f} g")
|
||||
|
||||
@@ -423,7 +423,7 @@ class MainWindow(QMainWindow):
|
||||
table_layout.addWidget(self.table)
|
||||
|
||||
# --- 合计统计标签 ---
|
||||
self.total_summary_label = QLabel("合计:0 板 | 时间:未知 | 耗材:未知")
|
||||
self.total_summary_label = QLabel("合计:0 板 | 时间:0s | 耗材:0.00 g")
|
||||
table_layout.addWidget(self.total_summary_label)
|
||||
file_body.addLayout(table_layout, 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user