|
|
|
|
@ -9,6 +9,16 @@ from config import Cmd
|
|
|
|
|
|
|
|
|
|
class GlobalParamsPage(BasePage):
|
|
|
|
|
def __init__(self, parent, tcp_client):
|
|
|
|
|
# 先定义同步模式映射关系
|
|
|
|
|
self.sync_mode_mapping = {
|
|
|
|
|
"PT外同步,B码外同步": 0,
|
|
|
|
|
"PT内同步,B码外同步": 1,
|
|
|
|
|
"PT外同步,B码内同步": 2,
|
|
|
|
|
"PT内同步,B码内同步": 3
|
|
|
|
|
}
|
|
|
|
|
self.reverse_sync_mode_mapping = {v: k for k, v in self.sync_mode_mapping.items()}
|
|
|
|
|
|
|
|
|
|
# 然后调用父类的__init__
|
|
|
|
|
super().__init__(parent, tcp_client, "全局参数")
|
|
|
|
|
|
|
|
|
|
# 配置样式
|
|
|
|
|
@ -61,7 +71,8 @@ class GlobalParamsPage(BasePage):
|
|
|
|
|
{"label": "心跳包周期", "attr": "heartbeat_period", "type": "spin", "args": (1, 3600), "unit": "s",
|
|
|
|
|
"readonly": False},
|
|
|
|
|
{"label": "通道使能掩码", "attr": "ch_en_mask", "type": "hex_entry", "unit": "", "readonly": False},
|
|
|
|
|
{"label": "同步模式", "attr": "sync_mode", "type": "combo", "options": ["外同步", "内同步"],
|
|
|
|
|
{"label": "同步模式", "attr": "sync_mode", "type": "combo",
|
|
|
|
|
"options": list(self.sync_mode_mapping.keys()), # 使用映射的键作为选项
|
|
|
|
|
"readonly": False},
|
|
|
|
|
{"label": "内同步频率", "attr": "pt_internal_period", "type": "spin", "args": (40, 300), "unit": "",
|
|
|
|
|
"readonly": False},
|
|
|
|
|
@ -101,13 +112,9 @@ class GlobalParamsPage(BasePage):
|
|
|
|
|
entry.configure(state='readonly', style='Readonly.TEntry')
|
|
|
|
|
|
|
|
|
|
elif field["type"] == "combo":
|
|
|
|
|
var = tk.StringVar() # 改为StringVar来存储显示文本
|
|
|
|
|
# 存储映射关系
|
|
|
|
|
self.sync_mode_mapping = {"外同步": 0, "内同步": 1}
|
|
|
|
|
self.reverse_sync_mode_mapping = {0: "外同步", 1: "内同步"}
|
|
|
|
|
|
|
|
|
|
var = tk.StringVar() # 使用StringVar存储显示文本
|
|
|
|
|
combobox = ttk.Combobox(parent, textvariable=var,
|
|
|
|
|
values=list(self.sync_mode_mapping.keys()), state="readonly", width=10)
|
|
|
|
|
values=field["options"], state="readonly", width=15) # 增加宽度以适应更长的文本
|
|
|
|
|
combobox.grid(row=i, column=1, sticky='w', padx=2, pady=2)
|
|
|
|
|
|
|
|
|
|
else: # entry
|
|
|
|
|
@ -192,11 +199,12 @@ class GlobalParamsPage(BasePage):
|
|
|
|
|
self.ch_en_mask_var.set(f"0x{config.ch_en_mask:02X}")
|
|
|
|
|
|
|
|
|
|
# 同步模式:将数字值转换为对应的文本显示
|
|
|
|
|
sync_mode_text = self.reverse_sync_mode_mapping.get(config.sync_mode, "外同步")
|
|
|
|
|
sync_mode_text = self.reverse_sync_mode_mapping.get(config.sync_mode, "PT外同步,B码外同步")
|
|
|
|
|
self.sync_mode_var.set(sync_mode_text)
|
|
|
|
|
|
|
|
|
|
self.pt_internal_period_var.set(config.pt_internal_period)
|
|
|
|
|
|
|
|
|
|
print(f"同步模式设置: {config.sync_mode} -> {sync_mode_text}")
|
|
|
|
|
print("全局参数读取成功")
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|