Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Cristaldo <rcristal@gmail.com>2013-01-24 20:53:57 (GMT)
committer Roberto Cristaldo <rcristal@gmail.com>2013-01-24 20:53:57 (GMT)
commitb0f97c8510d446afec7a8a09e4f50c09d96564f8 (patch)
tree2ca68bb66330aae6f3ac39f4742543d2e9a9a8ec
parentecb5d99eb721b99b6b8198b47684168c07544df3 (diff)
Funciona el random de palabras y letras. Falta integrar
-rwxr-xr-xEjemplo.py17
-rw-r--r--activity.py57
-rwxr-xr-xelephant.py123
3 files changed, 128 insertions, 69 deletions
diff --git a/Ejemplo.py b/Ejemplo.py
index 207452f..b0b53b4 100755
--- a/Ejemplo.py
+++ b/Ejemplo.py
@@ -1,9 +1,11 @@
#!/usr/bin/python
-import get_words
+import elephant
+
+from subprocess import Popen
def main():
- words = get_words.word_list()
+ words = elephant.word_list()
word_list = words.get_word_list()
print 'Lista de palabras'
@@ -22,5 +24,16 @@ def main():
print 'Palabra aleatoria %s y el path correspndiente %s' %(word, path)
+ choice_letter = elephant.letters()
+
+ letter_to_say = 'Donde esta la letra '
+ letter_to_say += choice_letter.get_letter(word)
+ print letter_to_say
+
+ say(letter_to_say)
+
+def say(text):
+ Popen(['espeak', '-v', 'es', text])
+
if __name__ == "__main__":
main() \ No newline at end of file
diff --git a/activity.py b/activity.py
index 4fe56cc..a8718f4 100644
--- a/activity.py
+++ b/activity.py
@@ -16,6 +16,9 @@
import gtk
import logging
+import elephant
+
+from random import choice
from gettext import gettext as _
@@ -71,6 +74,12 @@ class ElephantActivity(activity.Activity):
# self.set_canvas(label)
# label.show()
+ # Instances to Elephants classes
+ words = elephant.word_list()
+ choice_letter = elephant.letters()
+
+
+
# Vertical box conteinter definition
vbox_main = gtk.VBox()
@@ -92,15 +101,23 @@ class ElephantActivity(activity.Activity):
button_option3 = gtk.Button()
button_option3.set_label('Opcion 3:')
- # Label and image area
- image_word = gtk.Image()
- pixbuf = gtk.gdk.pixbuf_new_from_file("images/elefante_logo.png")
- scaled_pixbuf = pixbuf.scale_simple(150,150,gtk.gdk.INTERP_BILINEAR)
- image_word.set_from_pixbuf(scaled_pixbuf)
+ #Old activity title
+ #image_word = gtk.Image()
+ #pixbuf = gtk.gdk.pixbuf_new_from_file("images/elefante_logo.png")
+ #scaled_pixbuf = pixbuf.scale_simple(150,150,gtk.gdk.INTERP_BILINEAR)
+ #image_word.set_from_pixbuf(scaled_pixbuf)
+
+ #label_word = gtk.Label()
+ #label_word.set_text('Elefante')
+
- label_word = gtk.Label()
- label_word.set_text('Elefante')
+ #Get a word form word list and path
+ word, path = self.get_random_word(words)
+ #Image and label word
+ image_word = self.show_image(path)
+ label_word = self.show_label(word)
+
# Create layout
self.set_canvas(vbox_main)
vbox_main.add(hbox_01)
@@ -119,4 +136,28 @@ class ElephantActivity(activity.Activity):
#ShowMeTheMoney!!!
vbox_main.show_all()
-
+
+ # Get random word form word list
+ def get_random_word(self, words):
+ word_list = words.get_word_list()
+ word = choice(word_list)
+ path = words.get_word_image_path(word)
+
+ return word, path
+
+ # Create image from path
+ def show_image(self, path):
+ image = gtk.Image()
+ pixbuf = gtk.gdk.pixbuf_new_from_file(path)
+ scaled_pixbuf = pixbuf.scale_simple(150,150,gtk.gdk.INTERP_BILINEAR)
+ image.set_from_pixbuf(scaled_pixbuf)
+
+ return image
+
+ # Crete label form word
+ def show_label(self,word):
+ label = gtk.Label()
+ label.set_text(word)
+
+ return label
+
diff --git a/elephant.py b/elephant.py
index 3cde126..5f680e7 100755
--- a/elephant.py
+++ b/elephant.py
@@ -1,69 +1,74 @@
#!/usr/bin/python
-import gtk
+import ConfigParser
-class ElephantApp():
+from random import choice
- def __init__ (self):
- # Main windows definition
- window_main = gtk.Window()
+# Global definition
+CONF_FILE='elephant.conf'
+CAT_SECTION='Categories'
+WORDS_SECTION='Words'
- # Vertical box conteinter definition
- vbox_main = gtk.VBox()
+# Class
+# Return the word list from config file and numbers of word
+class word_list:
+
+ def __init__(self):
+ # Number of words
+ self.number_of_words = len(self.get_word_list())
- # Horizontal boxes conteiners definition
- hbox_01 = gtk.HBox()
- hbox_02 = gtk.HBox()
- hbox_03 = gtk.HBox()
+ # Get all categories from config file
+ def get_categories(self):
+ parser = ConfigParser.SafeConfigParser()
+ parser.read(CONF_FILE)
- # Buttons definitions
- button_repeat = gtk.Button()
- button_repeat.set_label('Repetir')
-
- button_option1 = gtk.Button()
- button_option1.set_label('Opcion 1:')
+ full_list = parser.items(CAT_SECTION)
+ category_list = [row[1] for row in full_list]
+
+ return category_list
+
+ # Get all words from a specifir category
+ #def get_words_in_category(self, category):
+ # parser = ConfigParser.SafeConfigParser()
+ # parser.read(CONF_FILE)
+ #
+ # word_list = parser.options(category)
+ #
+ # return word_list
+
+ # Get all words form config file
+ def get_word_list(self):
+ parser = ConfigParser.SafeConfigParser()
+ parser.read(CONF_FILE)
- button_option2 = gtk.Button()
- button_option2.set_label('Opcion 2:')
+ full_list = parser.items(WORDS_SECTION)
+ word_list = [row[0] for row in full_list]
+
+ return word_list
+
+ # Get path of choosen image
+ def get_word_image_path(self, word):
+ parser = ConfigParser.SafeConfigParser()
+ parser.read(CONF_FILE)
+
+ image_path = parser.get(WORDS_SECTION, word)
+
+ return image_path
+
+class letters:
+
+ def __init__(self):
+ pass
+
+ def get_letter(self, word):
+ letter = choice (word)
+
+ return letter
+
- button_option3 = gtk.Button()
- button_option3.set_label('Opcion 3:')
-
- # Label and image area
- image_word = gtk.Image()
- pixbuf = gtk.gdk.pixbuf_new_from_file("images/elephant.jpg")
- scaled_pixbuf = pixbuf.scale_simple(150,150,gtk.gdk.INTERP_BILINEAR)
- image_word.set_from_pixbuf(scaled_pixbuf)
- label_word = gtk.Label()
- label_word.set_text('Elefante')
-
- # Connect to destructor
- window_main.connect('destroy', self.destroy)
-
- # Create layout
- window_main.add(vbox_main)
- vbox_main.add(hbox_01)
- vbox_main.add(hbox_02)
- vbox_main.add(hbox_03)
-
- # Put label and label on layout
- hbox_02.add(image_word)
- hbox_02.add(label_word)
-
- # Put buttons on layout
- hbox_01.add(button_repeat)
- hbox_03.add(button_option1)
- hbox_03.add(button_option2)
- hbox_03.add(button_option3)
-
- # ShowMeTheMoney
- window_main.show_all()
-
- # Kaaabbbuummm!!
- def destroy(self, elephant_window, data=None):
- gtk.main_quit()
-
-if __name__ == "__main__":
- elephant = ElephantApp()
- gtk.main() \ No newline at end of file
+
+
+
+
+ \ No newline at end of file