diff options
author | flavio <fdanesse@gmail.com> | 2012-08-04 16:27:48 (GMT) |
---|---|---|
committer | flavio <fdanesse@gmail.com> | 2012-08-04 16:27:48 (GMT) |
commit | 663b6c907c1f75502b1ccc0135a9532634830a88 (patch) | |
tree | cce7e17271e1fefafa51f4c1182b29df22e90f5e /Speak.py |
Diffstat (limited to 'Speak.py')
-rw-r--r-- | Speak.py | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/Speak.py b/Speak.py new file mode 100644 index 0000000..9a0a5a2 --- /dev/null +++ b/Speak.py @@ -0,0 +1,197 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +import sys +import os + +import gi +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GObject +from gi.repository import GdkX11 + +from Widgets import Speaking +from Widgets import Toolbar +from Widgets import ToolbarPitchRate +from Widgets import ToolbarFace +from Sound import Sound + +BASE = os.path.dirname(__file__) + +GObject.threads_init() +Gdk.threads_init() + +class Speak(Gtk.Window): + + def __init__(self): + Gtk.Window.__init__(self) + + self.set_title("Hablar con Sara") + self.set_icon_from_file(os.path.join(BASE, "icons", "face.svg")) + self.set_resizable(True) + self.set_border_width(0) + self.set_size_request(640, 480) + self.modify_bg(0, Gdk.Color(65000, 28260, 30516)) + + self.add_events( + Gdk.EventMask.POINTER_MOTION_HINT_MASK | + Gdk.EventMask.POINTER_MOTION_MASK) + + self.toolbar = None + self.toolbarpitchrate = None + self.toolbarface = None + self.notebook = None + self.speaking = None + self.sound = None + + self.dinamic_toolbars = [] + + self.setup_init() + + def setup_init(self): + """Se crean los objetos y se empaqueta todo.""" + + self.toolbar = Toolbar() + self.toolbarpitchrate = ToolbarPitchRate() + self.toolbarface = ToolbarFace() + self.notebook = Gtk.Notebook() + self.notebook.set_show_border(False) + self.notebook.set_show_tabs(False) + + vbox = Gtk.Box(orientation = Gtk.Orientation.VERTICAL) + vbox.pack_start(self.toolbar, False, False,0) + vbox.pack_start(self.toolbarpitchrate, False, False,0) + vbox.pack_start(self.toolbarface, False, False,0) + + self.speaking = Speaking() # Pagina inicial en el notebook + self.notebook.append_page(self.speaking, Gtk.Label("")) + vbox.pack_start(self.notebook, True, True,0) + + self.dinamic_toolbars = [self.toolbarpitchrate, self.toolbarface] + + self.add(vbox) + + self.show_all() + + map(self.hide_widgets, self.dinamic_toolbars) + + xid = self.speaking.face.get_property('window').get_xid() + self.sound = Sound(xid) + + self.sound.set_pitch(100) + self.sound.set_rate(100) + self.sound.set_voice('es') + + self.connect("motion_notify_event", self.mouse_moved) + + self.toolbar.connect("switch-voice", self.switch_voice) + #self.toolbar.connect("switch-desktop", # cambiar entre speaking, chat y robot) + self.toolbar.connect("switch-toolbar", self.switch_toolbar) + + self.toolbarpitchrate.connect("pitch", self.switch_pitch) + self.toolbarpitchrate.connect("rate", self.switch_rate) + + self.toolbarface.connect("number-eyes", self.number_eyes) + self.toolbarface.connect("switch-type-mouth", self.switch_type_mouth) + self.toolbarface.connect("switch-type-eyes", self.switch_type_eyes) + + self.speaking.connect("speak", self.speak) + + self.connect("delete_event", self.delete_event) + self.connect("destroy", self.salir) + + def speak(self, widget, value): + """Cuando el usuario ingresa texto para hablar.""" + + self.sound.speak(value) + + def switch_pitch(self, widget, value): + """cuando cambia pitch.""" + + self.sound.set_pitch(value) + self.sound.speak("Campo Modificado.") + + def switch_rate(self, widget, value): + """Cuando cambia rate.""" + + self.sound.set_rate(value) + self.sound.speak("Velocidad Modificada.") + + def number_eyes(self, widget, value): + """Recibe la cantidad de ojos que deben dibujarse.""" + + self.speaking.face.set_number_eyes(value) + self.sound.speak("Ojos Modificados.") + + def switch_type_mouth(self, widget, value): + """Recibe el tipo de dibujo para la boca.""" + + self.speaking.face.set_type_mouth(value) + self.sound.speak("Boca Modificada.") + + def switch_type_eyes(self, widget, value): + """Recibe el tipo de ojos a dibujar.""" + + self.speaking.face.set_type_eyes(value) + self.sound.speak("Ojos Modificados.") + + def switch_toolbar(self, widget, value): + """Para que se muestre la toolbar pitch-rate o face""" + + if value == "pitch-rate": + if self.toolbarpitchrate.get_visible(): + self.toolbarpitchrate.hide() + else: + map(self.hide_widgets, self.dinamic_toolbars) + self.toolbarpitchrate.show() + + elif value == "face": + if self.toolbarface.get_visible(): + self.toolbarface.hide() + else: + map(self.hide_widgets, self.dinamic_toolbars) + self.toolbarface.show() + + def hide_widgets(self, objeto): + """Esta funcion es llamada desde self.switch_toolbar()""" + + if objeto.get_visible(): objeto.hide() + + def switch_voice(self, widget, value): + """Cuando cambia el lenguaje.""" + + self.sound.set_voice(value) + self.sound.speak("Voz Modificada.") + + def delete_event(self, widget = None, event = None, data = None): + self.salir() + return False + + def salir(self, widget = None, senial = None): + sys.exit(0) + + def mouse_moved(self, widget, event): + """Le dice a la cara hacia donde mirar.""" + + pos = (event.x, event.y) + self.speaking.look_at(pos) + +if __name__=="__main__": + Speak() + Gtk.main() +
\ No newline at end of file |