<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>WxPython on shocksolution.com</title><link>https://shocksolution.com/tags/wxpython/</link><description>Recent content in WxPython on shocksolution.com</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 16 Aug 2008 20:47:05 +0000</lastBuildDate><atom:link href="https://shocksolution.com/tags/wxpython/index.xml" rel="self" type="application/rss+xml"/><item><title>Redirecting text output from Python functions</title><link>https://shocksolution.com/posts/redirecting-text-output-from-python-functions/</link><pubDate>Sat, 16 Aug 2008 20:47:05 +0000</pubDate><guid>https://shocksolution.com/posts/redirecting-text-output-from-python-functions/</guid><description>&lt;p&gt;Two posts ago, I described how I wrote a function in Python that reads in a binary file from Labview. In my last post, I described using wxPython to write a GUI to process the data from those binary files. Naturally, I called the binary-file-reader function from the GUI. The problem is that the file reader prints a lot of information to the terminal, using Python &lt;strong&gt;print&lt;/strong&gt;statements. None of this goes to the GUI, requiring the user to run the GUI from a terminal and keep an eye on the text output, which is inconvenient. However, I don&amp;rsquo;t want to modify the file reader to include GUI-specific code, because that would be less modular and less re-usable. Instead, I learned that Python has a very easy facility to redirect&lt;strong&gt;stdout&lt;/strong&gt;, the default destination of the &lt;strong&gt;print&lt;/strong&gt; statement. I modified the file reader as follows:&lt;/p&gt;</description></item><item><title>Fun with threads in Python and wxPython</title><link>https://shocksolution.com/posts/fun-with-threads-in-python-and-wxpython/</link><pubDate>Mon, 11 Aug 2008 22:12:07 +0000</pubDate><guid>https://shocksolution.com/posts/fun-with-threads-in-python-and-wxpython/</guid><description>&lt;p&gt;I have finally gotten back to programming in the last couple of days.  Our project has finally started to generate a lot of data, so I&amp;rsquo;ve been refactoring and improving my code that &lt;a href="https://shocksolution.com/blog/2008/06/25/reading-labview-binary-files-with-python/" title="Reading%20Labview%20binaries%20with%20Python"&gt;reads data stored in LabView binaries&lt;/a&gt;.  Today I spent a lot of time creating a GUI for browsing data.  Arguably, this wasn&amp;rsquo;t the best use of my time, but I learned a lot about multi-threaded Python GUI programming with wxPython.  You can find a gold mine of &lt;a href="http://wiki.wxpython.org/LongRunningTasks" title="Multi-threading%20with%20wxpython"&gt;information on the multi-threaded wx programming&lt;/a&gt; at the wxPython wiki.  Because the LabView binary data has to be read sequentially, and the files are rather large, it takes a long time to read in a file.  I spawn a thread to handle the file reading,  while allowing the GUI to remain responsive.  The thread posts messages to the GUI window, which are used to update the user on the status of the file reading operation.  When the file is read, a final message containing the data is posted to the window.  It&amp;rsquo;s really pretty slick now that I&amp;rsquo;ve figured out how to do it. I will soon post a clever scheme to capture text output from the file-reading function, and display it in the GUI, without making substantial changes to the file-reading function.&lt;/p&gt;</description></item></channel></rss>