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

Matt D md123 at nycap.rr.com
Fri Jun 14 21:59:39 CEST 2013


On 06/14/2013 03:14 PM, Dave Angel wrote:
> On 06/14/2013 10:48 AM, Matt D wrote:
>> Hey,
>> here is a snip of my code.
>>
>> #logger code----------------------------------------------
>>         #  first new line
>>         #self.logfile.write('\n')
>>         #  date and time
>>         #self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S",
>> gmtime()))))
>>         #  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is
>> what we want
>>         tmplist = []
>>         tmplist.append(str(strftime("%Y-%m-%d %H:%M:%S", localtime())))
>>         tmplist.append(field_values["nac"])
>>         tmplist.append(field_values["tgid"])
>>         tmplist.append(field_values["source"])
>>         tmplist.append(field_values["dest"])
>>         tmplist.append(field_values["algid"])
>>
> 
> tmplist is an unnecessary complication.  Did you look at my sample loop,
> which I'll repeat here with a correction:
> 
> 
>         for k in FIELD_LIST_NAMES:
>             #  get the value of the current TextCtrl field
>             f = field_values.get(k, None)
>             if not f is None:
>                 #output the value with trailing comma
>                 self.logfile.write('%s,'%(str(f)))
>             else:
>                 self.logfile.write(",")
>         self.logfile.write("\n")
> 
> This code preserves your original feature of not crashing when the C++
> program fails to fill in all your expected keys. It also makes sure
> there will be unadorned commas for missing fields, making it possible
> for a spreadsheet to read the columns correctly.
> 
> If you want to populate a list first, by all means do so, but do it in a
> loop, using the FIELD_LIST_NAMES as keys.
> 
> One thing I didn't handle was the date field.  I'd do that by adding it
> to the field_values dict, or to a copy of it. That way, it's all
> consistent, even though one field comes from local and the rest from the
> pickle.
> 
> 
yes acutally this templist business broke my code.  the TectCtrls in the
traffic panel would were not being populated and the logfile.csv was
empty.

So should i replace:

#logger code---------------
        #  first new line
        self.logfile.write('\n')
        #  date and time
        self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S",
localtime()))))
		#  loop through each of the TextCtrl objects
        for k,v in self.fields.items():
            #  get the value of the current TextCtrl field
            f = field_values.get(k, None)
            if f:
                #  output the value with trailing comma
                self.logfile.write('%s,'%(str(f)))		
		#end logger code ----------------

With the code you posted above?

I am pretty sure that the reason i don't get the 'source' and 'dest'
fields is because of this:

#if the field 'duid' == 'hdu', then clear all the fields
        if field_values['duid'] == 'hdu':
            self.clear()

since the 'source' and 'dest' are in the LUD1 and not the HDU so it
doesn't update when the LDU1 comes through (if the LDU1) does actually
get serialized.  still haven't found a way to get to view the serialized
data.


More information about the Tutor mailing list