Shawn Driscoll's Tech Blog

Stuff That Happened in the Past

Tuesday, March 25, 2014

Tuesday, February 25, 2014

Some Sound Advice for Old Python and Py2exe Users

I've recently been working on a hobby Python 2.5 app involving audio from .WAV files. The program uses PyQt4 for its GUI, which was laid out using Qt Designer. This meant that, not only was I using QApplication for my program's chassis, but I could use .QRC files to fuel it.

But first, I want to show a "before" image.

Let's say your Python program plays certain .WAV files during its execution. I happened to be using QSound from PyQt to play the audio. This worked out well enough for me. I had the .WAV files in their own "sounds\" folder. The problem though was when I used Py2exe to distribute my app. I was having to manually copy my .WAV files into the dist folder after each version update because Py2exe didn't know to bundle them. On the Py2exe site, I found this way of getting the copying done for me.

from distutils.core import setup
import py2exe

data_files = [
              (r'sounds', [r'sounds\activated.wav',

This is just a snip from the script I use that imports and runs Py2exe. First, a "sounds" folder is created in the "dist" folder. Then the .WAV files are copied to it from their "sounds\" folder. No more having to manually copy these files over each time.

So this was working out swimmingly until I thought I'd give glob a try.

from distutils.core import setup
import py2exe

import glob

data_files = [
              (r'sounds', glob.glob(r'sounds\*.wav'))

The glob module allows "*.*" copying of files. So that was pretty cool. I didn't have to remember filenames to include in my list.

But then yesterday, I had the great idea I was going to put my .WAV files into a Python script and import it. I would list the filenames in a special .QRC file and then convert it to a Python file. That way the audio files could not be found or tampered with after distributing. Well... The QSound module I was using wanted nothing to do that with. So I went to the Qt Google+ Community and asked if this was even do-able. I was told to use the Phonon module to play such audio files.

Done. Here is a video showing an "after" image.

Monday, February 17, 2014

Wednesday, February 5, 2014

Getting Py2exe to Work With Matplotlib for Python 2.5

I just started playing around with Matplotlib in Python 2.5.4. I love it so far. And, of course, I just had to make a Windows EXE file from a project I was working on. Nothing but crashes using Py2exe until I learned about glob.

The problem I was having was with the Matplotlib data files not being included/found when running the EXE. At the CMD prompt, I enter py2exe as usual.

The code is below:

# Used successfully in Python 2.5.4 for py2exe and matplotlib
from distutils.core import setup
import py2exe

import glob
opts = {'py2exe': {'includes': ['matplotlib.backends',
                                'matplotlib.figure', 'pylab', 'numpy',
                   'excludes': ['_gtkagg', '_tkagg', '_agg2', '_cairo', '_cocoaagg',
                                '_fltkagg', '_gtk', '_gtkcairo'],
                   'dll_excludes': ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll']

data_files = [(r'mpl-data', glob.glob(r'C:\Python25\Lib\site-packages\matplotlib\mpl-data\*.*')),
                  (r'mpl-data', [r'C:\Python25\Lib\site-packages\matplotlib\mpl-data\matplotlibrc']),
                  (r'mpl-data\images', glob.glob(r'C:\Python25\Lib\site-packages\matplotlib\mpl-data\images\*.*')),
                  (r'mpl-data\fonts', glob.glob(r'C:\Python25\Lib\site-packages\matplotlib\mpl-data\fonts\*.*'))]

# for console program use "console = [{'script': ''}]"
# for windows program use "windows = [{'script': '3d6_line_bar.pyw'}]"
setup(windows = [{'script': '3d6_line_bar.pyw'}], options=opts, data_files=data_files)

Wednesday, January 29, 2014

Python Programming: Building Character

I recently posted a YouTube video showing how to quickly generate the beginnings of a role-playing character for Traveller, using Python 2.5.4.

The source code is below:

from random import randint

char_name = ['STR', 'DEX', 'END', 'INT', 'EDU', 'SOC', 'PSI']

char = [0,0,0,0,0,0,0]

for i in range(len(char_name)):
    char[i] = randint(1,6) + randint(1,6)
for i in range(len(char_name)):
    print '%s: %d' % (char_name[i], char[i])

I may do more such posts here in the future, now that I've recently learned how to properly post program code.

Tuesday, January 14, 2014

Use Jython to do Screen Capture Videos

I'm trying out Drew's code from

I'm using Eclipse 4.3 with PyDev 3.2 to run this Jython 2.5.4rc1 program. The installed Java JDK 1.7.0_45 library contains the actual screen capture routine.

Monday, January 13, 2014

Python 3 is not Python

There was a time when Python was mature enough as a language for me to leave other languages I didn't care for and program strictly in Python. There was a time when Python programming was fresh and fun, yada yada. A time when print was a statement and not a function. A time when all the more interesting modules were written for Python, etc etc.

That time was Python 2.5.

Now Python has regulated itself to being updated just for the sake of being updated, making it less compatible or interesting for those that enjoyed the programming language enough to leave other languages.

Python 2.5 is for the computer programmer.

Python 3.x is for the software developer.

It's an entirely different mindset that Python 3 users come from. It's a job now, rather than a hobby. It's a corporate regulation rather than a computer artist's tool. Python 2.5 follows the Zen of Python, while Python 3 does not.

If I had my way, Python 3 would be renamed to something else. Because it is a different language, I mean, different development solution. And it doesn't run Python 2.5 code. Period.

Friday, January 10, 2014

Lessons From '70s Star Trek Arrays

Star Trek: The Mainframe Game was based on two-dimensional arrays. One for mapping sectors. And one for mapping quadrants. These were the short and long-range sensor scans that were routinely performed. These 2D arrays were stored as DIM S(8,8) and DIM Q(8,8) in the HP-2000F computer which ran its own version of BASIC.

Now fast-forward 40 years.

Star Trek: The Python Game is now in the works. And arrays have been poo-poo'd on over the years, but that doesn't matter. Arrays are a non-issue for Python. Its format may look different is all, as it uses [ ][ ] for its indexing.

Here is some Python code to get started with:

It seems pretty straight forward, as it initializes a ten by ten array with zeros. Then assigns an integer value of 807 to a location in the array. The program refers to the array as "grid". This is the output from the Python code:

And there you have it. The makings of an old-school 2D array using Python.

Wednesday, January 8, 2014

Programming Java for WAV File Playback Using Eclipse in Windows 7

Instead of NetBeans, I'm using Eclipse to do some simple audio wav file playback. The code is written in Java for Windows 7.

Saturday, January 4, 2014

My try at Eclipse+PyDev for Python, Jython, and C/C++ (includes console I/O bugfix)

What's installed:
Windows 7
Eclipse 4.3 (codename Kepler)
PyDev 3.2
Python 2.5.4
Jython 2.5.4rc1
MinGW GCC 4.3.3

8.21 CDT plugin was installed by pointing Eclipse at

Friday, January 3, 2014

Rant: The TAB Key

Sounds like a movie title.

I rant for 27 unedited minutes about the TAB key here (not to be confused with the ANY key). Lots of tangents are thrown in for good measure. Hopefully, someone will make good use of this rather important keystroke.

Thursday, January 2, 2014

Python 2.5 Programming: PyCharm Boot Camp

I de-obfuscate an old dice rolling program written in C by rewriting it in Python, when I already had a pretty good Python dice rolling program written that I could have just made changes to.

Anyway, I'm using PyCharm for the first time here (so be kind, rewind). This video was cut down from its original length of four hours. Thanks to VirtualDub for repairing my long-ass AVI files that my video editors said were either too big or too corrupted (larger than 4GB blah blah).

GitHub has a bit cameo role in this picture. The source code can be found at my GitHub.