May 28 2008

Sweet Home 3D for a beautiful home

Want to design the interiors of your new Home in Gnu/Linux ? or you just need to modify the interiors of your’ home ? … You can do it all using the nice program called Sweet Home 3D.  It is available from http://sweethome3d.sourceforge.net/index.html.

Just download the software from http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-1.3-linux-x86.tgz. As it is a java based Software, make sure that you have openjdk installed in your machine.  In the latest Ubuntu Hardy Heron release,  the execution of Sweet Home 3D was flawless.

Have a look at my experiements with SweetHome 3D :)

It’s really cool.. You can make wonders with some sense of beauty and a mind willing to spend hours with this software.


May 26 2008

GCompris for Unnikkuttan

Last Friday, my Uncle called me up for a particular requirement – to buy one PC for Unnikkuttan and Ponnu, my cousins.  He wanted his children to use that Computer for education purposes. I agreed to go with him and help him in choosing the PC configuration.

After some comparison by visiting multiple stores, we have decided to buy the Acer Aspire PC, which costs about 23000 (nowadays, I feel laptops are better than Desktops when we think about our wallet). It had a 1.6 Ghz, 1 MB L2 cache, 800 MHz FSB , Intel pentium dual core processor , 1 gb ram, Intel 945 GC motherboard, DVD writer….

Well, the dealers has installed some games on the PC and just after booting the PC in Windows XP , Unnikkuttan started playing the games, mostly nothing to with education and more to do with the violence. Jose Uncle wasn’t that happy with what unnikkuttan doing with the PC.

Next week, I have visited Unnikkuttan’s home , this time with 3DVDs of Debian Etch Gnu/Linux. I have installed the Debian on the 40 GB partition of that massive 160 GB HDD. Installed the Debian Gnu/Linux. Both Unnikkuttan and Ponnu were amused by the installation steps of Debian.  The whole installation took around 30 minutes (thanks to that high speed processor with 1 GB ram ).

After that it was the time for Education softwares. I have installed GCompris and Kdeedu and asked Unni and Ponnu to use it. They really liked those programs, I could guess it from their fight for playing the games. Again not willing to hurt Unnikkuttan’s desire for Racing, I have installed the Torcs race game for him. He got thrilled by that game anyway..

The PC boots directly into Debian and I have configured the Debian to have a “passwordless” entry to the Desktop to reduce the “password” problem for children. I know they are smart enough to remember the passwords. But unfortunately I dont’ remember my passwords these days. So I have decided to not to take a chance for myself :)

Nowadays Unnikkuttan and ponnu are proud owners of a Debian Linux ( I have removed the GNU to for ease of the kids) machine. They are the future, let them play with the Gnu/Linux Innocent  

( I wonder why people are saying Linux is hard to use while children like Unnikkuttan and ponnu , with ages 4 and 6 respectively are using it without any problem)


May 22 2008

Play with Cheetah : the python based templating engine

Cheetah is a python powered  Templating engine and code generation tool (Though I never tried it’s code generation functionality). Its main application is in the Web Development scenario itself.

To start with Cheetah, we can download the latest release of cheetah from http://sourceforge.net/project/showfiles.php?group_id=28961.
Installation is done by the usual
python setup.py install

After this we are going to test the prime functionality of Cheetah, the Web Development scenario.

The simplest template (Greeting.tmpl)
###################################
Hello, $firstName.

