初始化
This commit is contained in:
26
demo/mvvm/view_model.py
Normal file
26
demo/mvvm/view_model.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
ViewModel 层。
|
||||
|
||||
ViewModel 连接界面操作与业务数据:按钮点击后不直接操作界面,
|
||||
而是修改 Model;Model 再通过事件通道通知 View 刷新。
|
||||
"""
|
||||
from mvvm.model import *
|
||||
|
||||
|
||||
class MainWinVM(object):
|
||||
"""主窗口 ViewModel:保存主窗口需要的数据模型和按钮事件逻辑。"""
|
||||
|
||||
def __init__(self):
|
||||
# 创建日志内容 Model。
|
||||
# 主题 "log_to_view" 表示:这个 Model 的变化要通知日志 View。
|
||||
self.model_log = StringModel('log_to_view', '启动日志')
|
||||
|
||||
def event_log_yes(self):
|
||||
"""Yes 按钮点击事件:写入一条 yes 日志。"""
|
||||
self.model_log.value = 'log: yes!!!'
|
||||
|
||||
def event_log_no(self):
|
||||
"""No 按钮点击事件:写入一条 no 日志。"""
|
||||
self.model_log.value = 'log: no~~~'
|
||||
Reference in New Issue
Block a user