Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAssim Deodia <assim.deodia@gmail.com>2008-07-09 16:34:14 (GMT)
committer Assim Deodia <assim.deodia@gmail.com>2008-07-09 16:34:14 (GMT)
commit421881b00310f3aa540be1a700e38a3921a13fbd (patch)
tree0ab10e3c40c066911b45bee0ce746e83159112c2
parent2b70f37fbd9eba4413dbb80351104aa9b6f3ea66 (diff)
GUI improved. database modified to include phoneme
-rw-r--r--dict.dbbin13402112 -> 13600768 bytes
-rw-r--r--dict.py40
-rwxr-xr-x[-rw-r--r--]las-gui.py126
-rw-r--r--las.py15
4 files changed, 127 insertions, 54 deletions
diff --git a/dict.db b/dict.db
index 8765420..7be9ab5 100644
--- a/dict.db
+++ b/dict.db
Binary files differ
diff --git a/dict.py b/dict.py
index 799912b..aa953c9 100644
--- a/dict.py
+++ b/dict.py
@@ -76,7 +76,7 @@ class Word:
self.word = None
self.length = None
self.synsetid_list = []
- return
+ return None
else:
return "Invalid Usage"
@@ -92,6 +92,13 @@ class Word:
def get_wordid(self):
return self.wordid
+
+ def get_category(self, categoryid):
+ self.category_list = []
+ self.cur.execute("SELECT * from las_categorydef where categoryid = ?", (categoryid,))
+ (categoryid, name, pos) = self.cur.fetchone()
+ return name
+
def get_synsetid(self):
self.cur.execute("SELECT * from las_sense where wordid = ?", (self.wordid,))
@@ -99,14 +106,16 @@ class Word:
self.synsetid_list.append(synsetid)
return self.synsetid_list
+
def get_def(self):
self.def_list = []
if self.synsetid_list == []:
self.get_synsetid()
for synsetid in self.synsetid_list:
self.cur.execute("SELECT * from las_synset where synsetid = ?", (synsetid,) )
- for (synsetid, pos, definition) in self.cur:
- self.def_list.append( (pos, definition))
+ for (synsetid, pos, categoryid, definition) in self.cur:
+ cat_name = self.get_category(categoryid)
+ self.def_list.append((pos, definition, cat_name))
return self.def_list
def get_usage(self):
@@ -116,20 +125,39 @@ class Word:
for synsetid in self.synsetid_list:
self.cur.execute("SELECT * from las_sample where synsetid = ?", (synsetid,))
for (synsetid, sampleid, sample) in self.cur:
- self.usage_list.append( (sample))
+ self.usage_list.append((sample))
return self.usage_list
+ def update_score(self, wordid, action = "correct"):
+ if action == "correct":
+ try:
+ self.cur.execute("SELECT * from las_score where wordid = ?", (wordid,))
+ (wordid, num_played, num_correct) = self.cur.fecthone()
+ num_played = num_played + 1
+ num_correct = num_correct + 1
+ self.cur.execute("UPDATE las_score SET num_played = ? , num_correct = ? where wordid = ?", (num_played, num_correct, wordid,))
+ except :
+ self.cur.execute("INSERT into las_score (wordid, num_played, num_correct) VALUES (?,?,?) ", (wordid,1,1, ))
+ elif action == "incorrect":
+ try:
+ self.cur.execute("SELECT * from las_score where wordid = ?", (wordid,))
+ (wordid, num_played, num_correct) = self.cur.fecthone()
+ num_played = num_played + 1
+ self.cur.execute("UPDATE las_score SET num_played = ? where wordid = ?", (num_played, wordid,))
+ except :
+ self.cur.execute("INSERT into las_score (wordid, num_played) VALUES (?,?) ", (wordid,1, ))
+ self.conn.commit()
if __name__ == "__main__":
k = Dict()
num_words = k.get_num_words()
print num_words
- id = k.get_random_wordid(length = 5, numwords = 3) #will return word of length 15
+ id = k.get_random_wordid(length = 5, numwords = 3) #will return word of length 5
for (wordid,) in id:
print wordid
l = Word("wordid", wordid )
print l.get_word()
print l.get_def()
- print l.get_usage() \ No newline at end of file
+ print l.get_usage()
diff --git a/las-gui.py b/las-gui.py
index 2d2e21b..796dc2e 100644..100755
--- a/las-gui.py
+++ b/las-gui.py
@@ -11,10 +11,16 @@ class LS_gui:
# This is a callback function. The data arguments are ignored
# in this example. More on callbacks below.
+ def __init__(self, handle):
+ self.__init__
+
def __init__(self):
DBname = "dict.db"
self.las = Listenspell(DBname)
self.load_activity_interface()
+ self.play_game("start")
+ gtk.main()
+
def destroy(self, widget, data=None):
#print "destroy signal occurred"
@@ -43,17 +49,27 @@ class LS_gui:
self.Hcontainer.pack_start(self.vcontainer_left,True, True,0)
- self.Hcontainer.pack_start(self.vcontainer_right,True, True,0)
+ self.Hcontainer.pack_end(self.vcontainer_right,False, False,0)
#####################Left Pane widgets##########################
- self.label_v_left_a = gtk.Label("Hello this is label 1")
- self.label_v_left_b = gtk.Label("label 2")
+ #self.label_v_left_a = gtk.Label("Hello this is label 1")
+ #self.label_v_left_b = gtk.Label("label 2")
- self.label_v_left_a.show()
- self.label_v_left_b.show()
+ #self.label_v_left_a.show()
+ #self.label_v_left_b.show()
- self.text_input = gtk.Entry(0)
+ self.main_output_view = gtk.TextView()
+ self.main_output_buffer = gtk.TextBuffer()
+ #self.main_output_buffer.set_text("This is main output")
+ self.main_output_view.set_editable(False)
+ self.main_output_view.set_buffer(self.main_output_buffer)
+
+ self.display_main_output("This is main output")
+
+ self.main_output_view.show_all()
+
+ self.text_input = gtk.Entry()
#self.text_input.set_text("Preset input text")
#self.text_input.
self.text_input.show()
@@ -61,8 +77,12 @@ class LS_gui:
self.text_input.connect("activate", self.text_input_activate, None)
self.console_text_view = gtk.TextView()
+
+
#self.console_text_view.show()
-
+ #self.h_adj = gtk.Adjustment(value=0, lower=0, upper=4, step_incr=1, page_incr=0, page_size=0)
+ #self.console_text_sw = gtk.ScrolledWindow(vadjustment=self.h_adj)
+
self.console_text_sw = gtk.ScrolledWindow()
self.console_text_sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
self.console_text_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
@@ -83,14 +103,14 @@ class LS_gui:
self.console_text_frame.add(self.console_text_sw)
self.console_text_frame.show_all()
- self.vcontainer_left.add(self.label_v_left_a)
- self.vcontainer_left.add(self.label_v_left_b)
- self.vcontainer_left.add(self.text_input)
- self.vcontainer_left.add(self.text_submit_button)
- self.vcontainer_left.add(self.console_text_frame)
+ self.vcontainer_left.pack_start(self.main_output_view, True, True )
+ #self.vcontainer_left.pack_start(self.label_v_left_b, True, False )
+ self.vcontainer_left.pack_start(self.text_input, False, True )
+ self.vcontainer_left.pack_start(self.text_submit_button, False, False )
+ self.vcontainer_left.pack_start(self.console_text_frame, True, True )
- ################################################################
+ ################################################True################
#################Right pane wigets##############################
@@ -126,17 +146,17 @@ class LS_gui:
self.stats_table = gtk.Table(4,2,True)
self.score_label = gtk.Label("Score: ")
- self.score_value_label = gtk.Label("s")
+ self.score_value_label = gtk.Label("?")
#self.score_value_label.
self.skill_level_label = gtk.Label("Skill Level: ")
- self.skill_level_value_label = gtk.Label("sl")
+ self.skill_level_value_label = gtk.Label("?")
self.words_played_label = gtk.Label("Words played: ")
- self.words_played_value_label = gtk.Label("wp")
+ self.words_played_value_label = gtk.Label("?")
self.words_correct_label = gtk.Label("Correct Words: ")
- self.words_correct_value_label = gtk.Label("cw")
+ self.words_correct_value_label = gtk.Label("?")
self.stats_table.attach(self.score_label, 0, 1, 0, 1)
self.stats_table.attach(self.score_value_label, 1, 2, 0, 1)
@@ -192,10 +212,10 @@ class LS_gui:
self.las.say_text(self.elem)
def get_def_button_clicked(self, widget, data = None):
- definition = self.las.get_word_info(self.wordid, "def")
+ def_list = self.las.get_word_info(self.wordid, "def")
self.display_console("Definition: ")
- for (pos, definition) in definition:
- self.display_console(pos + " : " + definition)
+ for (pos, definition, name) in def_list:
+ self.display_console(pos + "(" + name + ") : " + definition)
def get_usage_button_clicked(self, widget, data = None):
if self.usage_used == 0:
@@ -214,44 +234,53 @@ class LS_gui:
self.display_console("Word Length: " + str(len(self.elem)))
def ask_skill_level(self):
- dialog = gtk.Dialog("Enter Skill Level", self.main_window, 0,(gtk.STOCK_OK, gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL))
+ self.skill_level_dialog = gtk.Dialog("Enter Skill Level", self.main_window, 0,(gtk.STOCK_OK, gtk.RESPONSE_OK, "Quit Game", gtk.RESPONSE_CANCEL))
self.las.say_text("Skill Level")
hbox = gtk.HBox(False, 8)
hbox.set_border_width(8)
- dialog.vbox.pack_start(hbox, False, False, 0)
- stock = gtk.image_new_from_stock(
- gtk.STOCK_DIALOG_QUESTION,
- gtk.ICON_SIZE_DIALOG)
- hbox.pack_start(stock, False, False, 0)
-
+ self.skill_level_dialog.vbox.pack_start(hbox, False, False, 0)
+
table = gtk.Table(1, 1)
table.set_row_spacings(4)
table.set_col_spacings(4)
hbox.pack_start(table, True, True, 0)
label = gtk.Label("Skill Level")
- label.set_use_underline(True)
+ #label.set_use_underline(True)
table.attach(label, 0, 1, 0, 1)
local_skill_level = gtk.Entry()
local_skill_level.set_text(str(self.las.get_skill_level()))
+ local_skill_level.connect("activate", self.local_skill_level_activate, None)
table.attach(local_skill_level, 1, 2, 0, 1)
label.set_mnemonic_widget(local_skill_level)
- dialog.show_all()
- response = dialog.run()
+ self.skill_level_dialog.show_all()
+ response = self.skill_level_dialog.run()
if response == gtk.RESPONSE_OK:
skill_level = int (local_skill_level.get_text())
-
- dialog.destroy()
+ self.skill_level_dialog.destroy()
self.las.set_skill_level(skill_level)
self.update_all()
+
+ elif response == gtk.RESPONSE_CANCEL:
+ self.game_exit()
+ elif response == gtk.RESPONSE_NONE:
+ self.game_exit()
+
+ def local_skill_level_focus(self, widget, event, data= None):
+ #print "text_input_focus_in"
+ return False
+
+ def local_skill_level_activate(self, widget, data=None):
+ self.skill_level_dialog.response(gtk.RESPONSE_OK)
def shout(self,string):
self.display_console("")
for char in string:
self.display_console(char, newline = False)
self.las.say_text(char)
+ self.las.say_text(string)
################################################################
@@ -286,6 +315,8 @@ class LS_gui:
self.usage_used = -1
self.total_num_usage = -1
+ self.text_input.set_text("") # Clear answer field
+
# Initilazing variable for eacch word
self.elem = self.las.get_word_info(self.wordid, "word") #get a word from the list
@@ -304,7 +335,7 @@ class LS_gui:
self.las.play_sound("begin")
self.this_level_size = 7
self.this_level_max_error = 3
- self.display_label_a("Welcome")
+ self.display_main_output("Welcome")
self.las.say_text("Welcome")
self.ask_skill_level()
self.wordid_list = self.las.load_wordid(self.this_level_size + self.this_level_max_error)
@@ -331,18 +362,25 @@ class LS_gui:
########################Display Methods#########################
- def display_console(self, text, newline = True ):
+ def display_console(self, data, newline = True ):
if newline == True:
- text = "\n" + text
- self.console_text_buffer.insert_at_cursor(text)
-
- def display_label_a(self, text):
- self.label_v_left_a.set_text(text)
-
- def display_label_b(self, text):
- self.label_v_left_b.set_text(text)
+ data = "\n" + data
+ self.console_text_buffer.insert_at_cursor(data)
+
+ def display_main_output(self, data, newline = True, clear_previous = True):
+ if clear_previous == True:
+ self.main_output_buffer.set_text(data)
+ elif newline == True:
+ text = "\n" + data
+ self.main_output_buffer.insert_at_cursor(data)
+ else:
+ self.main_output_buffer.insert_at_cursor(data)
+
################################################################
+
+ def game_exit(self):
+ gtk.main_quit()
########################Game Logic##############################
@@ -360,5 +398,5 @@ class LS_gui:
if __name__ == "__main__":
gui = LS_gui()
#gui.__init__()
- gui.play_game("start")
- gui.main()
+ #gui.play_game("start")
+ #gui.main()
diff --git a/las.py b/las.py
index 3423e8a..9f31b57 100644
--- a/las.py
+++ b/las.py
@@ -91,9 +91,11 @@ class Listenspell():
self.play_sound("correct")
self.points = self.points + self.skill_level
self.words_correct = self.words_correct + 1
+ self.word_obj.update_score(wordid)
def ans_incorrect(self, wordid):
self.play_sound("incorrect")
+ self.word_obj.update_score(wordid, "incorrect")
def clear_screen(self,numlines=100):
"""Clear the console.
@@ -136,9 +138,14 @@ class Listenspell():
def say_text(self, text):
if self.init == False:
- bus = dbus.SessionBus()
- self.espeak_object = bus.get_object('org.laptop.Speech','/org/laptop/Speech')
- self.init = True
+ try:
+ bus = dbus.SessionBus()
+ self.espeak_object = bus.get_object('org.laptop.Speech','/org/laptop/Speech')
+ self.init = True
+ except dbus.exceptions.DBusException:
+ print "Speech Server not turned on."
+ return False
+
text = str(text)
self.espeak_object.SayText(text)
@@ -153,4 +160,4 @@ class Listenspell():
def exit_game(self):
self.say_text("goodbye")
- sys.exit() \ No newline at end of file
+ sys.exit()