Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Ortiz <rafael@activitycentral.com>2011-07-13 05:04:03 (GMT)
committer Rafael Ortiz <rafael@activitycentral.com>2011-07-13 05:04:03 (GMT)
commitc9cfc5ca3c8662d965bf0e1e3921145bd490a1a0 (patch)
tree41f0fe8aa7be249af5e3298ecea13fc5ae15397c
parente33814dc9e60e0273b1e9467e23cfe69fe463e7e (diff)
various pep8 fixes
-rw-r--r--speak/eye.py45
-rw-r--r--speak/face.py29
-rw-r--r--speak/glasses.py47
-rw-r--r--speak/mouth.py37
-rw-r--r--speak/voice.py3
5 files changed, 87 insertions, 74 deletions
diff --git a/speak/eye.py b/speak/eye.py
index 1fe23f5..7996d9d 100644
--- a/speak/eye.py
+++ b/speak/eye.py
@@ -7,8 +7,8 @@
#
# Parts of Speak.activity are based on code from Measure.activity
# Copyright (C) 2007 Arjun Sarwal - arjun@laptop.org
-#
-# Speak.activity is free software: you can redistribute it and/or modify
+#
+# Speak.activity 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 3 of the License, or
# (at your option) any later version.
@@ -28,13 +28,14 @@ import gobject
import cairo
import math
+
class Eye(gtk.DrawingArea):
def __init__(self, fill_color):
gtk.DrawingArea.__init__(self)
self.connect("expose_event", self.expose)
self.frame = 0
self.blink = False
- self.x, self.y = 0,0
+ self.x, self.y = 0, 0
self.fill_color = fill_color
# listen for clicks
@@ -78,17 +79,17 @@ class Eye(gtk.DrawingArea):
if self.x is None or self.y is None:
# look ahead, but not *directly* in the middle
- if a.x + a.width/2 < self.parent.get_allocation().width/2:
+ if a.x + a.width / 2 < self.parent.get_allocation().width / 2:
cx = a.width * 0.6
else:
cx = a.width * 0.4
return cx, a.height * 0.6
EYE_X, EYE_Y = self.translate_coordinates(
- self.get_toplevel(), a.width/2, a.height/2)
+ self.get_toplevel(), a.width / 2, a.height / 2)
EYE_HWIDTH = a.width
EYE_HHEIGHT = a.height
- BALL_DIST = EYE_HWIDTH/4
+ BALL_DIST = EYE_HWIDTH / 4
dx = self.x - EYE_X
dy = self.y - EYE_Y
@@ -106,23 +107,23 @@ class Eye(gtk.DrawingArea):
dx = dist * cosa
dy = dist * sina
- return a.width/2 + dx, a.height/2 + dy
+ return a.width / 2 + dx, a.height / 2 + dy
def expose(self, widget, event):
self.frame += 1
bounds = self.get_allocation()
eyeSize = min(bounds.width, bounds.height)
- outlineWidth = eyeSize/20.0
- pupilSize = eyeSize/10.0
+ outlineWidth = eyeSize / 20.0
+ pupilSize = eyeSize / 10.0
pupilX, pupilY = self.computePupil()
- dX = pupilX - bounds.width/2.
- dY = pupilY - bounds.height/2.
- distance = math.sqrt(dX*dX + dY*dY)
- limit = eyeSize/2 - outlineWidth*2 - pupilSize
+ dX = pupilX - bounds.width / 2.
+ dY = pupilY - bounds.height / 2.
+ distance = math.sqrt(dX * dX + dY * dY)
+ limit = eyeSize / 2 - outlineWidth * 2 - pupilSize
if distance > limit:
- pupilX = bounds.width/2 + dX*limit/distance
- pupilY = bounds.height/2 + dY*limit/distance
+ pupilX = bounds.width / 2 + dX * limit / distance
+ pupilY = bounds.height / 2 + dY * limit / distance
self.context = widget.window.cairo_create()
#self.context.set_antialias(cairo.ANTIALIAS_NONE)
@@ -133,23 +134,23 @@ class Eye(gtk.DrawingArea):
# background
self.context.set_source_rgba(*self.fill_color.get_rgba())
- self.context.rectangle(0,0,bounds.width,bounds.height)
+ self.context.rectangle(0, 0, bounds.width, bounds.height)
self.context.fill()
# eye ball
- self.context.arc(bounds.width/2,bounds.height/2, eyeSize/2-outlineWidth/2, 0,360)
- self.context.set_source_rgb(1,1,1)
+ self.context.arc(bounds.width / 2, bounds.height / 2, eyeSize / 2 - outlineWidth / 2, 0, 360)
+ self.context.set_source_rgb(1, 1, 1)
self.context.fill()
# outline
self.context.set_line_width(outlineWidth)
- self.context.arc(bounds.width/2,bounds.height/2, eyeSize/2-outlineWidth/2, 0,360)
- self.context.set_source_rgb(0,0,0)
+ self.context.arc(bounds.width / 2, bounds.height / 2, eyeSize / 2 - outlineWidth / 2, 0, 360)
+ self.context.set_source_rgb(0, 0, 0)
self.context.stroke()
# pupil
- self.context.arc(pupilX,pupilY,pupilSize,0,360)
- self.context.set_source_rgb(0,0,0)
+ self.context.arc(pupilX, pupilY, pupilSize, 0, 360)
+ self.context.set_source_rgb(0, 0, 0)
self.context.fill()
self.blink = False
diff --git a/speak/face.py b/speak/face.py
index 5ad632c..ffbe556 100644
--- a/speak/face.py
+++ b/speak/face.py
@@ -44,8 +44,9 @@ FACE_PAD = 2
class Status:
def __init__(self):
self.voice = voice.defaultVoice()
- self.pitch = espeak.PITCH_DEFAULT
- self.rate = espeak.RATE_DEFAULT
+ self.pitch = espeak.PITCH_MAX / 2
+ self.rate = espeak.RATE_MAX / 2
+
self.eyes = [eye.Eye] * 2
self.mouth = mouth.Mouth
@@ -110,7 +111,7 @@ class View(gtk.EventBox):
self._mouth = None
self._mouthbox = gtk.HBox()
self._mouthbox.show()
-
+
# layout the screen
box = gtk.VBox(homogeneous=False)
box.pack_start(self._eyebox)
@@ -121,12 +122,11 @@ class View(gtk.EventBox):
self._mapped = False
self._peding = None
- self.connect("map_event",self._map_event)
+ self.connect('map', self.__map_cb)
self.update()
-
- def _map_event(self, widget, event):
- self._mapped = True
+
+ def __map_cb(self, widget):
if self._peding:
self.update(self._peding)
self._peding = None
@@ -135,15 +135,20 @@ class View(gtk.EventBox):
if self._eyes:
map(lambda e: e.look_ahead(), self._eyes)
- def look_at(self, x, y):
+ def look_at(self, pos=None):
if self._eyes:
- map(lambda e, x=x, y=y: e.look_at(x,y), self._eyes)
+ if pos is None:
+ display = gtk.gdk.display_get_default()
+ screen_, x, y, modifiers_ = display.get_pointer()
+ 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:
- if not self._mapped:
+ if not self.flags() & gtk.MAPPED:
self._peding = status
return
self.status = status
@@ -169,6 +174,10 @@ class View(gtk.EventBox):
# 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)
+ 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)
diff --git a/speak/glasses.py b/speak/glasses.py
index fb64bbd..399c01a 100644
--- a/speak/glasses.py
+++ b/speak/glasses.py
@@ -23,24 +23,25 @@
from eye import *
+
class Glasses(Eye):
def __init__(self, fill_color):
Eye.__init__(self, fill_color)
def expose(self, widget, event):
bounds = self.get_allocation()
-
+
eyeSize = min(bounds.width, bounds.height)
- outlineWidth = eyeSize/20.0
- pupilSize = eyeSize/10.0
- pupilX, pupilY = self.pupil_position()
- dX = pupilX - bounds.width/2.
- dY = pupilY - bounds.height/2.
- distance = math.sqrt(dX*dX + dY*dY)
- limit = eyeSize/2 - outlineWidth*2 - pupilSize
+ outlineWidth = eyeSize / 20.0
+ pupilSize = eyeSize / 10.0
+ pupilX, pupilY = self.computePupil()
+ dX = pupilX - bounds.width / 2.
+ dY = pupilY - bounds.height / 2.
+ distance = math.sqrt(dX * dX + dY * dY)
+ limit = eyeSize / 2 - outlineWidth * 2 - pupilSize
if distance > limit:
- pupilX = bounds.width/2 + dX*limit/distance
- pupilY = bounds.height/2 + dY*limit/distance
+ pupilX = bounds.width / 2 + dX * limit / distance
+ pupilY = bounds.height / 2 + dY * limit / distance
self.context = widget.window.cairo_create()
#self.context.set_antialias(cairo.ANTIALIAS_NONE)
@@ -51,31 +52,31 @@ class Glasses(Eye):
# background
self.context.set_source_rgba(*self.fill_color.get_rgba())
- self.context.rectangle(0,0,bounds.width,bounds.height)
+ self.context.rectangle(0, 0, bounds.width, bounds.height)
self.context.fill()
- def roundrect(x1,y1, x2,y2):
- self.context.move_to(x1, (y1+y2)/2.)
- self.context.curve_to(x1,y1, x1,y1, (x1+x2)/2.,y1)
- self.context.curve_to(x2,y1, x2,y1, x2,(y1+y2)/2.)
- self.context.curve_to(x2,y2, x2,y2, (x1+x2)/2.,y2)
- self.context.curve_to(x1,y2, x1,y2, x1,(y1+y2)/2.)
+ def roundrect(x1, y1, x2, y2):
+ self.context.move_to(x1, (y1 + y2) / 2.)
+ self.context.curve_to(x1, y1, x1, y1, (x1 + x2) / 2., y1)
+ self.context.curve_to(x2, y1, x2, y1, x2, (y1 + y2) / 2.)
+ self.context.curve_to(x2, y2, x2, y2, (x1 + x2) / 2., y2)
+ self.context.curve_to(x1, y2, x1, y2, x1, (y1 + y2) / 2.)
# eye ball
- roundrect(outlineWidth,outlineWidth, bounds.width-outlineWidth,bounds.height-outlineWidth)
- self.context.set_source_rgb(1,1,1)
+ roundrect(outlineWidth, outlineWidth, bounds.width - outlineWidth, bounds.height - outlineWidth)
+ self.context.set_source_rgb(1, 1, 1)
self.context.fill()
# outline
self.context.set_line_width(outlineWidth)
- roundrect(outlineWidth,outlineWidth, bounds.width-outlineWidth,bounds.height-outlineWidth)
+ roundrect(outlineWidth, outlineWidth, bounds.width - outlineWidth, bounds.height - outlineWidth)
#roundrect(0,0, bounds.width,bounds.height)
- self.context.set_source_rgb(0,0,0)
+ self.context.set_source_rgb(0, 0, 0)
self.context.stroke()
# pupil
- self.context.arc(pupilX,pupilY,pupilSize,0,360)
- self.context.set_source_rgb(0,0,0)
+ self.context.arc(pupilX, pupilY, pupilSize, 0, 360)
+ self.context.set_source_rgb(0, 0, 0)
self.context.fill()
return True
diff --git a/speak/mouth.py b/speak/mouth.py
index b01155a..a72312a 100644
--- a/speak/mouth.py
+++ b/speak/mouth.py
@@ -28,11 +28,12 @@ import cairo
from struct import unpack
import numpy.core
+
class Mouth(gtk.DrawingArea):
def __init__(self, audioSource, fill_color):
gtk.DrawingArea.__init__(self)
- self.connect("expose_event",self.expose)
+ self.connect("expose_event", self.expose)
self.buffers = []
self.buffer_size = 256
self.main_buffers = []
@@ -45,10 +46,10 @@ class Mouth(gtk.DrawingArea):
if len(buf) < 28:
self.newest_buffer = []
else:
- self.newest_buffer = list(unpack( str(int(len(buf))/2)+'h' , buf))
+ self.newest_buffer = list(unpack(str(int(len(buf)) / 2) + 'h', buf))
self.main_buffers += self.newest_buffer
- if(len(self.main_buffers)>self.buffer_size):
- del self.main_buffers[0:(len(self.main_buffers)- \
+ if(len(self.main_buffers) > self.buffer_size):
+ del self.main_buffers[0:(len(self.main_buffers) - \
self.buffer_size)]
self.queue_draw()
@@ -58,7 +59,7 @@ class Mouth(gtk.DrawingArea):
if len(self.main_buffers) == 0 or len(self.newest_buffer) == 0:
self.volume = 0
else:
- self.volume = numpy.core.max(self.main_buffers)# - numpy.core.min(self.main_buffers)
+ self.volume = numpy.core.max(self.main_buffers) # - numpy.core.min(self.main_buffers)
def expose(self, widget, event):
"""This function is the "expose" event handler and does all the drawing."""
@@ -71,30 +72,30 @@ class Mouth(gtk.DrawingArea):
self.context.set_antialias(cairo.ANTIALIAS_NONE)
#set a clip region for the expose event. This reduces redrawing work (and time)
- self.context.rectangle(event.area.x, event.area.y,event.area.width, event.area.height)
+ self.context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
self.context.clip()
# background
self.context.set_source_rgba(*self.fill_color.get_rgba())
- self.context.rectangle(0,0, bounds.width,bounds.height)
+ self.context.rectangle(0, 0, bounds.width, bounds.height)
self.context.fill()
# Draw the mouth
- volume = self.volume / 65535.
+ volume = self.volume / 30000.
mouthH = volume * bounds.height
- mouthW = volume**2 * (bounds.width/2.) + bounds.width/2.
+ mouthW = volume**2 * (bounds.width / 2.) + bounds.width / 2.
# T
# L R
# B
- Lx,Ly = bounds.width/2 - mouthW/2, bounds.height/2
- Tx,Ty = bounds.width/2, bounds.height/2 - mouthH/2
- Rx,Ry = bounds.width/2 + mouthW/2, bounds.height/2
- Bx,By = bounds.width/2, bounds.height/2 + mouthH/2
- self.context.set_line_width(min(bounds.height/10.0, 10))
- self.context.move_to(Lx,Ly)
- self.context.curve_to(Tx,Ty, Tx,Ty, Rx,Ry)
- self.context.curve_to(Bx,By, Bx,By, Lx,Ly)
- self.context.set_source_rgb(0,0,0)
+ Lx, Ly = bounds.width / 2 - mouthW / 2, bounds.height / 2
+ Tx, Ty = bounds.width / 2, bounds.height / 2 - mouthH / 2
+ Rx, Ry = bounds.width / 2 + mouthW / 2, bounds.height / 2
+ Bx, By = bounds.width / 2, bounds.height / 2 + mouthH / 2
+ self.context.set_line_width(min(bounds.height / 10.0, 10))
+ self.context.move_to(Lx, Ly)
+ self.context.curve_to(Tx, Ty, Tx, Ty, Rx, Ry)
+ self.context.curve_to(Bx, By, Bx, By, Lx, Ly)
+ self.context.set_source_rgb(0, 0, 0)
self.context.close_path()
self.context.stroke()
diff --git a/speak/voice.py b/speak/voice.py
index 5fc732e..1e984db 100644
--- a/speak/voice.py
+++ b/speak/voice.py
@@ -21,7 +21,8 @@
# You should have received a copy of the GNU General Public License
# along with Speak.activity. If not, see <http://www.gnu.org/licenses/>.
-import re, os
+import re
+import os
from gettext import gettext as _
import logging