Sharing Events and Data Between Frames

Greetings –

I guess my previous post was too lengthy!

Is superclassing the best way to share data between frames
in a single application?

What about events? For example:

If I have a frame with a text box
and a button, how can I make the button update ‘send’ an update to
another frame with a text box?

I have an OnClick that does a
GetValue on the text box. How can I use that to SetValue the other text box in
a different frame?

Any guidance would be GREATLY appreciated,

Hal Kurz

Hi Hal,

Just use a reference to the other frame. Here is a small example showing you how to do it:

#----------------------start-----------
import wx

class FrameBase(wx.Frame):
def init(self, title):

    wx.Frame.__init__(self, None, title=title)
    self.txt = wx.TextCtrl(self)
    self.txt.Bind(wx.EVT_TEXT, self.OnText)

def OnText(self, evt):
    if 'otherFrame' in dir(self):

        self.otherFrame.txt.SetValue(self.txt.GetValue())
    evt.Skip()

if name ==“main”:
app = wx.App(0)
f1 = FrameBase(“Frame One”)
f2 = FrameBase(“Frame Two”)

f2.otherFrame = f1 #the reference ;)
f1.Show()
f2.Show()
app.MainLoop()

#----------------------the end-----------

Typing in the Frame2 will automaticaly update in the Frame1.

Peter.

···

On 2/26/07, ITC Python python@itccinc.com wrote:

Greetings –

I guess my previous post was too lengthy!

Is superclassing the best way to share data between frames
in a single application?

What about events? For example:

If I have a frame with a text box
and a button, how can I make the button update ‘send’ an update to
another frame with a text box?

I have an OnClick that does a
GetValue on the text box. How can I use that to SetValue the other text box in
a different frame?

Any guidance would be GREATLY appreciated,

Hal Kurz


There is NO FATE, we are the creators.

ITC Python wrote:

Any guidance would be GREATLY appreciated,

Depending on how large and complex you expect your app to be you might want to begin investigating organizing it around a MVC (Model-View-Controller) pattern.

   http://wiki.wxpython.org/index.cgi/ModelViewController

The app I'm doing right now has grown large enough that it would have been impossible to organize all the gui-gui and gui-data interactions without MVC. That said, I think some of the stuff people do in MVC goes too far. IMHO.

In any case, you'll probably learn a lot by reading up on it.

Michael