[Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

Dave Angel davea at davea.name
Thu Jun 13 14:22:00 CEST 2013


On 06/13/2013 12:18 AM, Matt D wrote:
>
>
>    <SNIP>
>>
>>
> yes the .py file has TextCtrl fields that get there values from a
> pickled dictionary.  Another peice of the code watches a thread for the
> pickle.  this is why i didnt use a list.  I have been unable to find a
> nice way to just make a list with the items i need.  would be nice to
> have that simplicity.
> What you said is true, the the list is unordered.  More importantly the
> new line comes in at the wrong point.  I want all the values in a row
> starting with time.  from there i will look for a way to remove some
> unwanted items and ordering the others.
> I attached the .py file for you to see the whole thing hoping this is
> not too presumptuous.  Thanks.
>
>

I don't mind the attached source file.  Note that some readers may not 
be able to see it (attachments aren't guaranteed to survive), and others 
might find it excessive in length.  But I'm fine with it.

I notice you didn't change the newline to a comma, in the place that I 
commented earlier.  You explicitly separate the fields with newlines, 
while commenting that it's done with commas.

What you presumably want is to change the line inside the loop

     self.logfile.write('\n')
to
     self.logfile.write(',')

and add one of the former lines outside the loop, after writing the last 
field.

About the ordering:  Do you have a specific ordering in mind?  Who 
decides it?  The program that creates the pickle?  How tightly bound are 
the two?  Is there a 3rd program that's going to read the csv file?  Are 
all of these programs written in Python?  Will there be multiple 
versions, over time?

If all of these programs have to share the same definition for the csv 
file, then at least some of it should be in common code.  Simplest is to 
have the list/tuple of field names as a real list, defined in a module 
that they all import.  Then, instead of using self.fields.items(), you 
use something like common.FIELD_LIST_NAMES

common.py might have a line something like:

#define the tuple of names that will be used for the csv file
FIELD_LIST_NAMES = ("date", "duid", "nac", "source", "dest", "mfid", 
"algid", "kid", "mi", "tgid")

Notice that TrafficPanel.init() might well collapse into a loop, if you 
add just a little more information into common.py  Then you'd find that 
editing the one place adds a new field, both to the csv file but also to 
the gui.

However, then if you add a new field, or remove one, you're obsoleting 
any csv files that may still be lying around, with no way to detect 
which ones are new and which ones are old.  Typically this is managed 
with a version field in the first line of the file.

But another, more standard, way to manage this is to make it a real csv 
file, with the field names in the first line (also comma separated). 
Python has a csv module, which solves another potential problem your 
logic may have:  what happens if any of those values has a comma in it?


I know I only hinted at the possible implementations, but until you make 
some architectural choices clear, I really cannot add much more.

Here are some other remarks about the code:

line 53:  method Clone() should be lowercase, per Pep8.  I don't believe 
it does anything useful, but you don't call it anyway.

line 76:  deleting a local just before a method returns does exactly 
nothing.  When the method ends, the local will go out of scope, and the 
effect in either case is to decrement the refcount for the created 
DataEvent instance.

Incidentally, if you happen to be using Thunderbird, you might look for 
the Reply-List button.


-- 
DaveA


More information about the Tutor mailing list