Steve Freedenburg wrote:
Is there a way to refactor event binding and event generation?
Did you see my response yesterday to your question: Is there a DRY method for events? That should help.
> I'm not after "C" speed... I'm after as fast as Python can go speed.
Again: NONE of the suggestions we've been making are about speed. Speed is irrelevant here. This is about clear, maintainable, code.
I have 12 lines that look like this:
self.Bind(wx.EVT_BUTTON, self.C1DefSnd, self.Containers[0]['SndBtn'])
...
self.Bind(wx.EVT_BUTTON, self.C6DefSnd, self.Containers[5]['SndBtn'])
You're right, that's not good, You've got a combination of building your GUI from a data structure, and building it by hand -- odd mixture.
I've lost track of what you are doing, so it may help to explain what each of these 12 buttons are supposed to do. Note that longer names might help here -- there's a brief but good discussion of that in this page:
http://swc.scipy.org/lec/style.html
That whole site is pretty good, actually.
Anyway, the question is:
What is the difference between self.C1DefSnd and self.C2DefSnd, etc?
If they are pretty different, then you probably want to put those methods in your data structure defining your buttons, like the example you will find in the thread from yesterday and today:
"Dry question"
If they are pretty much the same, then you can use one of the methods I presented in my post yesterday under:
"Is there a DRY method for events?"
which was in answer to one of your questions. Read that code. If you don't understand it, ask here.
By the way, that code is also a good example of how to write a small self contained app that tests one little aspect of how to do something in your program. If you do that with each of these problems, you will:
1) find it easier to understand what is happening
2) have a complete example you can post here for us to look at and help you with.
self.Bind(wx.EVT_BUTTON, self.C1DefFnt, self.Containers[0]['FntBtn'])
by the way, I'd write this:
self.Containers[0]['FntBtn'].Bind(wx.EVT_BUTTON, self.C1DefFnt)
It does the same thing, but I like it better because I'm clearly saying:
"bind the event from this button"
rather than
"bind the event i this frame, that, by the way, comes from this particular button"
Also, for some events, the way you wrote it may not work at all.
Do read:
http://wiki.wxpython.org/wxPython%20Style%20Guide
It will help.
-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@noaa.gov