[wxPython-users] Binding with parameters?
Christopher Barker
Chris.Barker at noaa.gov
Tue Jul 17 09:56:04 PDT 2007
Chris Mellon wrote:
> Here the lambda is creating a new function object.
I was going to suggest the same thing...
> Now, all that said, from what you've shown I don't think that this is
> the best solution.
But I agree. I mostly use the lambda trick when I am auto-generating a
bunch of controls -- I may have ten similar buttons, and I want each one
to be bound to the same callback, but indicate which button was pressed,
for instance.
In this case, I'd keep it simpler.
> Try using the wx.Log classes or the python standard
> logging class
Or save the path as a class attribute:
self.logFilePath = HoweverThatIsSet
self.createConditionActionSetButton = wx.Button(self.panel_left,
label="Create Condition - Action Set", pos=(0, 20), size=(200,20))
self.Bind(wx.EVT_BUTTON,
self.OnCreateConditionActionSet,
self.createConditionActionSetButton)
And here the function:
def OnCreateConditionActionSet(self, evt, path):
logfile = open(self.logFilePath, 'r+')
print 'create c a set'
If that logfile is accessed from a lot of different places in your code,
store the path in a config module of some sort.
Oh, you can clean up that Bind() call a bit too:
self.createConditionActionSetButton.Bind(wx.EVT_BUTTON,self.OnCreateConditionActionSet)
See:
http://wiki.wxpython.org/wxPython_Style_Guide
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list