Archive for June, 2009

KDE தமிழாக்கம் பயிற்சி வகுப்பு

Date : 28 / 06 / 09

Location : AU-KBC Block, MIT , Chrompet , Chennai.

Topics Discussed :    KDE – Tamil Translation .

Class Conducted By :  Mr. Ramdhas

Attenties : Nandha kumar, Manikandan, Ramachandran (Saveetha coll Mca Guys and My Classmates)   Santhosh ( Arunai coll BE Guy) , Sathish ( DMI Coll BE Guy) , Mr.Ravi Jeya , Rajkumar and I (Arulalan) ( KanchiLug Guys).

And Few More People . . .

kde

kde

Today Ramdhas sir gave a wonderful class about KDE Tamil Translation .

KDE is like Gnome GUI environment .  Its much graphical user interface.

KDE also supports for Tamil Fonts to users like

For Eg:

Settings      ->      அமைப்புகள்

Places         ->       இடங்கள்

Start            ->       தொடங்கு

Like this Kubuntu  environment should be in tamil fonts….

He explained how to Convert all english Strings to Tamil Strings  .

And he installed Lokalise and Poedit , Using any one of this application we can convert english to tamil string…

And he shows live demo….

Goal :

Our goal is , we have to give Kde-Base Application Tamil Translated Files for Kde 4.4 Releases ….

kubuntu 9.04

He gaves   kubuntu 9.04   cd to us …

kubuntu cd

kubuntu cd

Thanks to Mr.Ramdhas . !

Documentation will be updated by soon.

அருளாளன் . த

Advertisements

Comboboxentry-Glade-Ruby

A Exercise on Interdependent select (or chained select) using ComboBoxEntry in Glade3 And RubyCore:

we are going to develop chained selection module using comboboxentry .

In first comboboxentry, will list out countries names, when user select any one of countries from this list, application will display another dependent comboboxentry.

The second comboboxentry have to list out “states” which are all corresponding to selected country in first comboboxentry box.

Then it will be displayed , third comboboxentry & it will list out cities corresponding to the selected state in second comboboxentry box.


How to install ruby :

$sudo apt-get install ruby

How to install glade :

$sudo apt-get install glade

Or goto ‘synaptic package mamager’ and find glade3, select mark for installation and click ‘Apply’ button.

ruby-glade-create-template command :

To run this command we have to install ruby package,

$sudo apt-get install libglade2-ruby


How to install active-record :

$sudo apt-get install rubygems

$sudo gem install activerecord

Error :

While installing activerecord , it will show following error:

