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

Prasad, Ramit ramit.prasad at jpmorgan.com
Mon Jun 10 17:53:06 CEST 2013


Adding attribution back (I wrote the original quoted bit). Please leave
the attribution as I have done below otherwise it is unclear who said
what. 

Matt D wrote:
> [Ramit Prasad wrote:]
> > It looks to me like there is a separate thread that pulls data off some queue
> > and then hands it to WX in the form of a DataEvent. WX calls display_data
> > which unpickles the data. Pickle is just a format of storage and can store
> > all Python built-in types. It seems that what is stored is a Python
> > dictionary. In fact, you can probably add (and should add) a print statement
> > to print attrs in display_data to see the data. It's always important to know
> > what your data looks like. If you are only familiar with Visual Basic and C++,
> > you may want to familiarize yourself with Dictionaries (aka Hashmaps). They
> > are basically containers with key-value pairs for unique keys. By knowing the
> > name of the data you want (for example "duid") you can retrieve the value and
> > post it back to the appropriate TextCtrl.
> >
> 
> Hey,
> So is the separate thread is this??:
> 
> import gnuradio.gr.gr_threading as _threading

Well that is the threading base class. traffic_watcher_thread is the
class that actually which does the threading.

> 
> This is how the pickled data is brought into the wxPython UI? I have
> been unable to find any explanation on the web about the wxDATA_EVENT?
> 
> The 'class traffic_watcher_thread(_threading.Thread):' is this what
> waits on the message queue for another frame of pickled data to come in?

Yes that class is what does the waiting for data / threading bit.

> 
> One of the main problems I have with understanding the Python code I
> have shared is that the pickle comes from C++ code.  The program uses
> C++ for what is computational intense and it uses Python for the UI and
> for sending the data stream between the C++ blocks.  I have never tried
> modifying code in a program that uses two languages before.

Unless you have an academic curiosity, you really don't need to 
bother with what the C++ does. Knowing the data it returns is a good
idea.

> 
> From python.org/2/library/pickle:
> "Perhaps the most obvious thing to do with these byte streams is to
> write them onto a file" and  sense "the pickle data format uses a
> printable ASCII representation" . . . "it is possible for a human to
> read the pickled file with a standard text editor."  I would love to
> have this wxPython code write the pickled data to file just to see
> exactly what is in it.  Do you know of some sort of code I can put in to
> make the pickle write to a file?  I think this is the best starting
> point instead of playing with the UI.

Why not just print field_values from TrafficPane.update? I wouldn't
get caught up too much in the pickle data format. What you care
about is what it returns. So print the returned data (after
it is already unpickled). 

Writing to file is also a reasonable endeavor, the below
sample will write to file, but it will overwrite the file
each time you get new data. You can change 'w' to 'a' (I think)
for append mode which will then append to the bottom of the file. Not sure 
how fast your data will grow so you may want to watch the file size.
You may also want to look at the pprint std library instead of str. 
It helps to format objects when being logged/printed to make them
easier to see. For this example you would replace `str` with
`pprint.pformat` (and appropriate arguments).

# using open as a context manager will open and close file automatically
with open( r'c:\unpickled_data.txt', 'w' ) as f:
    f.write( str(field_values) )
    


> 
> Thank you very much for your attention.
> Cheers,
> Matt
> 

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list