#!/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.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
# 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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