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

Dave Angel davea at davea.name
Fri Jun 14 22:17:12 CEST 2013


On 06/14/2013 03:59 PM, Matt D wrote:
> 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?

Don't replace anything till you understand it.  But if you think you do 
then my code replaces the part starting at the for loop.
>
> 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.

I don't know anything about LUDI or HDU.  But perhaps you're saying that 
some fields aren't in every pickle, but the value in the csv for each 
line should be the last one pickled.  In that case, you have a big logic 
flaw in your code.  When you output your stuff to the logfile, you use 
only the values in field_values, not any values previously stored in 
self.fields.  Do you perhaps mean that whenever a value is missing from 
the pickle, you want to use the one from self.fields?

If you happened to want exactly this, you could add the two middle lines 
as below.  something like:

               f = field_values.get(k, None)
               if f is None:                           #add me
                   f = self.fields.get(k, None)        #add me
               if not f is None:

But clearly, that's much more specific than you've ever been.  There are 
also better ways to do it if that's exactly what you want.


>  still haven't found a way to get to view the serialized
> data.

print field_values, right at the beginning of update().  Or you could 
pretty it up, by looping through its items().



-- 
DaveA


More information about the Tutor mailing list