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

Prasad, Ramit ramit.prasad at jpmorgan.com
Tue Jun 4 18:28:36 CEST 2013


Matt D wrote:
> Hello,
> 
> I am using an open source wxPython GUI that I like very very much. I
> have ideas about some modifications I need but I cannot be bothering the
> author too much so I must learn some very specific things about Python
> in order to make the modification myself.  First, I need some help
> understanding the code behind this GUI.  From reading the comments I
> understand that the part of the program written in C++ sends a Python
> pickled dictionary to a msg_queue and when Python decodes the pickle the
> TextCtrl fields (in the wxPython GUI I am using) receive/display the
> appropriate values. And as new messages are received by Python the GUI
> fields are cleared to display the new values.
> 
> For starters I would like the values to be displayed on the GUI in some
> sort of a scrolling panel as they are cleared from the TextCtrl fields
> so the user can watch recent activity.  I dont know what the best way to
> do this would be; the wxpython.scrolledPanel widget?  I am unclear if
> this can be put on the same GUI pane as the TextCtrl fields are and I am
> unclear about if I can take the values from the TextCtrl fields or have
> to use the pickle or what? I dont see any variables declared (like in
> Visual Basic) so its not like I can just make a list and a textbox and
> print it.

Scrolled panel is just a graphical container that allows for scrolling inside,
but it is the window that scrolls not widgets inside it. This of it like
a webpage that scrolls. If you use web email the text widget in the 
email needs to scroll so you can see your full email context and not 
just scroll the page.

You will probably need to create a TextCtrl with the appropriate style
and append your new data. I have given an example below that should
automatically scroll with your new data.

#in __init__
self.scrolling_widget = wx.TextCtrl( self, wx.ID_ANY, '', size=(-1, 275), style=wx.TE_AUTO_SCROLL|wx.TE_READONLY|wx.TE_PROCESS_ENTER|wx.TE_WORDWRAP|wx.TE_MULTILINE )

You will probably have to edit TrafficPane.update so that it performs 
the action you want. BTW, the widgets are all stored in self.fields. 
You will need to look at the init to see how they stored to get the 
correct field if you want to change existing field behavior. 

self.fields["dest"] # Destination TextCtrl

That being said, for your desired effect I think all you need to do
is change:

v.SetValue(f)

to:

old_text = v.GetValue()
# You may need to modify or add some context as otherwise it will
# just dump the data and may not make sense when looking at it
# scroll.
self.scrolling_widget.AppendText(old_text)
v.SetValue(f)

> 
> More importantly I need to save the values from the TextCtrl fields,
> preferable in a CSV file, for later inspection.  From looking at the
> Logging HOWTO and the Logging Cookbook I see there are alot of loggers
> available, or ways to log, but they all look like they are orientated
> towards exception handling and debugging so I am unsure what is the best
> way to go about this; maybe wxLogTextCtrl ?  Utimately I need to log the
> values from the TextCtrl fields in a row of comma separated values
> adding a time/date stamp as one of the values.  I need this log so the
> data can easily be worked on in excel or SAS.  I need the time/date
> stamp for time series analysis.

Create a list of lists with your data (think table). Then use the 
csv module to write that data to file. If you need to append,
You should read all the existing data. Close the file, append
your new data and then write to a new complete file. Once
the write has succeeded, rename/overwrite the existing file.
That will help prevent you from losing existing data if a problem 
occurs on write. 

# Sort the dictionary keys so you get the same order for each row
row = [ field_values[k] for sorted(field_values) ]
# Now read csv, append row, write new csv, and then overwrite old file

> 
> I attached the code behind the wxPythoin GUI I am using.
> Any help will be much appreciated.
> 
> Thanks in advance
> --
> Matt D
> ------------

Well that should get you started. Post back if you need specific
help with something else.



~Ramit


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