English to Gujarati Dictionary

Finally, I managed to complete the long awaited pending task to have a english to gujarati dictionary widget. I used pygtk (again) and get the job done. Earlier plugin was missing one thing – i.e. it used to display the meaning in the window (which has a tiny web browser in it, and the result is actually a response to a web query), but you cannot query another word from the same window. This newer widget has added this feature. It has:

1. Button
2. Text Box
3. Browser window (with only limited functionality – just to display the meaning of english word)

Now I can press ctrl+w by selecting any word and see the meaning + I can type a new word in the text box and press the button to view its meaning. So even if I want to view the meaning of a word which is nowhere in a screen (hence, i can’t select it), i can do that. Here is the screen shot:

Yo !!!
And the code is here…

#!/usr/bin/env python
import gtk
import random
import sys
import webkit
import os

class pyapp(gtk.Window):
    def __init__(self):
        super(pyapp,self).__init__()

        self.set_title("English to Gujarati Dictionary");
        self.set_size_request(700,500);
        self.set_position(gtk.WIN_POS_CENTER);
        self.connect("destroy", gtk.main_quit);

        self.glurl = "http://www.gujaratilexicon.com/Ajxindex.php?action=Ajxdictionary&mode=search&type=1&dictype=EG"

        hbox = gtk.HBox(False, 0);
        hbox1 = gtk.HBox(True, 0);
        vbox = gtk.VBox(False, 0);
        te = gtk.Entry(30);
        button1 = gtk.Button("Search Word");
        button1.connect_object("clicked", self.on_clicked, te)
        self.browser = webkit.WebView();
        self.scrollbar = gtk.ScrolledWindow();
        self.scrollbar.add(self.browser);

        f=os.popen("xclip -o")
        word = f.read()
        newword = word;
           
        if (word[-3:] == "ing"):
            newword = word[:-3]

        hbox.pack_start(button1, False, 0, 0);
        hbox.pack_end(te, True, 1, 0);
        hbox1.pack_start(self.scrollbar, True, True, 1);
        vbox.pack_start(hbox, False, 0, 0);
        vbox.pack_start(hbox1, True, True, 1);

        button1.show();
        te.show();
        self.add(vbox);
        self.show_all()
        self.browser.show()
        self.scrollbar.show()

        if (len(word) > 0):
            te.set_text(newword);
            self.on_clicked(te);
           

    def on_clicked(self, widget):
        irand=random.randint(1,4000)
        irand1=random.randint(7000,6000000);
        self.glurl = self.glurl+"&r="+str(irand)+"."+str(irand1)+"&sitem="+widget.get_text()
        self.browser.open(self.glurl);
        self.browser.show()
        self.scrollbar.show()

pyapp()
gtk.main()

Advertisements

3 thoughts on “English to Gujarati Dictionary

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s