Archive for January, 2006

January 31, 2006: 12:45 am: kpdPython

This is an inital cut of a Flite (Festival Light) python wrapper. It will speak arbritary text passed to it. Some strings cause the library to lock up. I am not sure why. Enjoy!

Download pyFlite

January 30, 2006: 9:56 pm: kpdprogramming

As a kid, my older brother and I would head up to the local arcade and play Atari’s primitive tank combat game. This was a long time before Doom, a time when simple gray-scaled graphics sufficed.

I spent a long time creating a clone of Tank when I received my first computer, the TI-99/4A. It was one of my first real programs. Very blocky, very slow, and a whole lot of fun. One option was that your could shoot trees and receive a point for each shot if you killed the other tank. The idea was that while one player was busy shooting trees, the other might sneak up behind for the kill.

I recreated Tank as Super Tank over Christmas break one year in college. This was a good excuse to practice my nascent C language skills. BBS’s and the Net were around and the game made it to a few archives.

Not having thought much about the game over the last few years, I was happily surprised to stumble on it last week at a site called Abandonware. They even gave it a decent review! Seeing the screenshots brings back some great memories.

It would be great fun to port it to PyGame some day.

January 28, 2006: 6:46 pm: kpdrowing

Robert Walton, a local referee, is offering a free clinic at the Cleveland Rowing Foundation boathouse on Monday, February 27, from 7 to 8 pm. ‘Introduction to Officiating, or “What are the People in the Blue Shirts Doing?”‘ will include:

  • Some basic rules
  • Typical regatta procedure
  • Role of the rowing referee
  • Becoming licensed as a referee
  • Things to read

This is a great opportunity to learn about the rules of rowing and understand a little better what is happening on regatta day.

January 24, 2006: 1:18 am: kpdrowing

My rowers and coxswains pulled their second 2K Erg tests of the year today. It’s always energizing watching them come together for these pieces. You can’t help catch the energy they generate as they row and cheer each other. I was able to stop up a little early and talk to them about pain management in the context of a 2000 meter erg piece. We discussed:

Pain vs. ‘the feelings of working hard’: Pain is a protection mechanism that minimizes bodily harm, erging pain is a sign that you are working hard, growing, pushing limits, etc. It is unfortunate that our language does not distinguish between the two sensations, but it does not so all feelings are lumped as ‘pain.’

Tolerance: Some people tolerate ‘pain’ better than others. Why? They attribute the pain to different things ( I am working hard vs. I am out shape), confidence – having blasted through it in the past makes it easier to do so again, and desire – if you don’t want to challenge yourself this way then you should rethink your decision to row on a competitive crew team.

Techniques to actively deal with the pain of a 2000 meter row:

  1. Attention Diversion:
    1. on short pieces and on the water divert your attention to something rowing related such as breathing, form, or timing
  2. Countering (followed by self instructions)
    1. such as when that voice tells you ‘it hurts, you should ease up’, count er with ‘yes, so what? that doesn’t mean I have to ease up, stay on it!’
  3. Forced Breathing:
    1. 3-4 deep, rapid breaths, attempting to expel all air on the exhale

Those reading this that are not rowers may not understand why mostly sane people would put themselves through something like this. An excerpt from one of my former rowers says it best. She has just described the feeling of the first time she broke 8 minutes on the 2K erg test:

I still wonder how I stuck through that first winter, having rowed only four times the past fall and knowing nothing of the spring sprint season, that heavenly light at the end of the tunnel. Whenever I find myself in need of extra motivation to push me into the lion’s den, to lead me like a lamb to the slaughter of the erg, I remember that 2K, the approval of my role models, captains and coaches at my achievement and the unrestricted pride and confidence I had in my own ability. I remember what that room has taught me- to push myself to the farthest limit and with one more stroke to break it, to sacrifice a moment’s happiness, comfort and oxygen for later reward, and that I am mentally and physically stronger than I ever thought possible. I now know I can enter hell and emerge triumphant, and even have fun along the way. I know I will enter the erg room with reluctance and face the erg with apprehension, but I know I can and will prevail, for the erg room is not really hell, and it is not the enemy, but the best means to a noble and excellent end.

So, how do you manage the pain of a 2000 meter erg piece? I’d love to hear your answer in the comments.

