[Tutor] Need Help Modifying a wxPython GUI (scrolling display and logging)
Prasad, Ramit
ramit.prasad at jpmorgan.com
Wed Jun 5 17:13:47 CEST 2013
Please always CC the list. It's to your benefit as other people
might be able to answer faster or better. Thanks for bottom posting
and plain text emails.
Matt D wrote:
> On 06/04/2013 12:28 PM, Prasad, Ramit wrote:
> > 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.
> >
>
> Hello,
>
> Thank you Ramit for your reply. I haven't had time to yet use the code
> you have given me but will soon. But first, I am confused as to how the
> code knows what values to display? I understand that the data comes out
> of a 'pickle" but I don't understand how or how it is possible for
> you/me (or us) to take only what we need out of the pickle without using
> variable names (i have only used Visual Basic and C++).
>
> Also, should I just put the code into the file that is running in my
> program? It doesn't need to be compiled right? I have not figured a way
> to use an IDE because the code needs that pickle.
>
> Cheers,
> Matt
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.
More information about the Tutor
mailing list