How can I databind the value self.text in MyModel to the controls in the wx.Frame?
When the text control changes the text I would like the label to change aswell as the contents of the other text control automatically. (ideally without having to write any code if that's possible)
Note: this is a dummy example below to illustrate the general problem which may get more complicated as more fields are added to both the view and the model
import wx
class MyModel(object):
def __init__(self):
self.text = "hello"
class MyRegion(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="My Region")
self.model = MyModel()
self.label = wx.StaticText(self, label=self.model.text)
self.textbox = wx.TextCtrl(self, value=self.model.text)
self.textbox2 = wx.TextCtrl(self, value=self.model.text)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.label, 0, wx.ALL, 5)
sizer.Add(self.textbox, 0, wx.ALL, 5)
sizer.Add(self.textbox2, 0, wx.ALL, 5)
self.SetSizer(sizer)
if __name__ == "__main__":
app = wx.App()
frame = MyRegion(None)
frame.Show()
app.MainLoop()
- Is there a data/model-centric approach to this as opposed to having to bind the views events to code so that that code update the model which then triggers some more code which updates the rest?
- If there isn't then what mechanisms/recommended approaches are there which would be used to trigger updates to the view once the model has been updated?