January 23, 2006: 5:14 pm: kpdPython

Years ago I spent quite a bit of time learning and using SWIG, mostly in the creation of the pyFLTK Fast Light Toolkit wrappers for python. Swig was, and still is an impressive piece of work – Dave Beazely and the other guilty parties have done a lot to make scripting languages more useful. Pyrex is getting a lot of attention lately. People seem to love it, so I gave it a try. I have a python extension that wraps some C++ classes for the Concept II Rowing Machine. The early implementation was in SWIG. I reimplemented the extension using Pyrex. Some thoughts on the results:

  • SWIG’s ability to use the .h files cuts down on busy work
  • One set of SWIG source files can generate wrappers for multiple languages ( with minor tweaks for each language)
  • the SWIG build process is more complicated – more libraries, dependencies, etc
  • Python helper code must reside outside of the SWIG extension library, so there is more work in creating a ‘package’ that uses the generated python shadow classes
  • SWIG can automatically generate python shadow classes
  • PYREX file contains a mixture of C declarations and arbitrary python code
  • PYREX generates one .pyd file that contains both the bridge code to C and the python code – I like this simplicity
  • PYREX extension builds quicker than the SWIG extensions
  • PYREX support for C++ is through a patch supplied by a third party. It works fine for the simple C++ classes I am using
  • SWIG C++ is more mature

I wasn’t able to compare sizes of the resulting extensions as I now have different functionality in each version. The Pyrex code being in a single file does make things simpler to manage.

Since it is working well and I have no need to support other scripting languages, the extension will remain in Pyrex. This is not a slam on SWIG and I’m sure in other projects SWIG will be used again.

January 19, 2006: 12:08 am: kpdPython, wxPython

I was having some trouble getting a window to resize when the contained controls were shown or hidden. After some searching and experimentation, I found this sequence to work:


   def OnInit( self ):
        self.res   = wxXmlResource( GUI_FILENAME )
        self.frame = self.res.LoadFrame( None, GUI_MAINFRAME_NAME )
        self.frame.Show(1)
        self.showControls = XRCCTRL(self.frame, 'showControls')
        self.controlPanel = XRCCTRL(self.frame, 'controlPanel')
        self.Bind( EVT_TOGGLEBUTTON, self.OnChange, self.showControls)
        return 1

    def OnChange(self, event):
        sizer = self.frame.GetSizer()
        sizer.Show( self.controlPanel, show=self.showControls.GetValue(), recursive=true)
        size=sizer.GetMinSize()
        self.frame.SetMinSize(size)
        self.frame.Fit()

where gui.xrc is:


<?xml version="1.0" encoding="cp1252"?>
<resource>
  <object class="wxFrame" name="FRAME1">
    <title>Test</title>
    <centered>1</centered>
    <object class="wxBoxSizer">
      <orient>wxVERTICAL</orient>
      <object class="sizeritem">
        <object class="wxToggleButton" name="showControls">
          <label>Show Controls</label>
          <checked>1</checked>
        </object>
      </object>
      <object class="sizeritem">
        <object class="wxPanel" name="controlPanel">
          <object class="wxBoxSizer">
            <orient>wxHORIZONTAL</orient>
            <object class="sizeritem">
              <object class="wxStaticText" name="theLabel">
                <label>Label:</label>
              </object>
            </object>
            <object class="sizeritem">
              <object class="wxTextCtrl" name="theTextControl"/>
              <option>1</option>
            </object>
          </object>
        </object>
      </object>
    </object>
  </object>
</resource>

2/1 Update – had wrong app code in place

January 11, 2006: 11:35 am: kpdPython

Monday I attended my first Cleveland Area Python Interest Group meeting. There were about 12 people present, although there are about 40 people on the CLEPY google group. Ian Maurer gave a great introduction to jython. I’ve used it to create some custom Ant tasks for Java in the past, so much of it was a good review. The jylluminate module is something new that looks interesting. It provides the introspection capabilities we’re used to in cpython. Jaison Lee gave a presentation on the SCONS build tool. The tool’s strength appears to be it’s hiding of nuances between different target platforms to the build-script maintainer. Think of it as a replacement for make that uses python scripts instead of makefiles. Looking forward to the next meeting.