These are my open source and hobby projects.  I hope you find one of these interesting and useful for your own projects.  The menu on the left allows you to jump directly to a project of interest.

WiiuseCpp and PyWii

posted Oct 7, 2012, 10:04 AM by James Thomas

Wiiusecpp is a C++ wrapper library for the wiiuse Nintendo Wiimote library. Pywii is a python swig wrapper of the wiiusecpp library and can be found as part of that library distribution. Download the library at the bottom of this page.

For those not familiar, offers the following brief description for the wiiuse library:

  • Wiiuse is a library written in C that connects with several Nintendo Wii remotes. Supports motion sensing, IR tracking, nunchuk, classic controller, and the Guitar Hero 3 controller. Single threaded and nonblocking makes a light weight and clean API.
  • Licensed under GNU GPLv3 and GNU LGPLv3 (non-commercial).

This project heavily depends on wiiuse and so I offer the library with the same license options. Users of either wiiusecpp or pywii will need to download and install the wiiuse library prior to building this library.

This library has been in the wild for quite some time and I've not heard of any bugs. So for now I'm calling this stable.

My true motivation for this library is the python wiimote driver. When I started there are a few attempts at a Python wiimote library on the internet but I did not find any that were as full featured as the wiiuse library. There is a ctypes based python wrapper of wiiuse discussed here but it did not work for me and it would not have been very ‘pythonic’ since it really just gave access to the functions and structures of wiiuse. I hope I have succeeded at a functional and clean implementation with this library.

