Tuesday, January 31, 2006

Showcasing Python: rur-ple on the web?

There has been much discussion on Python related blogs expressing fear about how "Ruby on Rail" might be a "killer app", promoting strong adoption of Ruby over Python, etc. Much also has been said about how the lack of a "single web framework" was hurting Python, etc.

I was intrigued with the idea of a "Try Python" web site that I read about recently. Inspired by an idea originally mentioned by Steve Howell to create Webster van Robot, a web version of Guido van Robot (which itself was the inspiration for rur-ple) I have been wondering about the possibility of creating a version of rur-ple (only Reeborg's world part) that would run in a standard browser, just like one can use "Try Python".

There are two versions of "Try Python": Mike Meyer's, and Devan Lai's. While Devan (a very promising 14 year old programmer, imho) in a post on comp.lang.python wrote that Meyer's is the "cooler" implementation of the two, I personnally think that Devan's is the cooler of the two, and the one with the best potential for showcasing rur-ple as his version can already accept function definitions (and probably more; I just had a very quick look at both).

Now, I know very little about web stuff. One thing I know is that, for "games" type object, it is much better required to have all the code on the client side (through a java applet, a flash file, or some very fancy javascript) rather than on the server side. I also know that there is (for now, anyway) no Python support in standard browsers. How's that for very little? :-)

Now, I think that, if having a version of rur-ple on the web were to be done, it could generate a lot more attention on Python, and on the web framework that would have been used to develop it if using one of those fancy web frameworks is required.

Nonetheless, if one was to really showcase Python using rur-ple on the web, I think the following requirements would have to be satisfied:
  • It should not require the user to install a plugin in his/her browser, just like it is done with the "Try Python" sites;
  • it should not require a special browser, like Grail, either;
  • it should not require some fancy javascript, but only html and css - remember, it is Python we want to showcase; along the same lines, it should not be implemented via a Python applet. Using Jython would be almost like cheating, imho.
Ok, the no-javascript part is perhaps too strong; after all, javascript is probably a "web standard" on the same footing as html and css. Still, it should be kept to a minimum...

Can this be done using one of these famous web frameworks that are generating so many discussions, including the one spurred by Python's bdfl? I personnally have no idea... One thing I know for sure: if it is, I will have to do some major refactoring of my code as the gui stuff is too much intertwined with the logic part; I had no concept of the model-view-controller approach when I started creating rur-ple, and I had no clear reason to try to conform to it (if it ain't broke...) later on. But, given a strong enough incentive, I could always do it!

Monday, January 30, 2006

Rur-ple 0.95 is out

RUR-PLE 0.95 has been released. The "end" is somewhat in sight. A copy of the announcement that I have posted on a few lists is appended at the end of this post.

