-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
executable file
·58 lines (47 loc) · 1.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# coding=utf-8
from gi.repository import Gtk, GObject
import sqlite3
# Connecting to DATABASE
connection = sqlite3.connect('db/dict.db')
sql = connection.cursor()
def eng2bn(word):
# FETCHING INDEX
sql.execute('SELECT * FROM english WHERE word=?', (word.upper(),))
try:
bn_index = sql.fetchone()[0]
# FETCHING MEANING
sql.execute('SELECT * FROM bengali WHERE serial=?', (bn_index,))
meaning = sql.fetchone()[1]
return meaning
except TypeError:
return "শব্দটি পাওয়া যায়নি!"
class DictGui:
def __init__(self):
builder = Gtk.Builder()
builder.add_from_file("ui.glade")
self.window = builder.get_object("main_window")
self.search_en = builder.get_object("search_en")
self.result_view = builder.get_object("result_lab")
self.mnu_about = builder.get_object("mnu_about")
self.about_dialog = builder.get_object("aboutdialog")
builder.connect_signals(self)
def show_about(self, about):
abt = self.about_dialog.run()
self.about_dialog.hide()
def on_search_activate(self, search_en):
# Main Event Handler
word = self.search_en.get_text()
if word == '':
self.result_view.set_text('')
return
result = eng2bn(word)
if result != None:
self.result_view.set_text(result)
def mnu_quite_app(self, window):
Gtk.main_quit()
if __name__ == '__main__':
dict = DictGui()
dict.window.connect("delete-event", Gtk.main_quit)
dict.window.show_all()
Gtk.main()