Chris you're right, I could call the buttons 0, 1, 2, but it's how I started
out, before learning better techniques, and that lists start with 0.
As for what the buttons are for...
I'm writting a program that will open a log file (of the users choosing,)
and read the last entry in that log file, and pubsub it to another frame.
For example:
I want to see the log entry that contains "green hats" to go to the
frame "Green hat;" and the log entry that contains "red socks" to
go to the frame "Red socks." In real time.
So the log is continually read for the latest log entry.
Here I use container as a name for the wx.Frame with a textctrl in it
The point of the buttons, and objects in this part of the program I'm
working on is for the user to define, the label for the contianer,
the search string to be used to sort log entries that go into the container
the foreground, and background color, font, and optionally a wav fule
to note that the occurance of "X" has been publushed to it's respective
frame.
I had a few issues, and the gang here has been fantastic in helping,
teaching, mentoring, scrutinizing my code. And from time to time
knocking me around a wee-bit when my code it outright wrong.
Originally nothing was refactored. No patterns, no nothing. Every
object was coded, every bind, event handler etc... 12 buttons, 12
binds, 12 event handlers. Now I'm working with 12 buttons and scads
of other widgets more efficiently coded, and the 12 buttons, with
2 binds, and 2 event handlers to deal with the buttons.
Ultimately, I had a py file that worked..... ugly and apparantly hard to
read. I could read it today, but in the future that would not be so true.
because I'd have forgotten what the quirks were. And an EXE that
didn't work.
So I thought if I made the folks here happy that would reflect what what
py2exe was looking for to work right and be happy, and it would work
as an exe too.
Steve
···
----- Original Message ----- From: "Christopher Barker" <Chris.Barker@noaa.gov>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Wednesday, 23 July, 2008 13:04
Subject: Re: [wxpython-users] Check my refactor for efficiency please.
Again, efficiency is not the point here!
def CDefSnd(self, event):
self.btn = event.GetEventObject()
for x in range(0,5):
if self.btn == self.Containers['SndBtn']:
print x # dialog will go here (this is simpler)
event.Skip()
The bottom code works, I know that button 1, is list index 0
and button 6, is list index 5... it works.Why not call them button0, button1, etc?
But anyway, presumably each of those buttons is related to something, hopefully some object in your system. So what you really want wot know is which object the button is supposed to do some action on. In this case, perhaps you have a list of those objects, parallel to the Containers list, so you can index into that to get the object.
-Chris
--
Christopher Barker, Ph.D.
OceanographerEmergency 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 receptionChris.Barker@noaa.gov
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users