Daniel Johnson wrote:
The error I am getting is
Traceback (most recent call last):
File "NewProject.py", line 87, in OnEdit
win = MyFrame4(self, -1, "",sim_name=sim_name)
File "NewProject.py", line 1098, in __init__
wx.Frame.__init__(self, *args, **kwds)
File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_windows.py",
line 476, in __init__
newobj = _windows_.new_Frame(*args, **kwargs)
TypeError: 'sim_name' is an invalid keyword argument for this function
It's hard to tell from just this error message, but it looks like you are passing the sim_name keyword argument into MyFrame4's __init__, then passing all the keyword args on to wx.Frame.__init__, but that doesn't know what to do with a sim_name keyword.
My intial feeling is since I am using wxGlade for designing it inserts some
**kwds from stylewx.DEFAULT_FRAME_STYLE etc
That shouldn't make a difference.
So the parameter are not being matched correctly.
That's what keyword arguments are for -- they are named, so you don't need to put them in any particular order.
Is there a simple way of taking one on one parameter give that there is
*args and **kwds in such a case.
I don't understand that question. Remember that args is a tuple, kwargs is a dict.:
When you call your _init__ like this:
MyFrame4(self, -1, "",sim_name=sim_name)
you get:
args = (self, -1, "")
kwargs = {"sim_name": sim_name}
Does it make sense to pass those on to wx.Frame.__init__ ?
one solution is to remove the "sim_name" from kwargs:
self.sim_name = kwargs["sim_name"]
del kwargs["sim_name"]
then
wx.Frame.__init__(self, *args, **kwds)
or what I wrote before, putting sim_name before the other arguments.
working code is worth a thousand words. I've enclosed a demo of both methods in use.
I don't want to past the code as it is around 50KB.
This is key: ALWAYS, when you are having a problem like this, break it out into a tiny sample that does just the little bit you are trying to figure out. Then either:
A) you'll figure it out yourself as you isolate the problem
or
B) You'll have a nifty little sample to post on the list here and get help with.
The code I've enclosed only took me about 10 minutes to write, but it would have been 1 minute to fix yours if you had written it.
-Chris
junk.py (984 Bytes)
···
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov