From 3e5ee5c748d751ff1a3ffc346389bd1c454aebea Mon Sep 17 00:00:00 2001 From: flavio Date: Tue, 31 Jul 2012 12:57:19 +0000 Subject: Repairing cairo and removing the network --- (limited to 'face.py') diff --git a/face.py b/face.py index dec365e..9768157 100644 --- a/face.py +++ b/face.py @@ -42,7 +42,7 @@ logger = logging.getLogger('speak') FACE_PAD = 2 -class Status: +class Status(): def __init__(self): self.voice = voice.defaultVoice() self.pitch = espeak.PITCH_MAX / 2 @@ -52,26 +52,26 @@ class Status: self.mouth = mouth.Mouth def serialize(self): - eyes = {eye.Eye: 1, - glasses.Glasses: 2} + eyes = {eye.Eye: 1, glasses.Glasses: 2} + mouths = {mouth.Mouth: 1, - fft_mouth.FFTMouth: 2, - waveform_mouth.WaveformMouth: 3} + fft_mouth.FFTMouth: 2, + waveform_mouth.WaveformMouth: 3} return cjson.encode({ 'voice': {'language': self.voice.language, - 'name': self.voice.name}, + 'name': self.voice.name}, 'pitch': self.pitch, 'rate': self.rate, 'eyes': [eyes[i] for i in self.eyes], 'mouth': mouths[self.mouth]}) def deserialize(self, buf): - eyes = {1: eye.Eye, - 2: glasses.Glasses} + eyes = {1: eye.Eye, 2: glasses.Glasses} + mouths = {1: mouth.Mouth, - 2: fft_mouth.FFTMouth, - 3: waveform_mouth.WaveformMouth} + 2: fft_mouth.FFTMouth, + 3: waveform_mouth.WaveformMouth} data = cjson.decode(buf) self.voice = voice.Voice(data['voice']['language'], @@ -94,49 +94,40 @@ class Status: class View(Gtk.EventBox): + """Face.""" + def __init__(self, fill_color=style.COLOR_BUTTON_GREY): Gtk.EventBox.__init__(self) + self.status = Status() self.fill_color = fill_color - - self.connect('size-allocate', self._size_allocate_cb) - + self.modify_bg(0, self.fill_color.get_gdk_color()) + self._audio = espeak.AudioGrab() - - # make an empty box for some eyes - self._eyes = None + + self._eyes = [] self._eyebox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) - self._eyebox.show() - - # make an empty box to put the mouth in + self._mouth = None self._mouthbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) - self._mouthbox.show() - - # layout the screen + box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - box.set_homogeneous(False) - box.pack_start(self._eyebox, expand=True, fill=True, padding=0) - box.pack_start(self._mouthbox, expand=True, fill=True, padding=100) - box.set_border_width(0) - self.modify_bg(0, self.fill_color.get_gdk_color()) + + box.pack_start(self._eyebox, True, True, 0) + box.pack_start(self._mouthbox, True, True, 0) + self.add(box) - - self._peding = None - self.connect('map', self.__map_cb) - - self.update() - - def __map_cb(self, widget): - if self._peding: - self.update(self._peding) - self._peding = None + self.show_all() def look_ahead(self): + """ Look. . .""" + if self._eyes: map(lambda e: e.look_ahead(), self._eyes) - + def look_at(self, pos=None): + """ Look. . .""" + if self._eyes: if pos is None: display = Gdk.Display.get_default() @@ -144,54 +135,42 @@ class View(Gtk.EventBox): else: x, y = pos map(lambda e, x=x, y=y: e.look_at(x, y), self._eyes) - + def update(self, status=None): - if not status: - status = self.status - else: - # FIXME: view object has no attribute flags - #if not self.flags() & Gtk.MAPPED: - # self._peding = status - # return - self.status = status - - if self._eyes: - for eye in self._eyes: - self._eyebox.remove(eye) - if self._mouth: - self._mouthbox.remove(self._mouth) - + """ Re packaged the mouth and eyes according to quantity.""" + + if status: self.status = status + + for eye in self._eyes: + self._eyebox.remove(eye) + + for child in self._mouthbox.get_children(): + self._mouthbox.remove(child) + self._eyes = [] - - for i in status.eyes: + for i in self.status.eyes: eye = i(self.fill_color) self._eyes.append(eye) + + for eye in self._eyes: self._eyebox.pack_start(eye, True, True, 0) - eye.show() - self._mouth = status.mouth(self._audio, self.fill_color) - self._mouth.show() - self._mouthbox.add(self._mouth) - - # enable mouse move events so we can track - # the eyes while the mouse is over the mouth - #self._mouth.add_events(gtk.gdk.POINTER_MOTION_MASK) + self._mouth = self.status.mouth(self._audio, self.fill_color) + self._mouthbox.pack_start(self._mouth, True, True, 0) + + self.show_all() def set_voice(self, voice): self.status.voice = voice self.say_notification(voice.friendlyname) def say(self, something): - self._audio.speak(self._peding or self.status, something) + self._audio.speak(self.status, something) def say_notification(self, something): - status = (self._peding or self.status).clone() + status = self.status.clone() status.voice = voice.defaultVoice() self._audio.speak(status, something) def shut_up(self): self._audio.stop_sound_device() - - def _size_allocate_cb(self, widget, allocation): - self._mouthbox.set_size_request(-1, - int(allocation.height / 2.5)) -- cgit v0.9.1