25 lines
853 B
Python
25 lines
853 B
Python
#!/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 -> View:model_log 改变后刷新 view_log。
|
||
# 因为 view_log 没有主动发布事件,所以 View -> Model 方向暂时不会触发。
|
||
fw_proxy.binding(vm.model_log, ui.view_log)
|