Monday, February 28, 2011

Gimp programming : First step with Python-fu

Following my very first attempt in Python programming, the result was a command-line script that get value as arguments and display them as text histogram -  but the real idea behind was to get to know the syntax - Now the real challenge is to program Gimp scripts ... and the attempt below is my very first gimp python script (or python-fu).

It's pretty much the same simple idea to have values represented as horizontal histograms on a picture that can be saved...





Source available at http://pastebin.com/c33zgcSP

Wednesday, February 23, 2011

Programming: my first steps with Python

Maybe it's the beginning of a new hobby, but I'm going back to programming - but this time instead of using basic, pascal or C ... I'll have a try with Python.

I installed geany to have a better programming experience, than a bare text editor and the terminal - and the idea was to create a first program to get a touch with the syntax, and the overall logic of Python.

The program should receive a value through the command line, then display an histogram of that value. e.g : if I entered 20 - I should see 2 bars and 8 empty space

Pretty simple, let's begin.

First good surprise in Geany you can generate empty template for Python program
I named mine 'python-histogram1.py' and save it.
The first challenge was to find a way to get 'python-histogram1.py' to read the argument given to him - and using google search, I found that 'for arg in sys.argv' was the way to do it.
then second challenge was to convert 'arg' which is a string of characters into a numeric value - some search got me into using 'int()' but the program had to be sure it wasn't text - so I had to put a test 'arg.isdigit()' if that was true then a will receive the numeric value of arg.

At this point I was pretty happy with Python - no need to declare variables (like pascal or C would require) and since Geany was indenting the program for me - it was a pretty good experience so far.
Now that I had 'a' containing the numeric value - I had to make sure it was in the range of 0..100 - my first test condition - easy 'if a>=0 and a<=100:' no need to had then - the ':' was enough assuming I would indent properly afterward (see the gray zone) below.

Next step was to assign 'g' the integer result of division of 'a' by 10
In the meantime I had to assign str1 - my histogram string in preparation the '<' symbol
and initialize my index i to zero.

Then 2 loops have to be introduced (blue zone) the first one - will assign '[]' (which represents a full block) - then the 2nd loop would assign '__' (which represents empty space) to the histogram's string.

After that I finish the histogram with a '>' to signal his ending and print str1.



Here's the program 'python-histogram1.py' when executed with 6 arguments and the output result.


My conclusion after this little experiment is that Python is really fun to work with and assuming the indentation is respected and there's no infinite loop (got one in my second loop, because I forgot to add "i=i+1" - and I had to kill the process) everything went better than expected.

Friday, February 18, 2011

How to install myPaint 0.9.0 on LinuxMint 8 (Helena)

Lately I've been trying to use LinuxMint "Julia" then LinuxMint Debian Edition (lmde) - but even if both newest releases have great improvement (both in design and features), on my old pc nothing can beat LinuxMint 8 (helena) because the newest version are too resources demanding - that's mainly the reason I'm sticking with the old version.


Now there was something that kept tempting me to upgrade, it's the new release of myPaint 0.9.0 which brings great new features : faster saving, importing a new set of brushes, naming layers, and the "tab" key to hide everything but the drawing - compared to the old version of myPaint (0.8.0 the release available in LinuxMint 8) which looks a bit of a mess.


But updating the whole system just for one application ... well, was probably a bit drastic.

Anyway, with my previous experience in Linux Debian (and from the help of a very knowledgeable former colleague) I knew there was a way to download and compile from the latest source directly.

But the challenge as a non-developer is to understand the jargon and actually try it ... Luckily for me, mypaint has an irc channel and they were really helpful.

The whole process of compiling and running was done in less than 15mn.

  1. Download and extract the source
  2. open the terminal and install missing package by : sudo apt-get install g++ python-dev libglib2.0-dev python-numpy swig scons gettext libpng12-dev
  3. go into the extracted source directory and type : scons && ./mypaint which will build and then launch mypaint 0.9.0 
  4. later I installed the mypaint program in /usr/local/bin - by typing : sudo scons prefix=/usr/local install and after that step I changed the path to all menus to match the new location