This new version has required a lot of work, and relatively little to show for, for the casual observer. Other than writing more lessons, there are still a few things that I must implement before release 1.0. There has been a comment made on this blog about eliminating the "Success" dialog. The person who made the comment had a very good point. However, I have read a fair bit about "positive visual reinforcement" as an encouragement to programmers; even experience programmers seem to get motivated by it (think "green lights/red lights" for Java unit testers ... if you're familiar with it). So, I have been thinking about some alternative that don't require the user to actually press a button to resume.

This newest release has what I consider to be a really nifty feature; I call it the Lightning Compiler. This is a cross between a Python editor and a Python interpreter. It is a GUI based app with two main windows. Just enter a script, either by typing it in or importing from a file, in the Editor window, press "run", and you get the result in the output window. It handles input() and raw_input() through dialogs. I like it so much, that I submitted a simplified version to the online Python cookbook. It is available as a separate download (lightning.py) on sourceforge. I now use it as my lightweight basic Python testing environment. I still use SPE for serious coding though. If you haven't tried it yet, I strongly encourage you to do so.

[The lightning compiler is embedded in rur-ple in the fourth tab, and the interface is a bit different from the stand-alone version. It should be more user-friendly looking for a younger audience.]
RUR-PLE 0.95 has been released.

A link to the download page can be found at http://rur-ple.sourceforge.net

(The site is slightly out of date, and there is no plan to update it in the future as it provides an excellent idea of what RUR-PLE is about.)

This new version contains a few bug fixes and it should now work properly on MacOS. wxPython 2.6+ is strongly recommmended. There has been a few minor changes in the robot instructions, and the lessons has undergone some major changes.

RUR-PLE stands for Roberge's Used Robot: a Python Learning Environment.

This learning environment contains four main elements:

1. A simple html browser to look at the documentation and, potentially, the lessons. However, the new lessons use cascading style sheets which cannot be interpreted correctly by the browser. Usage of an external browser (Firefox :-) is strongly recommended.
2. A "robot world" with a robot that can accomplish tasks through Python programs.
3. A built-in interpreter which can be used to play with Python
4. A built-in file editor which can be used for futher Python explorations.

The interface is available in English, French and Spanish. Translations are welcome!

Version 0.95 contains 36 complete lessons (English version only). The lessons are also available as a separate download.

Version 1.0, which will aim to be a "complete" Python tutorial for people that have never programmed before, should have approximately 50 lessons.

A few "bonus" lessons have been included. In particular, it is suggested that you have a look at "A Robotic Fairy Tale".

In 1981, Richard Pattis introduced "Karel the Robot" as a tool to teach computer programming.
Reeborg is a robot built on the 1981 Pattis' model... and it is starting to show its age.
It has an oil leak, which allows us to follow its trail. Its compass is broken; it only knows if it is
facing north or not, unlike Karel who could determine its orientation with respect to all four cardinal points.
Pattis' Karel the Robot was named after the author Karel Capek, who popularized the word robot in his play Rossum's Universal Robots (RUR). While RUR-PLE shares the basic RUR acronym,
in this case it stands for Roberge's Used Robot. However, through the magic of Guido van Rossum's Python, you can learn how to fix it and design a better one, worthy of the name Rossum's Universal Robot.

Sunday, January 29, 2006

First separate release of rur-ple lessons

Finally! After much writing, rewriting, fixing typos, changing format to use style files, fixing more typos, I have a separate package of lessons for rur-ple completed. They can be found here. All in all, there is about 50% more material included than in the last rur-ple release. Now that they are separate from the application, it should be easier to have more frequent releases. It should also be easier for people to have an idea of what rur-ple is about without having to download and install the whole thing (including wxPython).

Next, I will have to do an application release, with various bug fixes...

Saturday, January 28, 2006

Foxit pdf reader: fast!

This post is not about Python, contrary to this blog's purpose - but I just had to write about Foxit pdf reader . It is fast. Incredibly fast compared with Adobe's Reader. When it is set as the system's default browser, it can be used with Firefox (just do Tools -> Options -> Downloads -> Plugins -> disable viewing PDF files with plugin). The only drawback I can see is that it is a Windows only product. You can even type in your own text on a page prior to printing.

Friday, January 27, 2006

Rur-ple: time to drop the browser?

After spending some time writing my python tutorial included with rur-ple in html+css, I have started getting even more annoyed with the simple html browser included with wxPython. I am thinking of dropping it altogether (or perhaps only use it to display some introductory message) and require the use of a standard browser to read the lessons in a separate window. While I have written a simple program that does the html+css -> simple html conversion, it is rather tedious to have to do this, lesson by lesson, every time I update a lesson. Of course, I could change it to process files in batch I suppose, but I'm not sure it's worth the effort.

This would have the added benefits that 1) I could do separate releases for the lessons and the main app, and 2) I could start adding "fancy css tricks" to make the lessons even more visually interesting.

In addition to dropping the browser, I have had to modify the "python editor" window so that programs are not run from it using "exec", as I found out that one cannot make use of "raw_input()" in code that's run by exec or other family members. I have had to embed a second python shell and programs are now run via an import/reload done at the push of a button. I looked briefly at how Idle runs programs, but it was rather convoluted and didn't seem worth the effort to implement. Perhaps someone reading this will have a better idea... [I have not looked yet at the possibility of using popen(), which I have never used, but is apparently used by Makebot; Makebot seems to be doing exactly what I would like to do.].

I'm almost ready for a new release (0.9.5?) of rur-ple, which should now work under MacOS (as well as Windows and Linux). The new release should include about 40 lessons; 10 more lessons or so and it will be finally release 1.0; next will be an introduction to designing games with Pygames!

Reading about browsers, I found out that 20% of users still use screen sizes of 800x600 only. Rur-ple's interface has grown so that it currently needs at least 900x700 for sub-windows to be displayed in a large enough size to be fully useful. One solution might be to reduce the button sizes; however I am afraid that they would become too small at much larger screen sizes. Of course, a way out would be to have multiple image sizes for the buttons, depending on the screen size ... but that somehow seems excessive. I wonder what Joel would think of this.

Thursday, January 19, 2006


Google "Karel Robot", and have a look at the results: web pages about how a Java or C++ version of "Karel the Robot" can be used to teach (parts of) a first year university level in computer science. You'll find explanations on how important programming concepts can be taught using modern paradigms, object-oriented and polymorphism. All serious stuff.

Now, Rur-ple is always described as a fun way to teach programming to children. Nothing serious about that.

Granted, the lessons included so far (save for a few incomplete examples) do not touch "important modern programming concepts, like objects, and polymorphism." And granted that I wrote the lessons so that even children could learn programming by using Rur-ple; I even made some comments about this fact. It is (only) possible to do so because Python is used (instead of C++ or Java).

I guess I will have to wait until I finish writing the first 50 lessons or so before I can have people notice that Rur-ple could perhaps be taken more seriously by older children.

That's my rant for 2006!

Tuesday, January 17, 2006

Rur-ple update

