March 30, 2010

Mobile SDKs

I met a nice guy who has a web page that presents an award-winning grill he's designed. He briefly mentioned the site that runs entirely on Flash and I offered to upgrade it for HTML, CSS and Javascript. I wanted to learn some CSS3 and MooTools on a real-world problem. The design consists of a menu, a large image and a caption. Images are switched either by timing or by user clicking next/back buttons, complete with fade out and fade in. As it came together I tested it on Firefox, Chrome, Opera, Arora, Safari, Konqueror and IEs 6-8. I decided to try out the popular mobile SDKs as well then. Namely, Nokia Maemo 5, Google Android and Apple iPhone. This is an overview and a quick, superficial evaluation of the mobile developer toolkits.

My aim was not to work on any platform-specific code, but to test out how these devices would display the page and the image transitions. I very much appreciate the ease of installation, good documentation and in general getting to the point very quickly with a minimum amount of hassle. Happy developers make better software. Even better when they needn't to fight with the toolchain. :)

Maemo 5 was the first one I picked since being Debian-based it seems to be the most open platform. I remember briefly using a Nokia N770 in 2006 and apparently Nokia thinks it's a product line worth upgrading by N810 and now N900 released in 2009. Unfortunately even with the backing of Nokia and several years of development, the documentation is not quite as organized as I'd like it to be, with all respect. From the main developer page, it takes five clicks through a Nokia site on another host, back to Maemo wiki, and to the cryptic installation notes that remind me of Gentoo manuals. Choosing those five clicks wasn't quite trivial either.

Thankfully some fellow Maemo developers kindly guided me to a hidden Nokia page hosting a prepared Ubuntu virtual image with the SDK and the rest of the tools. Apparently even hosted at this is an unofficial image. I let the 1.7 GB image to download overnight and launched it in VirtualBox the next morning without a hitch. It brought up the Ubuntu desktop, with no assistance or an emulator icon around. Here be dragons indeed.. Spells and incantations will apparently be needed. Now, somewhere in the middle of the installation spellbook it says "Xephyr" needs to be started:

$ Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -kb &

Mm-hm. This launches up an empty, gray X window. Now, the commands to start the "scratchbox environment" and inside it, the Maemo startup script:

$ setxkbmap fi
$ /scratchbox/login
> export DISPLAY=:2
> start

Success! I still think I shouldn't need to know any of this, but it is running with a fair amount of work. Unfortunately none of the apps were installed and the virtual device seemed quite empty – all there was this Application Manager:

Some extra packages need to be manually installed into the scratchbox environment:

> apt-get install nokia-binaries nokia-apps

Then I had the Maemo browser, which displayed the page correctly. Happiness!

I wonder what Intel does to the SDK now after merging Moblin and Maemo to MeeGo...

Next, testing Google Android. The SDK is a ~20 MB zip file that is a Java GUI which downloads the actual SDK. The size after downloading platforms v1.6 and v2.1 is 343 MB.

Creating an Android virtual device was very easy with the GUI.

And it renders correctly on version 2.1!

Finally, since I work on OS X, I can also try out the iPhone SDK. It required a registration and another overnight download of the whopping 2.8 GB package that comes with bundled Xcode. After downloading, QuickSilver finds the simulator quite nicely and it looks sleek.

I have only a few times used a real iTouch device, but I see the appeal in their design. iPhone with its Safari browser can display my test page correctly.

Overall, considering these mobile SDKs, Apple provides the most elegant solution, Google being in the middle ground and (now-depracated) Maemo the worst experience. While these being developer tools, the user is expected to have some technical knowledge. This is only a very superficial evaluation, just from the perspective of a web developer who wanted to test how his page renders on these platforms. Speaking of the devices, personally I cannot justify their price to their capabilities just yet, but it is nice to evaluate them by their SDKs. Maemo/MeeGo has the Debian sex appeal for the better and the worse. I feel that Nexus One won't be the first really big model even being technologically superior to the iPhone..

March 18, 2010

Python Qt4 soup - quick way to cook up a cross-platform GUI

A friend of mine asked me to do a very quick and dirty throwaway application that parses data off a standard HTML file into an Excel spreadsheet. I chose to do it in Python and spent about an hour to decide which backend libraries to use, and opted for BeautifulSoup and xlwt to do the hard work. The core app – one function to parse input and another function to create the Excel workbook – was written in under two hours. It was only running from the command line – so I cooked him up a GUI:

This friend is a Windows user who dislikes Linux and Mac, and he needs a clean GUI that is dead simple to run and operate. After one sleepless night of furious hacking, he got one. In a Windows exe. Developed on OSX, also running under Linux. This is the power of Python combined with Qt4. The sources are online for those interested to see the details. To emphasize the throwoff nature of the app, all labels are hard-coded to Finnish.

I already had some experience on PyQt4. If you're reading this and decide to look it up, do not pass PySide – it is a newer Python Qt4 bindings library endorsed by Nokia et al. Either one you choose, you can't pass QtDesigner, which is a nice tool to design the UI and comes bundled in the Qt developer packages. In this case all I did was to add a QTableView element with some margin for the tool and status bars.

QtDesigner creates an .ui file (XML) that is translated to Python via pyuic4. With a text editor (XCode) I wrote a subclass of the UI model that extends it with a toolbar with two functions and a status bar for messages. Using file dialogs is easy. The most tricky bit is to make the data from the input file visible in the table view. PyQt4 handles that by a custom subclass of QAbstractTableModel with specific methods the Qt4 API will call to update the table contents.

Quite simple until you get to signals, slots and threading, and it doesn't hurt too much to write and maintain. Overall, about 120 lines of code for the UI, 50 lines for the core.

Now all is left is to test and package it for Windows for my friend to run. I've gotten over my worst fear and loathing of Windows, but I still have a very uneasy feeling every time I boot the OS, even in VirtualBox. Text editor and the console are my friends, and cmd.exe does not quite meet my standards, even on Windows 7. Perhaps I'll look up TCC, but honestly I'd expect a better act on behalf of Microsoft. I had a better time with 4DOS 20 years ago running on MS-DOS 5. Oh, don't even get me started on ""..

    Si si, I'm a terminal snob.

Seems that py2exe is just what I need. It installed fine via easy_install into XP. Their wiki houses the information how to construct the for py2exe to build it. Mainly, name of the main script for the executable and which libraries to bundle. It creates a whole number of files, totalling 26 MB. I was unable to generate a single executable file, but this does the trick.