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

Matt D md123 at nycap.rr.com
Thu Jun 13 16:37:16 CEST 2013


On 06/13/2013 08:22 AM, Dave Angel wrote:
> 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.
> 
Hey,
line 202: self.logfile.write('%s,'%(str(f))) d
does put the comma in properly but,
line 203: self.logfile.write('\n')
was putting the newline after each value like you said.
I moved this back outside of the if statement to see (i am still a
little unsure about the indention and i have to test) if it will create
a new row only when all the k,v values have been looped through.

the ordering:  yes this is quite a hole in my understanding of what is
going on here.  the pickle is created in a collection of pretty
complicated C++ code that doesn't explicitly show how the pickle is
ordered or whats in it even in the pickle.cc and pickle.h files. the
pickle files take in some sort of stream, pickle the data, and send it
to a message queue that the trafficpanel waits on.  i need to log this
pickle or at at least dump it to terminal because i am pretty sure the
'source' and 'dest' fields (which currently are not available) are in
the pickle, albeit in a different data unit. I have read
"http://www.python.org/doc//current/library/pickle.html" two times
already and still cant find a way to print the pickle in human readable
form.  my understanding of pickling stinks.  The ordering at this point
is not so important (not nearly as important as getting the 'source'
'dest' fields) because the point of the .csv file is just to import it
into librecalc and work time series analysis on the data manually.  at
some later point in the development maybe this this task can be
automated but for now just an unordered file will suffice.

and yes i think there probably is some bit rot there its just that once
i get it running without errors i don't feel confident messing about
with other lines.

Thanks a bunch!






More information about the Tutor mailing list