Unfortunately for now the documentation is going to be limited to reading the code of the library and examples. Most of the code is is not very complicated so it should be pretty straightforward to see how to use the libraries. The library code can be found in the source directory (wiiusecpp.h and wiiusecpp.cpp). Python users be sure to look in pywii/pywii.i for some extra python code I’ve thrown in to extend the C++ libraries. I have C++ and Python implementations roughly equivalent to the wiiuse-example program (example/example.cpp, pywii/ and I tried to follow the same overall program layout so you can compare the three to see how things work. There is an extra python example (pywii/ which uses wiimotes with or without the nunchuk expansion to play notes. Use the wiimotes like drumsticks to play notes and rotate them in your hand (or swing sideways) to set the pitch. If you are using the nunchuk attachment the angle you are holding it at determines the pitch. It is very crude but it shows off an application class in the library which I think is a good way to make a wiimote program.

Presently wiiuse is available for Linux and Windows. I have done all my development on Ubuntu Linux so I have not tested compilation on Windows. I don’t expect any code to be affected to make it compile on windows but the make system is Linux oriented. If anybody on Windows is so inclined to generate them I’ll add project files for VC++ to the distribution. At one point in time when I still developed on windows I had a VC++ project file that automatically generated python swig wrappers so it is possible to automate the process. Email me if you are interested in getting that working and I’ll see if I can dig up some links on how to do it. Update: It looks like the University of Rochester has a course on programming with the wiimote. They have some instructions and Visual Studio makefiles for both wiiuse and wiiusecpp here.


posted Oct 7, 2012, 10:01 AM by James Thomas

PySheet Screenshot
PySheet is a simple Python based spreadsheet with integrated interpreter shell. The language for the formulas is Python. This program requires Python 2.6, a recent version of the wxPython library, and my EzWX library to run correctly. EzWX is my attempt at making wxPython a little easier to use to make a fully-functional GUI application. At the very least I'm sure that it will provide an example on how to implement certain GUI features using wxPython. Believe me, it took a lot of scouring the web and trial and error to figure it all out. To keep you from having to do a separate download I'm including in this distribution. Download PySheet at the bottom of this page.

Edit: I've finally gotten around to getting a working Windows setup and noticed that there are a few glitches in the UI. I'll see if I can figure out how to make the Windows version work the same as Linux. In the meantime, when you first start the program in windows just resize it a bit and the grid will redraw correctly. The other thing I noticed right away is that the enter key behaves differently when editing a cell. No it is not supposed to pop you down to the interpreter -- go figure.

Formulas and values can be manipulated from the spreadsheet cells or from the interpreter command line. The formula syntax requires the use of an equals sign similar to a regular spreadsheet. A formula can be entered in the interpreter window as follows:

>>> a3 = '=a1+a2'

Alternatively the formula can be entered directly into cell a3 without the quotes:

Cell dependencies are handled automatically using Tarjan's algorithm. In the case of a circular dependency a simple iterative method is used to find a solution assuming that it converges within 100 iterations.

Helper functions are defined in and are imported automatically when the program starts up. Range() can be used with functions that require an iterable as follows:
>>> a11 = '= sum(Range(a1,a10))' note this is equivalent:
>>> a11 = '= sum(Range("a1", "a10"))'

I have made cell variables know their own name so you don't have to always quote cell addresses. This also makes pySheet work more like you would expect for a spreadsheet program.

I have included a handy trick so you don't have to use the range function if you don't want to. The spreadsheet has a 'shortcut' name of ss. So instead of the Range() function you could use the following:
>>> sum(ss[a1:a10])
>>> a11 = '=sum(ss[a1:a10])'

This also works in the cells. Using ss was the closest I could come to having spreadsheet-like range functionality.

There is a helper function called Fill() which can be used to fill cell values while incrementing (left to right, top to bottom):
>>> Fill(a1,f10) # Can optionally provide a start and increment

Copy, paste, clear, and delete should work the way you would expect. Formula addresses are relative-translated when you do a copy etc. To create an absolute address use a trailing underscore after the column letter or the row number:
>>> a11 = '=a_1_ + b_1 + c1_'

I have attempted to provide multi-level undo/redo however it does not handle the commands you type at the command line at this time. I have attempted to verify that it works correctly in many scenarios including inserts, deletes, cuts, pastes, etc.

The file format despite the extension of .sht is actually just Python code like what you would type on the interpreter command line to populate cells. In fact a load is really just running exec on the file. Each non-empty cell is written out as a single Python statement.

Another of the quirks of me trying to keep this true to Python and avoiding the temptation to redefine the formula language is cell name case. You can use either upper or lower case but I had to pick one for Python to use in the 'locals' dictionary so I chose lower case. While it is completely transparent when working on the grid (everything is is just converted to lower), when you are working in the interpreter sometimes it works the way you expect, sometimes it doesn't. So use lower case all the time and your life will be easier.

Presently all of the math library is imported by default, perhaps others should be too. The import command and many others are disabled in the interpreter so any additional library imports would have to be included in when the instance of the Spreadsheet class is created (see the very bottom of the file). My intention is to eventually handle the selection of library imports via the GUI.

Note, this is really intended as an example/demo in the hopes that the techniques and code will be useful to people writing their own programs more than using this as an application. I'm working on a multi-sheet more capable version with plots and a few other neat things but I figured that this may be helpful for some people for the time being.

This was possible in large part due to the efforts of others who were generous enough to share with the world their ideas and software:


posted Oct 7, 2012, 9:35 AM by James Thomas   [ updated Oct 7, 2012, 9:42 AM ]

VisualPyODE 6-DOF Platform Demo
VisualPyODE is a framework library to aid in using 
PyODE and Visual Python together. When you create objects they have both physical and visual properties. Supports collision, assemblies, and comes with some helpful enhanced joints to simplify creating your visualized simulation. I have implemented the PyODE tutorial demo programs using the library so you can see exactly how it compares. There is also an extra demo of a 6DOF (six degree of freedom) platform that I put together to show how the piston assembly is used. Download the library at the bottom of this page. Dual licensed under LGPL or BSD for your programming pleasure.

Right now the libraries of enhanced joints and assemblies are pretty thin but hopefully they will grow over time. One of the primary reasons why I chose to work with VisualPython is it's simplicity combined with the ability to have mouse interaction with 3D objects. The combination of physics and 3D interaction is powerful and has many exciting applications. I have used it to allow the user to push and reshape objects connected by ode joints behaving like springs. I expect to be expanding on the enhanced joints in odelib and the pre-built assemblies in vpyode.lib over time. Presently there are enhanced hinge and slider joints with springs and friction, and a piston assembly.

Please be sure to read the code found in library (odelib/, vpyode/, vpyode/ as well as the demos to see how everything works. I developed and tested this on Ubuntu Linux using pyode and visual from the repositories but it should also work on Windows and OS/X assuming that you can get PyODE and VisualPython working on them -- AFAIK nothing VisualPyODE is platform specific.

I have a couple of new versions of the library that I have not yet released.  Visual Python is very fast but I have had numerous problems with it breaking on my systems, I have not found a good way to integrated into a UI like wxPython, and it does not allow subclassing or extending it from Python.  I created a clone of Visual Python using PyOpenGL, unfortunately it is very slow for large numbers of objects.  I also created a clone of Visual Python using Panda3D and it is faster than PyOpenGL for large numbers of objects but still much slower than Visual Python.  The Panda3D version seems to hold promise since the Panda folks are working on multi-threading the graphics pipeline and they have support for the Bullet physics library which may improve at a faster rate than ODE.  If any of this is very interesting to you send me an email and maybe we can work on it together.

FP in Python

posted Oct 7, 2012, 9:31 AM by James Thomas

Functional programming extensions for a Python shell.

For lack of a better term I'm calling this code objects. You can download the zip file at the bottom of this page. This should run on any OS with Python installed. One could argue that this is a form of functional programming not to dissimilar from a spreadsheet. This program is an offshoot of my Python based spreadsheet project. I realized that a Python shell which allowed formulas to behave like spreadsheet cells could be useful for those people who like to use Python interactively as a smart calculator. Here is an example of how it can be used:

$ python
Python Shell with code objects
>>> area = '= length * width'
Calculation of (area = length * width) had errors.
{'area': None}
>>> length = 4
Calculation of (area = length * width) had errors.
{'length': 4, 'area': None}
>>> width = 6
{'width': 6, 'area': 24}
>>> area
>>> width = '= a + b'
Calculation of (width = a + b) had errors.
Calculation of (area = length * width) had errors.
{'width': None, 'area': None}
>>> a = 2
Calculation of (width = a + b) had errors.
Calculation of (area = length * width) had errors.
{'a': 2, 'width': None, 'area': None}
>>> b = 10
{'width': 12, 'b': 10, 'area': 48}
>>> b = 5
{'width': 7, 'b': 5, 'area': 28}
>>> area

So any string assignment to a single variable will be tested to see if it begins with an equals sign. If it does then it will be converted into a CodeObject. Tarjan's algorithm is used to determine the correct calculation order. As a matter of convenience I have added print statements to display when calculations have errors and the results of variables which have been changed as a result of the new assignment. Other than the re-interpretation
of strings which start with an equals sign the interpreter should act as you would expect.

Obviously unlike a spreadsheet the names for your variables do not need to follow a cell address convention of letter for the column and number for the row. When using the interactive interpreter it does not matter too much. Of course this somewhat limits what sort of fancy operations you can do on ranges of variables and such. The simple spreadsheet program PySheet marries the shell with a grid for the best of both worlds.

I am also including a second file which contains a slightly modified version of the wxPython pyshell application. If you have wxPython installed you might like to use this instead of the text console. This file is included as an example and is not subject to the licensing of this distribution but rather is subject to the licensing of the wxPython project.

This was originally inspired by this ActiveState Recipe and Roberto Alsina's Blog on the subject. Without these preceding efforts I never would have attempted it.

Distributed under the GPL.

1-4 of 4