What semi-colon?

Python Wrangling - Getting to Know the Beast

Okay, so this month I finally got chance to delve into Python. I’m using version 3.1, as obviously there’s no point learning something thats going to be obsolete fairly soon, although this did make finding examples and stuff harder as the majority of stuff I found was for Python 2.

While I know python is a popular, and very capable, web programming language, I’m not really interested in that side of it. As far as I’m concerned I’ve got PHP which I use for regular development, and am pretty competent with, and Ruby on Rails, which I’m starting to try and get my head round, I neither need nor want yet another contender vying for position as my chosen tool when it comes to developing for the web. What I am very interested in python for, is desktop apps. From what I’ve heard python is a pretty good cross platform language with good tie-ins to the operating system and file structure. It also looks a hell of a lot simpler than C++, which I have tried to master on a few occasions and only ever succeeded in achieving basic competency with.

Now if you’ve seen any of my other posts you’ll know that I tend to do a lot of work with Javascript, and also know Actionscript, so you may be wondering why I don’t just use Air for building desktop apps. I’ve used Air before to build small desktop widgets using Actionscript, and will undoubtedly at some point end up playing around with it a bit more, but for users to run Air apps they’re required to download the Air runtime, and the last time I looked the Linux version was a bit behind. What I’m hoping to get with Python is something I can write once, maybe with some os specific tweaks, and compile to a valid executable/installer for any system.

So onto my first impressions. For someone that is used to languages like PHP, Javascript and Actionscript, Python is something of a shock to the system. The lack of curly braces to enclose functions and statements was something I was starting to come to terms with from Ruby, but the lack of any form of closing statement made reading through the code a somewhat strange experience. My learning project is a file renaming utility so I found the os functions, particularly os.rename() really useful. I started off just building the app as a command line script, then once I’d got that basic renaming functionality figured out, (not really that difficult when it’s just a call to one built in function), I started looking into adding a gui.

I ended up going with PyQT4, mainly because it was the only free, cross browser GUI framework that worked with Python 3. The hardest part about getting it all working was finding out how to actually create the window and use the ui. I’m using the following code:

Where main.ui is my layout xml file. One of the things I liked about PyQT was that it came with a GUI designer utility which lets me just layout the gui as I wanted it and save it to xml. Makes building the layout much easier. At the moment I’ve not really done much more than set up a basic gui with ultra simple file renaming (you select a file, type a new name and hit the big rename button) but I’m intending to add batch renaming with various renaming actions such as regular expressions, substringing, extension changing and more.

The main challenge at the moment is understanding how to use PyQt as I’m afraid the documentation isn’t particularly novice friendly, being more of a reference library. Some examples would be handy, especially as I struggled to find anything on google. I think when I’m a bit more comfortable with things I’ll post some examples/tutorials. I’ll also write a bit more about my python experiences as I get to spend more time with it.

Zebedee - a Multi Framework Accordion Widget

Zebedee is an accordion widget for multiple frameworks. At the moment it is only at V0.1, which only supports zepto.js, but I will be adding support for various different animation frameworks as I have time. I wanted to play around with Zepto, Thomas Fuchs' new mobile javascript framework and decided it would be fun to do an accordion widget to see if I could use the CSS3 transitions to animate the opening and closing of the accordion sections.

It was good fun having to go back to basics on it as I was used to having Prototype and Class.Create() to work with when creating new objects. Thankfully zepto provided a few good utility functions to keep my code neat and simple. The jQuery like chaining also came in handy in that regard.

I’ve purposefully kept the functionality simple, as I don’t really think it needs to be all singing, all dancing! At the moment it supports vertical and horizontal accordions and I will probably be adding the ability to set the the actual trigger event for the accordion to be bound to a child of the header object. Also the duration, transition type and trigger event are all configurable, as well as the class names assigned to the various components.

I should hopefully be adding support for Scriptaculous in the next month or so, and Scripty 2 should follow soon after that, so watch this space. In the meantime checkout the project page at the link below for more information and links to the GitHub source. I’ll also be popping up some demo pages when I get the chance.

Zebedee | Demos

Easel - an AS3 Colour Manipulation Library

Well my post for this month was going to be a tutorial on customising Flash UI components, but unfortunately doing it properly is going to take more time than I have available to me at the moment so I’m just going to keep working on that in the background and will post it when it’s ready.  In the meantime I’m going to put up more information about some of my Open Source projects and hopefully get them better known, which in turns should, I hope, accomplish one of the aims of this blog.  Getting people to help improve my stuff and, by proxy, improving my skills and knowledge.

So first up, purely by virtue of being my most recent, is Easel, a colour (I’m english, so yes it is spelt right!) manipulation library for Actionscript 3.  Easel came about from a need to take a randomly generated colour and get colours that would work well with it for dynamically generated objects in a recent project at work.  At first I just managed to find the Tint library by RevokeLabs which provided me with a darken function which did the trick for me.  However I then needed more, so I managed to find an algorithm to calculate the complementary colour on a forum somewhere, which I’m afraid I can’t remember, but have subsequently replaced so I don’t feel too bad about not crediting it.  From there I had the idea of replicating the colour manipulation functions of Sass, which I’d read about in a recent .Net tutorial, but hadn’t had a chance to play around with (I have now and will no doubt be writing more about this down the line, watch this space!).

I was struggling to find the algorithms to accomplish what I needed in AS3 so I ended up pulling the source for Sass from GitHub and wading through that to find what I needed.  I then proceeded to rewrite the functions to AS3 which involved rewriting the original manipulation functions from the Tint library as they relied on manipulating the RGB values whereas Sass was working with the HSL.  I did however keep the getHex and getRGB functions as there seemed to be no real difference in them.  The upside to this approach was that I learnt a bit about colour manipulations, and got more experience with Ruby code, always a good thing!

Please check out the link below or on the right for the project page which contains links to the GitHub source and the Demo.


New Year’s Resolutions

Ok, so one of my goals for this year is to really start getting involved more in the coding community.  That is the whole intention of this blog, to try and share my learning experiences and provide a home for the various projects I’m working on in my own time in the hope that other people will find them useful.  There is also the hope that more knowledgeable and more skilled folk than myself might catch wind and offer advice and help to myself.

In actual fact this goal was something I set myself towards the end of last year, which is when I first started setting up this blog, but I never seemed to find time to actually kick it off.  I guess that’s what New Year’s resolutions are all about, making you take that step.  So here goes, the blog is now officially live, and you are now, hopefully, reading the inaugural post.

I’m going to try and post as often as possible on here, probably monthly at the moment until I find enough to write about more often.  I’ll also be gradually adding pages and links for my various open source playground projects, so I’ll undoubtedly be posting to launch them and keep you all updated on their progress.

Here’s to 2011