#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 1.0.4 on Sun Apr 23 13:13:06 2023
#
import wx
# begin wxGlade: dependencies
# end wxGlade
# begin wxGlade: extracode
from pubsub import pub
from mvc_example import Env, install_package, interp # CLI 版のプログラムファイル
class Controller(object):
def __init__(self):
pub.subscribe(self.read, "Controller")
def read(self, x, env):
pub.sendMessage("Model.eval", x = x, env = env)
class Model(object):
def __init__(self):
pub.subscribe(self.eval, "Model")
def eval(self, x, env):
pub.sendMessage("View.setProperty", env = interp(x, env))
# end wxGlade
class View(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: View.__init__
self.env = Env(install_package())
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((400, 300))
self.SetTitle("ModelViewController")
grid_sizer_1 = wx.GridSizer(2, 2, 0, 0)
text = wx.StaticText(self, wx.ID_ANY, "My Money")
grid_sizer_1.Add(text, 0, wx.ALIGN_CENTER, 0)
self.add = wx.Button(self, wx.ID_ANY, "Add Money")
grid_sizer_1.Add(self.add, 0, wx.ALIGN_CENTER, 0)
# self.ctrl = wx.TextCtrl(self, wx.ID_ANY, "\"\"")
# 上を下のように改造する
self.ctrl = wx.TextCtrl(self, wx.ID_ANY, str(self.env.myMoney))
self.ctrl.Enable(False)
grid_sizer_1.Add(self.ctrl, 0, wx.ALIGN_CENTER, 0)
self.remove = wx.Button(self, wx.ID_ANY, "Remove Money")
grid_sizer_1.Add(self.remove, 0, wx.ALIGN_CENTER, 0)
self.SetSizer(grid_sizer_1)
self.Layout()
pub.subscribe(self.setProperty, "View")
self.Bind(wx.EVT_BUTTON, lambda event: pub.sendMessage("Controller.read", x = self.add.GetLabel(), env = self.env), self.add)
self.Bind(wx.EVT_BUTTON, lambda event: pub.sendMessage("Controller.read", x = self.remove.GetLabel(), env = self.env), self.remove)
# end wxGlade
def setProperty(self, env):
'''このメソッドを追加する'''
self.env = env
# SetValue で TextCtrl の内容を変更する
# https://d...content-available-to-author-only...n.org/wx.TextEntry.html#wx.TextEntry.SetValue
self.ctrl.SetValue(str(env.myMoney))
# end of class View
class MyApp(wx.App):
def OnInit(self):
self.View = View(None, wx.ID_ANY, "")
self.SetTopWindow(self.View)
self.View.Show()
return True
# end of class MyApp
if __name__ == "__main__":
m = Model() # ここを追加
app = MyApp(0) # View
c = Controller() # ここを追加
app.MainLoop()
IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwojIC0qLSBjb2Rpbmc6IFVURi04IC0qLQojCiMgZ2VuZXJhdGVkIGJ5IHd4R2xhZGUgMS4wLjQgb24gU3VuIEFwciAyMyAxMzoxMzowNiAyMDIzCiMKCmltcG9ydCB3eAoKIyBiZWdpbiB3eEdsYWRlOiBkZXBlbmRlbmNpZXMKIyBlbmQgd3hHbGFkZQoKIyBiZWdpbiB3eEdsYWRlOiBleHRyYWNvZGUKZnJvbSBwdWJzdWIgaW1wb3J0IHB1Ygpmcm9tIG12Y19leGFtcGxlIGltcG9ydCBFbnYsIGluc3RhbGxfcGFja2FnZSwgaW50ZXJwICMgQ0xJIOeJiOOBruODl+ODreOCsOODqeODoOODleOCoeOCpOODqwoKY2xhc3MgQ29udHJvbGxlcihvYmplY3QpOgogICAgZGVmIF9faW5pdF9fKHNlbGYpOgogICAgICAgIHB1Yi5zdWJzY3JpYmUoc2VsZi5yZWFkLCAiQ29udHJvbGxlciIpCiAgICBkZWYgcmVhZChzZWxmLCB4LCBlbnYpOgogICAgICAgIHB1Yi5zZW5kTWVzc2FnZSgiTW9kZWwuZXZhbCIsIHggPSB4LCBlbnYgPSBlbnYpCgpjbGFzcyBNb2RlbChvYmplY3QpOgogICAgZGVmIF9faW5pdF9fKHNlbGYpOgogICAgICAgIHB1Yi5zdWJzY3JpYmUoc2VsZi5ldmFsLCAiTW9kZWwiKQogICAgZGVmIGV2YWwoc2VsZiwgeCwgZW52KToKICAgICAgICBwdWIuc2VuZE1lc3NhZ2UoIlZp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