Your order (#$order) has shipped:
###################################                                  

Compile it using Cheetah

cheetah compile Greeting.tmpl
Compiling Greeting.tmpl -> Greeting.py

Now we got a Greeting.py. So let’s  test that in python

>>> from Greeting import *
>>> t = Greeting()
>>> t.firstName= ‘Maxin’
>>> t.order = 23342
>>> print t
Hello, Maxin.

Your order (#23342) has shipped:

Hmm.. It works..
Best reference for cheetah is available at http://www.cheetahtemplate.org/docs/users_guide_html


May 20 2008

System Tray application for Linux using Python and GTK

Creating an application which resides in the System tray adds charms to an otherwise simple application. Pleople tend to value accessibility and userfriendliness  than the quality of the program itself (pardon my friends, I am sure that you are not one of those chaps)

But, again it is fun to create a simple gui which demonstrates how to create an active System tray application using pygtk. My simple app goes like this.

#######################################################################################

#!/usr/bin/env python

import gtk

class StatusIcc:

    # activate callback
    def activate( self, widget, data=None):
    dialog = gtk.MessageDialog(
        parent         = None,
        flags          = gtk.DIALOG_DESTROY_WITH_PARENT,
        type           = gtk.MESSAGE_INFO,
        buttons        = gtk.BUTTONS_YES_NO,
        message_format = “Did you like this Activation example \n by Maxin B. John <maxinbjohn@gmail.com>?”)
    dialog.set_title(‘Popup example’)
        dialog.connect(‘response’, self.show_hide)
    dialog.show()
   
   # Show_Hide callback
    def  show_hide(self, widget,response_id, data= None):
           if response_id == gtk.RESPONSE_YES:
               widget.hide()
    else:
        widget.hide()
           

    # destroyer callback
    def  destroyer(self, widget,response_id, data= None):
        if response_id == gtk.RESPONSE_OK:
            gtk.main_quit()
    else:
        widget.hide()

    # popup callback
    def popup(self, button, widget, data=None):
        dialog = gtk.MessageDialog(
        parent         = None,
        flags          = gtk.DIALOG_DESTROY_WITH_PARENT,
        type           = gtk.MESSAGE_INFO,
        buttons        = gtk.BUTTONS_OK_CANCEL,
        message_format = “Do you want to close this Status Icon program?”)
    dialog.set_title(‘Popup Window’)
        dialog.connect(‘response’, self.destroyer)
    dialog.show()
     
       

    def __init__(self):
        # create a new Status Icon
        self.staticon = gtk.StatusIcon()
        self.staticon.set_from_stock(gtk.STOCK_ABOUT)
        self.staticon.set_blinking(True)
    self.staticon.connect(“activate”, self.activate)
        self.staticon.connect(“popup_menu”, self.popup)
        self.staticon.set_visible(True)

        # invoking the main()
        gtk.main()

if __name__ == “__main__”:
    statusicon = StatusIcc()
####################################################################################

Hmm , The code is pretty simple . It is using gtk.StatusIcon() for the System Tray app. The most important signal for the StatusIcon are “activate” and “poup_menu”. The callbacks for those singals are also self explanatory. So not much comments on the code. Now lets see my
app in action.

The Information (i) symbol in the system tray area is the running application. Right click and Left clicks will generate the “poup_menu” and “activate” signals respectively. 
Try the tray app for you next programming adventure :)


May 16 2008

Twitter through python

Twitter is a free social networking and micro blogging service that allows users to send “updates”  up to 140 characters long to the Twitter website, via SMS or instant messaging (google chat).
Updates are displayed on the user’s profile page and instantly delivered to other users who have signed up to receive them. The sender can restrict delivery to those in his or her circle of friends (delivery to everyone is the default). Users can receive updates via the Twitter website, instant messaging,SMS, RSS, email or through an application.

Now let’s have a look at python and integrate the Twitter with Python. Python-twitter module is a python wrapper around Twitter API which is available at http://code.google.com/p/python-twitter/. The twitter module depends on simplejson module which is available from http://pypi.python.org/packages/source/s/simplejson/simplejson-1.9.1.tar.gz. As it is a pure python implementation, installation is very easy and traditional.

Then download the python-twitter module from http://python-twitter.googlecode.com/files/python-twitter-0.5.tar.gz .
tar zxvf python-twitter-0.5.tar.gz
cd python-twitter
python setup.py build
python setup.py install
and we are done :)

Now let’s write the simplest python script to post a message in twitter.

###############################################################
# The simplest python program to play with twitter using python-twitter
#  Google Code:   http://code.google.com/p/python-twitter/
#  Google Groups: http://groups.google.com/group/python-twitter
#  Python twitter API can be used to send and receive twitter messages
#
# Thanks to DeWitt Clinton <dewitt@google.com> for this wonderful module
#

import twitter

api = twitter.Api(username=”my_twitter_username”, password=”my_secret_password”, input_encoding=None)
status = api.PostUpdate(“example of the simplest twitter message program “)
print status.text

###########################################################

It is very simple. Now let’s run the code as
python simple_twitter.py
example of the simplest twitter message program

