Saturday, May 31, 2014

Still Keeping to Pygame Despite Great New Kivy O'Reilly Book (for now)

Since I wrote about Kivy six months ago, my son and daughter have continued to make strong progress with Pygame.  For IDEs, they've both moved to PyCharm with its awesome code completion and easy integration with GitHub.  My son is making progress with object oriented programming and recursion.

Kivy is much more powerful than Pygame.  It is also harder to use.  Although the documentation is comprehensive, only the tutorials on Pong and Paint are geared toward beginners.  It also not designed to teach programming concepts to new programmers.  Kivy is geared more toward intermediate to advance programmers that want to get a mobile app up quickly. The new O'Reilly book, Creating Apps in Kivy,  by Dusty Phillips is great.  However, most people new to programming will get stalled around chapter 4.  Although the text is easy to follow and the code examples are clear, the concepts are dense.  Just as an example, in chapter 2 of this thin book, Dusty rips into list comprehensions.  While the example is easy to understand, a new programmer is better off dealing with for loops and list iteration.

There's many other places where Dusty teaches us a valuable concept, but I think it is too much, too soon for young developers.  This said, I've been gearing up for my son''s summer by going through the Kivy book and I plan to introduce him to Kivy later in June.

Kivy makes use of a Python file, which works great in PyCharm, and a kv language file, which does not work great by default.  To get the kv language syntax highlighting and tabs working properly in PyCharm, you need to install the kv settings file.  This makes the development process much easier.  I could never get the kv language settings working properly in Emacs.    After 20 years of using Emacs, I find myself grabbing PyCharm more and more.  It's amazing to me that even at my age, I find myself moving to new tools.  I've even moved off of the Emacs key mappings and am using the default PyCharm keymaps.  JetBrains has done a nice job.

I've also gone through the Packt Publishing book, Kivy: Interactive Applications in Python.  The O'Reilly book is much better, clearer, easier to read, with less errors in grammar.  It's also newer.  The O'Reilly book does focus on Python 3, which I don't think is a good thing since most Kivy development is still done with Python 2.7.  Though, I haven't run into any problems following the Python 3 examples.

Saturday, May 17, 2014

Magic and The 3rd Grade Girl Programmer

Somewhere along our path to adulthood, we stop believing in magic.  What would make us start believing again?

It seems improbable for a 9 year old girl to program.  Yet, I see it.  As she sits in front of a Linux computer slowly typing out code in PyCharm, I think that this tiny 3rd grade girl either represents the future of computer programming or a failed opportunity for everyone.

Adjust the y axis to move the character down the screen with keyboard input, I say.  I do not expect her to succeed.  She does it with the aid of PyCharm's fantastic code completion, happily typing in:

There's a moment of magic.  I imagine every girl in America, daintily typing out our future.  In her face, I see the things that adults would pay a fortune to capture, wonderment, belief, excitement in the aha instant of understanding.  The gears click in her head, she presses the Run button on PyCharm, a Pygame window starts up with a pink girl character in the center of the screen.  Then, the 3rd grade girl coder presses the down arrow key on her Logitech keyboard.  And, the girl on the screen moves down.

  First Hacker in History
She talks about Barbie, My Little Pony, Hello Kitty, and Ada Lovelace, creator of the world's first computer algorithm.  She knows about Ada Lovelace's work on the Babbage Analytical Engine, because girls talk in 3rd grade, letting the boys know that the world's first computer programmer was female.  I hope that their girl power feeling of superiority continues on through high school.

I let her know about the Top Secret Rosies documentary of the heroic women programmers during WW II.  She wasn't surprised.

Leading ENIAC hackers mid to late 1940s

Grace Hopper in 1952 with a UNIVAC 1

More links to great female programmers.

Thursday, May 15, 2014

Windows 8.1 and Pygame Subset for Android (pgs4a)

I recently got asked a question about Windows installation on the PyChildren forum.

Here's the question:

When I touch the icon, the screen turns black, and then it goes back to my apps page in my phone. I then run the logcat to find the problem, but all it gives me is this:

V/python ( 676): Extracting private assets.
I/python ( 676): extracting private.mp3 to /data/data/com.bennybear.fungame/files
The user was not using an mp3 sound file.  When the person extracted the Windows compressed package for pgs4a, the file got added into a sub-directory of the build.    Since I was helping my son to install pgs4a on his Windows 8.1 computer, I was able to replicate the problem.   I think that the process of unzipping or extracting the pgs4a file partially failed.  When I compared the pgs4a files on two different Windows 8.1 computers, I noticed they were different.

I then went to the pgs4a site and downloaded a tar.bz2 archive.  I used tar jxvf on cygwin to extract the files.

A working directory is shown below.

Note that inside of the pgs4a-0.9.6 directory, there is not another sub-directory called pgs4a-0.9.6.  In the failed builds, I noticed that there was a temporary pgs4a-0.9.6 file created in the same directory and all the files from that directory were not properly copied into the main directory.

Once I had the files properly extracted, I noticed that the python installsdk script was giving me error messages.  The script was failing to install android-api-15 and android-api-8.  I used the android.bat program in the android-sdk\tools directory to update the android SDK APIs.  

If you get an error message indicating that ant cannot find the build.xml file, this usually indicates that you don't have the proper Google APIs installed from the Android SDK (not the pgs4a installsdk script).  In almost all cases, I've had to install the Google APIs with the android sdk.  On windows, the android sdk manager is called android.bat

There is another pgs4a tool called  These tools are completely unrelated.

Once I had those installed, the build went fine.  In order to connect the Windows 8.1 laptop to my son's Motorola Moto G Android phone, I had to go to the Motorola site and install the driver.  With driver from Motorola, adb was able to detect the phone and install went smoothly.

I also installed it on my Samsung Galaxy phone from his Windows 8.1 laptop.

This seems like a pain in the rear, but I encourage you to keep going.  Pygame is fun because it makes it easy to bring the creative ideas from your brain into reality very quickly.   By putting these ideas, your works of art, on a phone, you can show your friends and help them to understand a bit more about how you think as a person.

My long term goal for my children is for technology to serve as a tool for creative expression, not a barrier.  It should be fun and frivolous.  Games are great learning tools.  The work and lessons here should not be viewed through the lens of making money or job-training.  These experiments with children are about developing creative thinking and techniques to express ideas.  Sure, it's a pain to get pgs4a to install sometimes.  I agree.  But, I still think it's the best way to get kids and adults up to speed to be able to take their ideas and prototype them on a mobile phone.  

Have fun!

If you have questions or would like to join the discussion, go to the PyChildren Forum.

Sunday, May 4, 2014

Installing Pygame Subset for Android on Windows 8.1

I documented an epic tale of installing pgs4a on Windows 8.1.

Although it took more time than I anticipated, I successfully installed a Pygame application from Windows 8.1 to my Samsung Galaxy Note 2.

 I previously wrote about Shems Eddine tutorial on pgs4a installation and always assumed that the process was easy on Windows.  Wow, now I realize that there are a few hurdles.  Although several people had asked me about pgs4a installation and configuration, I could never replicate these problems on Linux.

I was able to install a rudimentary version of Asteroids that my son and I are working on.  A big part of the lesson is using sine and cosine to rotate the ship in all 360 degrees.

I've also been encouraging him to move to PyCharm.

The screenshot below shows how to start android.bat from within the pgs4a\android-sdk\tools\ directory.

View of the Android-SDK package manager showing the API 17 packages installed.