okay code:
#!/usr/bin/python
import wx
import sys
class XPinst(wx.App):
def __init__(self, redirect=False, filename=None):
wx.App.__init__(self, redirect, filename)
def OnInit(self):
frame = wx.Frame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)
panel = wx.Panel(frame, -1)
log = wx.TextCtrl(panel, -1, size=(500,400), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
redir=RedirectText(log)
sys.stdout=redir
print 'test'
frame.Show()
return True
class RedirectText:
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl
def write(self,string):
self.out.WriteText(string)
app = XPinst()
app.MainLoop()
added:
class MyFrame(wx.Frame)
def __init__(self, parent, id, title, size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE):
wx.Frame.__init__(self, parent, id, title, size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)
replaced:
frame = wx.Frame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)
with:
frame = MyFrame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)
Now, it doesn't run...
I want to be able to call the MyFrame constructor more than once in my code passing different arguments
I tried many things...
instanciating MyFrame with all arguments
instanciating myFrame and with all, but default arguments
constructor method signature with all arguments
constructor method signature with all, but default arguments
calling parent constructor method with all arguments
calling parent constructor method with all, but default arguments
plus the tutorial http://zetcode.com/wxpython/ mentions a method where the number of default and optional arguments are different! (what's the difference?)
UDPATE:
"it has seven parameters. The first parameter does not have a default value. The other six parameters do have. Those four parameters are optional. The first three are mandatory." - http://zetcode.com/wxpython/firststeps/
UPDATE 2:
With semi-colon correction, i have just tried:
class MyFrame(wx.Frame):
def __init__(self, parent, id, title, size, style):
wx.Frame.__init__(self, parent, id, title, size, style)
- I tell what arguments are going in (second line)
- I call with the arguments that went in (third line)
UPDATE 3:
the full error message is:
Traceback (most recent call last):
File "test.py", line 29, in <module>
app = XPinst()
File "test.py", line 8, in __init__
wx.App.__init__(self, redirect, filename)
File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 7978, in __init__
self._BootstrapApp()
File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 7552, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "test.py", line 10, in OnInit
frame = MyFrame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)
File "test.py", line 21, in __init__
wx.Frame.__init__(self, parent, id, title, size, style)
File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_windows.py", line 497, in __init__
_windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))
TypeError: Expected a 2-tuple of integers or a wxSize object.
Why didn't it work?