Now when I visit my twitter home (http://twitter.com/maxinbjohn), I can see that message and I think it is cool Cool


May 14 2008

QuickCam Go on Ubuntu 8.04 LTS Linux

One of my worst fears were whether my newly owned Webcam (Logitech QuickCam Go) will work in Ubuntu Linux or not. Though it was cheap(Rs. 730/- or roughly 19 USD) , I didn’t wanted to experiment with it in M$ OS. But my fears were baseless. It worked smoothly in Ubuntu, didn’t even have to wait for installing the drivers in the Ubuntu 8.04 LTS distro.

Hmm.. it saved a considerable amount of time for me.
uname -a
Linux maxin-desktop 2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 UTC 2008 i686 GNU/Linux
At first I have tested it in the Ekiga Phone Software. Later decided to do something interesting with that. So I have installed ‘motion’ in Ubuntu Linux

sudo apt-get install motion

About Motion: ” motion uses a video4linux device for detecting movement. It makes snapshots of the movement which can be converted to MPEG movies in realtime (or later for low cpu usage), making it usable as an observation or security system”

Output of motion in Ubuntu Linux using my Logitech Quickcam Go webcam



It runs a webserver on port 8081 in my machine. I will be able to monitor whether somebody is present in front of my pc (or if the ‘motion’ is installed in my home pc, I can check whether somebody is intruding my home or not) using an ordinary web browser.


May 8 2008

The simplest (python based) pre-commit hook in Subversion

Hooks in Subversion are scripts or executables that are triggered by an event in the subversion version control life cycle. The following are the hooks supported by Subversion.

In the hooks directory of a repository we can find these template files:
post-commit.tmpl      pre-unlock.tmpl
post-lock.tmpl          pre-commit.tmpl
start-commit.tmpl     post-revprop-change.tmpl
pre-lock.tmpl          post-unlock.tmpl     pre-revprop-change.tmpl

start-commit
Before the commit transaction starts
pre-commit After the commit transaction starts but before the transaction is commited
post-commit After the commit transaction completes
pre-revprop-change Before a revision property is changed Repository Path,
post-revprop-change: After a revision property is changed Repository Path
pre-lock:  Before the lock being acquired
post-lock:  
After the lock being acquired

To test how a hook works, let’s create a repository in our Gnu/Linux Box.

svnadmin create hello

Now we have a repository called hello and it will contain files like
conf dav db format hooks joke.py locks pre-commit README.txt
Modify the conf/svnserve.conf to include passwd file and add users to the passwd file along with their passwords.

Then run the server as svnserve -d -r hello
To checkout :
svn co svn://127.0.0.1

Then lets move to the real work. We need to stop anybody who is trying to commit to our repository just because we are doing some important work on the server or we just dont want anybody to help us :)

To do that, let’s create a file called pre-commit in hooks folder in the repository (hello). The content of the pre-commit should be :

#!/usr/bin/env python
# ====================================================================
# The simplest pre-commit hook which prevents all the commits to the repository
# This can be useful(?) when you are doing the backup of your subversion repo.
# This small script will prevent the commit and will give a simple message
# to the person who is commiting the changes.
#
# USAGE:
# copy this script as pre-commit in the hooks directory of the svn server
#
# ====================================================================

import sys

MESSAGE=”"”
Dear Sir,

As we are doing some important work in the server,all those who are submitting
the changes will have to wait for some time.

Sorry for the inconvenience caused.

Regards,

Administrator.
“”"
# Messages written to the stderr will be shown to the person who is commiting.
sys.stderr.write(MESSAGE)

# Need to exit with anything other than 0 to fail the commit
sys.exit(2)

Let’s change the mode of the pre-commit to executable (chmod +x pre-commit)

To test this setup, lets create a sandbox and then try to commit our changes to the server.
svn co svn://127.0.0.1
cd 127.0.0.1
mkdir test
svn add test
svn commit -m “adding the test directory”

Now we will see the pre-commit hook in action:

Adding test
svn: Commit failed (details follow):
svn: ‘pre-commit’ hook failed with error output:

Dear Sir,

As we are doing some important work in the server,all those who are submitting
the changes will have to wait for some time.

Sorry for the inconvenience caused.

Regards,

Administrator.


This is the most simplest hook that can be implemented in Python. More complex hooks can be implemented in python using the svn module. More useful hooks examples are available from http://subversion.tigris.org/tools_contrib.html#hook_scripts


Get Adobe Flash playerPlugin by wpburn.com wordpress themes