初始化

This commit is contained in:
rxy
2026-05-18 11:33:59 +08:00
commit b22e46dd60
20 changed files with 1440 additions and 0 deletions

24
demo/mvvm/binder.py Normal file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
绑定层。
binder 的职责是把 View 和 ViewModel 连接起来:
1. 把界面控件信号连接到 ViewModel 的事件函数。
2. 把 Model 与 View 交给框架建立数据绑定。
"""
from mvvm.view_model import *
from mvvm.view import *
def binding_main_ui(ui: MainWinView, vm: MainWinVM):
"""绑定主窗口 UI 与主窗口 ViewModel。"""
# 绑定 PyQt 控件事件:按钮点击后调用 ViewModel 中的业务方法。
ui.YesBtn.clicked.connect(vm.event_log_yes)
ui.NoBtn.clicked.connect(vm.event_log_no)
# 建立双向绑定。
# 当前 demo 实际使用的是 Model -> Viewmodel_log 改变后刷新 view_log。
# 因为 view_log 没有主动发布事件,所以 View -> Model 方向暂时不会触发。
fw_proxy.binding(vm.model_log, ui.view_log)