Sounds like a great idea. That will be $10,000 (about the bare minimum to file a patent and prosecute it through issuance).
Something that is much easier and much cheaper for open source projects/idea to do is to submit a Defensive Publication, I talked with Tom Tyson of the Open Invention Network (http://www.openinventionnetwork.com/) a while ago and he explained the beauty of Defensive Publications. Basically the patent offices scour defensive publications prior to issuing a patent and if they find anything then the patent gets rejected. Therefore making it unable to patent by anyone else. These are easy to write up and their lawyers review them and submit them. I will be submitting many of my idea this way so nobody can claim patents on them, it is free. The website is http://www.defensivepublications.org/
I've noticed several design suggestions in your code.