Hello,
I'm very much new to Python and I am stumbling on my first 'experiment'.
What I want to do is create an application that operates as an on-screen log viewer where Python prints information it is processing into a wxTextCrl widget (called 'sampler' in my example).
I am using Boa Constructor to build the application. The problem I am having is understanding where in the code I can send information to the application. I have seen how to pass code into an application using event handlers from within the frame, but I want the event to happen outside of this context and then push the text into the frame to be formatted (unless there is a better way to handle this). Once application.MainLoop() is called I don't seem to be able to talk to the app.
Here is where my code stands at present:
#!/usr/bin/env python
#Boa:App:BoaApp
import wx
import Frame1
modules ={'Frame1': [1, 'Main frame of Application', u'Frame1.py']}
class BoaApp(wx.App):
def OnInit(self):
self.main = Frame1.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = BoaApp(0)
application.main.sampler.AppendText('This is a test')
application.MainLoop()
if __name__ == '__main__':
main()
#Boa:Frame:Frame1
import wx
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1SAMPLER,
] = [wx.NewId() for _init_ctrls in range(2)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(563, 427), size=wx.Size(400, 250),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(392, 212))
self.sampler = wx.TextCtrl(id=wxID_FRAME1SAMPLER, name='sampler',
parent=self, pos=wx.Point(0, 0), size=wx.Size(392, 212), style=0,
value='')
def __init__(self, parent):
self._init_ctrls(parent)
So my top level object is called application.
My frame object is called main
My text control widget is called sampler
I have been using the line:
application.main.sampler.AppendText('This is a test')
to try and access the text control.
If I append text to the widget before the MainLoop() it works. If I try and append text afterwards it fails.
Can someone please point me in the right direction?