#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Paralperu
# Copyright 2008 Santhosh Thottingal <santhosh.thottingal@gmail.com>
# http://www.smc.org.in
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# If you find any bugs or have any suggestions email: santhosh.thottingal@gmail.com
# URL: http://www.smc.org.in

import pygtk
pygtk.require('2.0')
import gtk

     
class Paralperu:
    def destroy(self, widget, data=None):
        gtk.main_quit()

    def __init__(self):
        window =  gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.connect("delete_event", self.destroy)
        vbox = gtk.VBox(True, 2)
        window.add(vbox)
        topBox = gtk.Table(rows=2, columns=6, homogeneous=True)
   
        wordlabel = gtk.Label("വാചകം:")
        wordlabel.set_justify(gtk.JUSTIFY_LEFT)
        resultlabel = gtk.Label(" സംഖ്യ: ")
        pbutton = gtk.Button(label="_Paralperu")
        pbutton.connect_object("clicked",self.paralperu, window)
        pbutton.show()
        qbutton = gtk.Button(label="_Quit")
        qbutton.connect_object("clicked",self.destroy, window)
        qbutton.show()
        resultlabel.set_justify(gtk.JUSTIFY_LEFT)
        self.entry = gtk.Entry(max=0)
        self.result = gtk.Entry(max=0)
        self.entry.show()
        wordlabel.show()
        self.result.show()
        resultlabel.show()
        topBox.attach(wordlabel,  0,  1 , 0, 1, gtk.FILL, gtk.FILL, 2)
        topBox.attach(self.entry, 1,  5 , 0, 1,  gtk.FILL, gtk.FILL, 2)
        topBox.attach(pbutton, 5,6,0,1, gtk.FILL, gtk.FILL, 2)
        topBox.attach(resultlabel, 0, 1 ,1,2, gtk.FILL, gtk.FILL, 2)
        topBox.attach(self.result, 1,5, 1, 2, gtk.FILL, gtk.FILL, 2)
        topBox.attach(qbutton, 5,6, 1, 2, gtk.FILL, gtk.FILL, 2)
        topBox.show()
      
        fButtons = gtk.HBox(homogeneous=False, spacing=0)
        infolabel = gtk.Label("രചിച്ചതു്: സന്തോഷ് തോട്ടിങ്ങല്‍ \nഅനുമതിപത്രം: GPLv3+ \nപരല്‍പേരിനെകുറിച്ചു കൂടുതലറിയാന്‍  http://ml.wikipedia.org/wiki/Paralperu")
        infolabel.set_justify(gtk.JUSTIFY_LEFT)
        fButtons.pack_start(infolabel, True, True, 2)
        infolabel.show()

    
        fButtons.show()
        vbox.pack_start(topBox)
        vbox.pack_start(fButtons)
        vbox.show()
        
        window.set_border_width(10)
        window.set_title("പരല്‍പേരു്")
        window.show()

      
    def paralperu(self, widget, data=None):
        text = unicode(self.entry.get_text())
        result = ""
        index = len(text) - 1
        while index >= 0:
              if  ((index)>= 0 ) :
                  if (text[index]== '്'):
                      index = index - 2 #skip the letter before chandrakkala
                      continue
              if (text[index] == 'ക'):
                  result = result + '1'
              if (text[index]== 'ട'):
                  result = result + '1'
              if (text[index]== 'പ'):
                  result = result + '1'
              if (text[index]== 'യ'):
                  result = result + '1'
                  
              if (text[index]== 'ഖ'):
                  result = result + '2'
              if (text[index]== 'ഠ'):
                  result = result + '2'
              if (text[index]== 'ഫ'):
                  result = result + '2'
              if (text[index]== 'ര'):
                  result = result + '2'
                  
              if (text[index]== 'ഗ'):
                  result = result + '3'
              if (text[index]== 'ഡ'):
                  result = result + '3'
              if (text[index]== 'ബ'):
                  result = result + '3'
              if (text[index]== 'ല'):
                  result = result + '3'
                  
              if (text[index]== 'ഘ'):
                  result = result + '4'
              if (text[index]== 'ഢ'):
                  result = result + '4'
              if (text[index]== 'ഭ'):
                  result = result + '4'
              if (text[index]== 'വ'):
                  result = result + '4'
                  
              if (text[index]== 'ങ'):
                  result = result + '5'
              if (text[index]== 'ണ'):
                  result = result + '5'
              if (text[index]== 'മ'):
                  result = result + '5'
              if (text[index]== 'ശ'):
                  result = result + '5'
                  
              if (text[index]== 'ച'):
                  result = result + '6'
              if (text[index]== 'ത'):
                  result = result + '6'
              if (text[index]== 'ഷ'):
                  result = result + '6'
                  
              if (text[index]== 'ഛ'):
                  result = result + '7'
              if (text[index]== 'ഥ'):
                  result = result + '7'
              if (text[index]== 'സ'):
                  result = result + '7'
        
              if (text[index]== 'ജ'):
                  result = result + '8'
              if (text[index]== 'ദ'):
                  result = result + '8'
              if (text[index]== 'ഹ'):
                  result = result + '8'
        
              if (text[index]== 'ഝ'):
                  result = result + '9'
              if (text[index]== 'ധ'):
                  result = result + '9'
              if (text[index]== 'ള'):
                  result = result + '9'
        
              if (text[index]== 'ഞ'):
                  sult = result + '0'
              if (text[index]== 'ന'):
                  result = result + '0'
              if (text[index]== 'ഴ'):
                  result = result + '0'
              if (text[index]== 'റ'):
                  result = result + '0'

              if (text[index]== 'അ'):
                  sult = result + '0'
              if (text[index]== 'ആ'):
                  result = result + '0'
              if (text[index]== 'ഇ'):
                  result = result + '0'
              if (text[index]== 'ഈ'):
                  result = result + '0'
              if (text[index]== 'ഉ'):
                  sult = result + '0'
              if (text[index]== 'ഊ'):
                  result = result + '0'
              if (text[index]== 'ഋ'):
                  result = result + '0'
              if (text[index]== 'ൠ'):
                  result = result + '0'
              if (text[index]== 'ഌ'):
                  sult = result + '0'
              if (text[index]== 'ൡ'):
                  result = result + '0'
              if (text[index]== 'എ'):
                  result = result + '0'
              if (text[index]== 'ഏ'):
                  result = result + '0'
              if (text[index]== 'ഒ'):
                  sult = result + '0'
              if (text[index]== 'ഓ'):
                  result = result + '0'
              if (text[index]== 'ഔ'):
                  result = result + '0'
              index = index-1    
 
        self.result.set_text( result)
      

    def main(self):
          gtk.main()

if __name__ == "__main__":
      paralperu = Paralperu()
      paralperu.main()