usr/bin/gem:10: undefined method `manage_gems’ for Gem:Module (NoMethodError)

For that do the following:

$sudo gedit /usr/bin/gem

add the following two lines in top of the coding :

require ‘rubygems’
require ‘rubygems/gem_runner’

and comment the next line by

#Gem.manage_gems

Glade Guide

1).Drag and drop “Window” from Top Level Window
2).Place “Fixed Layer” from Container in window
3).Take three “ComboBoxEntry” and place in window.
4).Set lable name to each comboboxentry and comboboxentry-entry1 to identify.

Signal:

set “changed “ signal to all comboboxentry widget. And save it as “combo.glade”

Open Glade3 from Programming Application

1

Opened Glade Window

2

Select Window Widget and drop in design area

3

Drag and drop “fixed” widget and plce inside toplevel window

4

Take comboboxentry

5

Change your comboboxentry widget label name to identify

6

Allign and customize comboboxentry widget box size

7

Set ‘change siganl’ to all comboboxentry from the “Signal”menu side panel

8

9

Drag and drop the ‘Label’ widget & change label name & allign it.

10

Final design view

11

Ruby Guide

$ ruby-glade-create-template combo.glade > combo.rb

Initialize Method :

Add one line inside initialize method as follow .

@glade[“Window1”].show_all

“Window1” is a default lable name of top level window. If u want change that lable name…

Program :

# Active Record

require ‘libglade2’
require ‘rubygems’
require ‘active_record’
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false
ActiveRecord::Base.establish_connection(
:adapter => “mysql”,
:encoding => “utf8”,
:database => “country”,
:username => “root”,
:password =>”password”,
:socket => “/var/run/mysqld/mysqld.sock”,
:dbfile => “:memory:”
)
ActiveRecord::Schema.define  do
create_table :countries do |table|
table.column :name, :string
end
create_table :states do |table|
table.column :country_id, :integer
table.column :name, :string
end
create_table :cities do |table|
table.column :state_id, :integer
table.column :name, :string
end
end
=begin
create database “ country” in your mysql by excuting this query
“mysql > create database country; “.
And set your mysql root user name “root” and “password” in the above code.
You can understand easily by seeing the above code, how active record creates tables and
corresponding fields.
Create_table: ‘table name’ – – – > It will create table in db.
Column: name, :String ( Field Type) – – -> It will set column field by this type and name.
=end
# Relationships :
class Country < ActiveRecord::Base
has_many :state
end
class State < ActiveRecord::Base
belongs_to :country
has_many :cities
end
class City < ActiveRecord::Base
belongs_to :state
end
=begin
This tells about relationships among those tables…
“Country “ table record entries having relationship with so many “State” table record
entries…
simply we can represent by one to many relationship, so in this case we have used “
has_many ”. This means a country “has_many” states.
“State” table record entries having relations under “Country” table record entries…. It can
be represented by “ belongs_to “. Since every state belongs to a country hence we have used
“belongs_to” in the state class to say that it belongs to a country.
=end
# Populating values into tables :
country=Country.new(:name=>’India’)
country.save
# here we are inserting value ‘India’ into country table
country.state << State.new(:name => ‘TamilNadu’)
# it will insert value ‘TamilNadu’ into state table with country_id
country.state.find(:all,:conditions => {:name => ‘TamilNadu’}).first.cities << City.new(:name
=>’Chennai’)
# it will append the new entries ‘ Chennai ‘ in “city” table with ‘Country_id’ and ‘ State_id’ .
country=Country.new(:name=>’America’)
country.save
country.state << State.new(:name => ‘Ohio’)
country.state.find(:all,:conditions => {:name => ‘Ohio’}).first.cities << City.new(:name
=>’Chicago’)
# Like wise, you can insert values into three tables as your wish
# and insert more country, states and city names in corresponding tables . . .
class ComboCountryGlade
include GetText
attr :glade
def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)
bindtextdomain(domain, localedir, nil, “UTF-8”)
@glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler|
method(handler)}
@glade[‘window1’].show_all
country_combo _method
end
# ComboBoxEntry Methods
# country method :
def country_combo_method
@glade[“country_comboboxentry”].show_all
@glade[“state_comboboxentry”].hide_all
@glade[“State_label”].hide_all
@glade[“city_comboboxentry”].hide_all
@glade[“City_label”].hide_all
# here, we are hiding state and city comboboxentry and their lables
@country_combobox = @glade[“country_comboboxentry”]
@country_list = Gtk::ListStore.new(String)
@country_cell = Gtk::CellRendererText.new()
# here, we are setting comboboxentry properties to box by calling inbuild Gtk methods
@country_combobox.pack_start(@country_cell, true)
@country_combobox.add_attribute(@country_cell, ‘text’,0)
@country_combobox.set_model(@country_list)
@country=Country.all
# here, we calling active record class.
# [Country.all] —> it will return all countries entries
@country.each do |country_name|
@country_iter =@country_list.append
@country_iter[0] =country_name.name
end
end
=begin
here, c_name is iterative variable of @country array record.
From that, we need “ country name field alone”, so that we use [c_name.name] —-> it will
return countries name.
[@c_list_cat.append] —–> it will helps to append strings in comboboxentry.
=end
# ComboBoxEntry change signal code : for country
def on_country_comboboxentry_changed(widget)
@country_click_iter= @glade[‘country_comboboxentry’].active_iter
@country_list.each do |model,path,@iter_country|
if path.to_s == @country_click_iter.to_s
@glade[‘country_comboboxentry-entry1’].text =@iter_country[0]
country_name=@glade[‘country_comboboxentry-entry1’].text
@state_combo = @glade[“state_comboboxentry”]
@state_combo.clear
state_combo_method(country_name)
end
end
end
=begin
active_iter : return , pointer of comboboxentry list by corresponding to mouse or keyboard
press on list.
path.to_s : to identify TreeView path of combobox entry.
state_combo(country_name) : Iside country change signal method, we are going to call “
State Comboboxentry and passing argument as country name, which is selected by user at
run time.
same like this logic we have to write code for state and city comboboxentries also .
=end
# State mathod :
def state_combo_method(country_name)
@glade[“state_comboboxentry”].show_all
@glade[“State_label”].show_all
@glade[“city_comboboxentry”].hide_all
@glade[“City_label”].hide_all
@state_combobox = @glade[“state_comboboxentry”]
@state_list = Gtk::ListStore.new(String)
@state_cell = Gtk::CellRendererText.new()
@glade[‘state_comboboxentry-entry2’].text=””
@state_combobox.pack_start(@state_cell, true)
@state_combobox.add_attribute(@state_cell, ‘text’,0)
@state_combobox.set_model(@state_list)
country1=Country.find(:all,:conditions=>{:name=>country_name}).first.state
country1.each do |state_name|
@state_iter =@state_list.append
@state_iter[0] =state_name.name
end
end
# ComboBoxEntry change signal code : for state
def on_state_comboboxentry_changed(widget)
state_click_iter= @glade[‘state_comboboxentry’].active_iter
@state_list.each do |model,path,@iter_state|
if path.to_s == state_click_iter.to_s
@glade[‘state_comboboxentry-entry2’].text =@iter_state[0]
state_name= @glade[‘state_comboboxentry-entry2’].text
@city_combo=@glade[“city_comboboxentry”]
@city_combo.clear
city_combo_method( state_name)
end
end
end
end
# city method :
def city_combo_method(state_name)
@glade[“city_comboboxentry”].show_all
@glade[“City_label”].show_all
@city_combo = @glade[“city_comboboxentry”]
@city_list = Gtk::ListStore.new(String)
@city_cell = Gtk::CellRendererText.new()
@glade[‘city_comboboxentry-entry3’].text=””
@city_combo.pack_start(@city_cell, true)
@city_combo.add_attribute(@city_cell, ‘text’,0)
@city_combo.set_model(@city_list)
city=State.all(:conditions=>{:name=>state_name}).first.cities
city.each do |city_name|
@city_iter =@city_list.append
@city_iter[0] =city_name.name
end
end
# ComboBoxEntry change signal code : for city
def on_city_comboboxentry_changed(widget)
@city_click_iter= @glade[‘city_comboboxentry’].active_iter
@city_list.each do |model,path,@iter_city|
if path.to_s == @city_click_iter.to_s
@glade[‘city_comboboxentry-entry3’].text =@iter_city[0]
end
end
end
# Main program for glade
if __FILE__ == $0
# Set values as your own application.
PROG_PATH = “combo_country.glade”
PROG_NAME = “YOUR_APPLICATION_NAME”
ComboCountryGlade.new(PROG_PATH, nil, PROG_NAME)
Gtk.main
end
# End of program
=begin
Save the whole program as combo.rb
And then run this program in terminal.
$ruby combo.rb
while running this combo.rb , combo.glade file must contain in the same folder.
=end



Output window :1

combo1

Output window : 2

combo2

Output window : 3
combo3

Output window : 4

combo4

Output window : 5
combo5

Output window : 6
combo6

Output window : 7

combo7

Use :

Using this Chained Selection program , we are developing a school management application with following scenerio .

first select one ‘class’ from class_combobox_entry and then choose ‘section’ from section_combobox_entry and then finally select ‘student name’ from student_combobox_entry.

you can download this program source code from here

you can download this document as pdf from here

Enjoy with Ruby and Glade .


Best wishes from Arulalan.T

அருளாளன்.த

require 'libglade2'
require 'rubygems'
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false
ActiveRecord::Base.establish_connection(
    :adapter => "mysql",
    :encoding => "utf8",
    :database => "country",
    :username => "root",
    :password =>"password",
    :socket => "/var/run/mysqld/mysqld.sock",
    :dbfile => ":memory:"
)
ActiveRecord::Schema.define do
    create_table :countries do |table|
        table.column :name, :string
    end
    create_table :states do |table|
        table.column :country_id, :integer
        table.column :name, :string
    end
    create_table :cities do |table|
        table.column :state_id, :integer
        table.column :name, :string
    end
end
=begin
create database “ country” in your mysql by excuting this query
“mysql > create database country; “.
And set your mysql root user name “root” and “password” in the above code.
You can understand easily by seeing the above code, how active record creates tables and corresponding fields.
Create_table: 'table name' - - - > It will create table in db.
Column: name, :String ( Field Type) - - -> It will set column field by this type and name.
=end
# Relationships :
class Country < ActiveRecord::Base
    has_many :state
end
class State < ActiveRecord::Base
    belongs_to :country
    has_many :cities
end
class City < ActiveRecord::Base
   belongs_to :state
end
=begin
This tells about relationships among those tables...
“Country “ table record entries having relationship with so many “State” table record entries...
simply we can represent by one to many relationship, so in this case we have used “ has_many ”. This means a country “has_many” states.
“State” table record entries having relations under “Country” table record entries.... It can be represented by “ belongs_to “. Since every state belongs to a country hence we have used “belongs_to” in the state class to say that it belongs to a country.
=end
 # Populating values into tables :
country=Country.new(:name=>'India')
country.save
# here we are inserting value 'India' into country table
country.state << State.new(:name => 'TamilNadu')
# it will insert value 'TamilNadu' into state table with country_id
country.state.find(:all,:conditions => {:name => 'TamilNadu'}).first.cities << City.new(:name =>'Chennai')
# it will append the new entries ' Chennai ' in “city” table with 'Country_id' and ' State_id' .
country=Country.new(:name=>'America')
country.save
country.state << State.new(:name => 'Ohio')
country.state.find(:all,:conditions => {:name => 'Ohio'}).first.cities << City.new(:name =>'Chicago')
# Like wise, you can insert values into three tables as your wish
# and insert more country, states and city names in corresponding tables . . .
class ComboCountryGlade
  include GetText
  attr :glade
  def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)
    bindtextdomain(domain, localedir, nil, "UTF-8")
    @glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}
    @glade['window1'].show_all
     country_combo_method
  end
 # ComboBoxEntry Methods
 # country method :
def country_combo_method
  @glade["country_comboboxentry"].show_all
  @glade["state_comboboxentry"].hide_all
  @glade["State_label"].hide_all
  @glade["city_comboboxentry"].hide_all
  @glade["City_label"].hide_all
  # here, we are hiding state and city comboboxentry and their lables
  @country_combobox = @glade["country_comboboxentry"]
  @country_list = Gtk::ListStore.new(String)
  @country_cell = Gtk::CellRendererText.new()
             # here, we are setting comboboxentry properties to box by calling inbuild Gtk methods
  @country_combobox.pack_start(@country_cell, true)
  @country_combobox.add_attribute(@country_cell, 'text',0)
  @country_combobox.set_model(@country_list)
            @country=Country.all
           # here, we calling active record class.
           # [Country.all] ---> it will return all countries entries
                        @country.each do |country_name|
     @country_iter =@country_list.append
     @country_iter[0] =country_name.name
                  end
 end
=begin
here, c_name is iterative variable of @country array record.
From that, we need “ country name field alone”, so that we use [c_name.name] ----> it will return countries name.
[@c_list_cat.append] -----> it will helps to append strings in comboboxentry.
=end
# ComboBoxEntry change signal code : for country
def on_country_comboboxentry_changed(widget)
    @country_click_iter= @glade['country_comboboxentry'].active_iter
            @country_list.each do |model,path,@iter_country|
     if path.to_s == @country_click_iter.to_s
       @glade['country_comboboxentry-entry1'].text =@iter_country[0]
                       country_name=@glade['country_comboboxentry-entry1'].text
                       @state_combo = @glade["state_comboboxentry"]
                       @state_combo.clear
                        state_combo_method(country_name)
               end
          end
   end
=begin
active_iter : return , pointer of comboboxentry list by corresponding to mouse or keyboard press on list.
path.to_s : to identify TreeView path of combobox entry.
state_combo(country_name) : Iside country change signal method, we are going to call “ State Comboboxentry and passing argument as country name, which is selected by user at run time.
same like this logic we have to write code for state and city comboboxentries also .
=end
# State mathod :
def state_combo_method(country_name)
  @glade["state_comboboxentry"].show_all
  @glade["State_label"].show_all
  @glade["city_comboboxentry"].hide_all
  @glade["City_label"].hide_all
  @state_combobox = @glade["state_comboboxentry"]
  @state_list = Gtk::ListStore.new(String)
  @state_cell = Gtk::CellRendererText.new()
   @glade['state_comboboxentry-entry2'].text=""
  @state_combobox.pack_start(@state_cell, true)
  @state_combobox.add_attribute(@state_cell, 'text',0)
  @state_combobox.set_model(@state_list)
            country1=Country.find(:all,:conditions=>{:name=>country_name}).first.state
  country1.each do |state_name|
     @state_iter =@state_list.append
     @state_iter[0] =state_name.name
        end
 end
# ComboBoxEntry change signal code : for state
def on_state_comboboxentry_changed(widget)
  state_click_iter= @glade['state_comboboxentry'].active_iter
            @state_list.each do |model,path,@iter_state|
   if path.to_s == state_click_iter.to_s
   @glade['state_comboboxentry-entry2'].text =@iter_state[0]
   state_name= @glade['state_comboboxentry-entry2'].text
     @city_combo=@glade["city_comboboxentry"]
     @city_combo.clear
   city_combo_method( state_name)
   end
         end
  end
end
# city method :
 def city_combo_method(state_name)
  @glade["city_comboboxentry"].show_all
  @glade["City_label"].show_all
  @city_combo = @glade["city_comboboxentry"]
  @city_list = Gtk::ListStore.new(String)
  @city_cell = Gtk::CellRendererText.new()
  @glade['city_comboboxentry-entry3'].text=""
  @city_combo.pack_start(@city_cell, true)
  @city_combo.add_attribute(@city_cell, 'text',0)
  @city_combo.set_model(@city_list)
  city=State.all(:conditions=>{:name=>state_name}).first.cities
  city.each do |city_name|
     @city_iter =@city_list.append
     @city_iter[0] =city_name.name
   end
  end
# ComboBoxEntry change signal code : for city
  def on_city_comboboxentry_changed(widget)
  @city_click_iter= @glade['city_comboboxentry'].active_iter
             @city_list.each do |model,path,@iter_city|
   if path.to_s == @city_click_iter.to_s
   @glade['city_comboboxentry-entry3'].text =@iter_city[0]
   end
       end
  end
# Main program
if __FILE__ == $0
  # Set values as your own application.
  PROG_PATH = "combo_country.glade"
  PROG_NAME = "YOUR_APPLICATION_NAME"
  ComboCountryGlade.new(PROG_PATH, nil, PROG_NAME)
  Gtk.main
end
# End of program
=begin
Save the whole program as combo.rb
And then run this program in terminal.
$ruby combo.rb
while running this combo.rb , combo.glade file must contain in the same folder.
=end

RAD INSTALLATION GUIDE

Ruby Arduino Development (RAD) Installation

we tried to install rad (Ruby Arduino Development) in ubuntu , but it showed many errors because of version variation between Ruby and Rubygems…

so we tried to install rad in new ubuntu loaded system. even there we got few errors, but finally we have installed successfully.

If gem works properly in your system then , just run:

$sudo gem install rad


In new ubuntu system ( or remove already installed ruby and rubygems)

to install rad follow the below steps:

Type the following link in your URL

www.rubyhead.com/files/installruby.zip


Then it will ask to save file and save that.

Now Extract (unzip) this “installruby.zip”…


$cd installruby


change the current directory into installruby folder via Terminal. Now run this following

$ ./installruby

(Here ‘installruby’ is a scripting program and it will install ruby,irb,rubygems, rails and many needed packages automatically.)


$sudo gem install rad


It will take some time to install and end with “could not find main page README.txt”

Many things will be installed and from that it installed “ParseTree-3.0.3”.. This is higher version , and it will make version conflict error while executing rake make:compile our project.

So we have to uninstall that and replace with “ParseTree-2.2.0”

$sudo gem uninstall ParseTree

Now it asks to remove some packages and we have to agree it by press “y”

(yes). And even it asks to remove “RubyToC” , so remove that too..

Now install “ParseTree-2.2.0”

$ sudo gem install –version=2.2.0 ParseTree


$sudo gem install RubyToC

Now we are going to download Arduino software.

Arduino Software Download Link:

http://arduino.cc/en/Main/Software

In that web page we have more links to download arduino, from that we have to choose below line:

Arduino 0012 (release notes): Windows, Mac OS X, Linux (32bit), Linux (AMD 64bit)

From this click Linux(32 bit) , then it will started to download

Then extract the downloaded “arduino-0012-linux.tgz”

Then we have to install gcc library for avr

$sudo apt-get install gcc-avr avr-libc

Now we have to make link between avr-gcc libraries and arduino

first create a directory “avr” inside the arduino-0012/hardware/tools.

$mkdir arduino-0012/hardware/tools/avr


$ ln -s /usr/bin /home/user name/arduino-0012/hardware/tools/avr

Now we finished all our installation & linking works. Let us start to work in rad.

RAD Use Guide

$rad my_sketch

Now it will created “my_sketch” folder inside current directory…

Inside that folder it has “my_sketch.rb” ,we have to write our ruby code for arduino in that file.

Inside that it have “config” folder, it contains “hardware.yml” and “software.yml”.

We have to edit “software.yml” and set the path to arduino( /home/user name/arduino-0012 )

We have to edit “hardware.yml” also

serial_port: /dev/ttyS0

physical_reset: false

mcu: atmega8

If the chip is does not atmega8 then change to corresponding chip name.(atmega168)

$rake make:compile

Reset your Arduino Board


$rake make:upload

Enjoy with RAD !

அருளாளன் . த

Hello world!

Welcome to all. I am ARULALAN.T , doing M.C.A in Saveetha Engg College, Chennai.

Here I am sharing my experience and experiments in Linux .

And I love Ruby Very Much .

I hope all my posts may helps you. !

Be Love Freedom & Live In Tux World