As the few readers of this blog know, my programming work had stalled for a few months. However, I have resumed work on rur-ple over the last few weeks and some good news should come out soon.

I have revised all existing lessons and changed from using hard-coded html information (like font-colors and such) to using cascading style sheets. This will give me more freedom in trying various visual designs for the lessons. However, since rur-ple makes use of wxPython and that its browser uses wxHtml which does not recognize style sheets ... I had to write a converter that would take an xHtml file with the associated .css and convert into plain Html. This work has taken a few (long) nights to complete but it is now essentially done; I can finally resume writing new lessons.

While revising the existing lessons, I wrote my own solutions to all suggested exercises. This lead to some reorganisation of the material, some new minor additions and, more importantly, some deletions of less pedagogical examples.

I have also received some feedback (bugs report!) from a MacOS user. I had to make a few changes to the basic code and it should now be more robust on all platforms. Unfortunately, this also lead me to change the default size on opening to 900x660; I just hope that this relatively large size (greater than 800x600) will not create problems for prospective users.

The lessons are now divided in 5 parts:
  1. Welcome to Reeborg's world. This includes 9 lessons and introduce various robot commands.
  2. Reeborg knows Python. 15 lessons, which include an introduction to the following Python keywords: def, if, else, elif, while, not, pass. Notions of "True" and "False" are also introduced.
  3. Python the interpreter. This will be more akin to a "standard" introduction to Python, although with some side-excursion back into Reeborg's world. I have written a few lessons but they will need some polishing. There should be about 10-15 lessons in total covering numbers, strings, tuples, lists, dicts as well as the following keywords: print, for, in, from, import, return, and the pseudo-keyword "as". Variable assignment is also going to be covered in this part.
  4. Learning about objects. This will include lessons going back and forth between "typical" Python examples and examples in Reeborg's world. I have written four lessons and plan for about a dozen. These lessons have been the most fun to write - hopefully, they will be fun to read as well.
  5. Making games with Pygame. I got sidetracked with learning about Pygame a few months ago. I have some first drafts of 7 lessons which were originally written independently of rur-ple and that I will have to integrate in it. I am planning to have about 20 simple lessons that will eventually lead to some separate lessons on "major projects".
I don't know if I will delay the release of version 1.0 of rur-ple until after these 5 parts (excluding the major Pygame projects) are completed. The next release will probably occur once I have completed the first three parts. Hopefully this will be done within a month. At that time, I should probably release a first version (0.1?) of my "xHtml/css to Html" converter.

Finally, as some users have suggested, I might investigate the possibility of turning the lessons into a book. However, I should probably get some more feedback from users before attempting to do so.

Saturday, January 07, 2006

Note to self: about site customization

This post is probably of no interest to anyone but myself. I just installed Python on a new Windows XP (English), with André as my usual user name and SPE wouldn't work, due to some encoding error. The solution (which I only found in Python in a Nutshell - and only because I vaguely remembered what to look for [other Python books did not cover that topic :-( ] ) was to create a file name sitecustomize in Lib with the following:

import sys

I have to remember this...

Friday, January 06, 2006

117 Outdone by a reader!

Markus Schramm from Germany has left a comment on my post Journey to 117 showing how one could shave yet one more character from the 117 character solution to the PyContest challenge. So, 116 it is!

Wednesday, January 04, 2006

css, wxHtmlWindow and going back to RUR-PLE

About a month ago, my second computer (actually, my main computer as the kids had taken over the better one) died. I had saved the hard-drive and managed tonight to recover the data on it. I found the beginning of a "standard" tutorial (in French) that I had started to write so that my kids could learn Python. That was in August 2004. Shortly afterwards, I discovered Guido van Robot and got inspired to create RUR-PLE. I worked fairly steady on it for a year and then, somehow, haven't been able to find the time to work on it for the past few months.

While I have been quite please with RUR-PLE in general, I have found one thing less than satisfactory: RUR-PLE uses wxPython and wxHtmlWindow to display its tutorial. Unfortunately, wxHtmlWindow does not support style sheets, but only simple html tags. My French tutorial made use of all kinds of css tricks in an attempt to have a pleasant look. I had to gave that up and hard-code font information in the tutorial that has been included with RUR-PLE.

I have found the result with wxHtmlWindow and hard-coded fonts to be somewhat disappointing. So, today I decided that I had to try and implement some work-around so that at least I could use style-sheets to colorize the source code and headings. I have made some limited progress and I hope to have something working soon, so that I can 1. change the existing lessons so that they use some (limited) styles instead of hard-coded font information, and 2. go back to writing some more lessons and get to version 1.0!

Note: I know of the existence of wxMozilla, but haven't been able to get it to work last time I tried. RUR-PLE, which is geared towards beginners (or teachers!) already require three separate installs (Python, wxPython, and itself!). I find this is already a bit much. Besides, if I haven't been able to get wxMozilla to work on my computer, how could I expect a complete beginner to do it?...