Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflavio <fdanesse@gmail.com>2012-07-31 14:09:40 (GMT)
committer flavio <fdanesse@gmail.com>2012-07-31 14:09:40 (GMT)
commitbdee0fb30a0e4d9da08fc7481e20070a3ce7ac0a (patch)
tree7c4df1c9a1e73b4b495497a1f00eedac74b9a5f7
parent777d75ee9daedc65e37f4b15e924feb2f6b6dcb6 (diff)
Modularization of the eye
-rw-r--r--activity.py8
-rw-r--r--chat.py3
-rw-r--r--eye.py59
-rw-r--r--face.py13
-rw-r--r--glasses.py92
5 files changed, 70 insertions, 105 deletions
diff --git a/activity.py b/activity.py
index 7761ad1..1090ad5 100644
--- a/activity.py
+++ b/activity.py
@@ -42,8 +42,8 @@ from toolitem import ToolWidget
from messenger import Messenger, SERVICE
from gettext import gettext as _
-import eye
-import glasses
+from eye import Eye
+from eye import Glasses
from mouth import Mouth
from mouth import FFTMouth
from mouth import WaveformMouth
@@ -406,8 +406,8 @@ class SpeakActivity(activity.Activity):
facebar.insert(mouth_shape_toolitem, -1)
self.eye_shape_combo = ComboBox()
- self.eye_shape_combo.append_item(eye.Eye, _("Round"))
- self.eye_shape_combo.append_item(glasses.Glasses, _("Glasses"))
+ self.eye_shape_combo.append_item(Eye, _("Round"))
+ self.eye_shape_combo.append_item(Glasses, _("Glasses"))
self.eye_shape_combo.set_active(0)
eye_shape_toolitem = ToolWidget(
diff --git a/chat.py b/chat.py
index ecbf1e1..c6af775 100644
--- a/chat.py
+++ b/chat.py
@@ -25,9 +25,6 @@ import sugar3.graphics.style as style
from roundbox import RoundBox
from sugar3.graphics.toggletoolbutton import ToggleToolButton
-import eye
-import glasses
-import mouth
import face
import messenger
from chatbox import ChatBox
diff --git a/eye.py b/eye.py
index 2729388..7374f92 100644
--- a/eye.py
+++ b/eye.py
@@ -133,4 +133,61 @@ class Eye(Gtk.DrawingArea):
context.fill()
return True
- \ No newline at end of file
+
+class Glasses(Eye):
+ def __init__(self, fill_color):
+ Eye.__init__(self, fill_color)
+
+ self.show_all()
+ self.connect('draw', self.do_draw)
+
+ def do_draw(self, widget, context):
+ rect = self.get_allocation()
+
+ eyeSize = min(rect.width, rect.height)
+ outlineWidth = eyeSize / 20.0
+ pupilSize = eyeSize / 10.0
+ pupilX, pupilY = self.computePupil()
+ dX = pupilX - rect.width / 2.
+ dY = pupilY - rect.height / 2.
+ distance = math.sqrt(dX * dX + dY * dY)
+ limit = eyeSize / 2 - outlineWidth * 2 - pupilSize
+ if distance > limit:
+ pupilX = rect.width / 2 + dX * limit / distance
+ pupilY = rect.height / 2 + dY * limit / distance
+
+ # background
+ context.set_source_rgba(*self.fill_color.get_rgba())
+ context.paint()
+
+ def roundrect(x1, y1, x2, y2):
+ context.move_to(x1, (y1 + y2) / 2.)
+ context.curve_to(x1, y1, x1, y1, (x1 + x2) / 2., y1)
+ context.curve_to(x2, y1, x2, y1, x2, (y1 + y2) / 2.)
+ context.curve_to(x2, y2, x2, y2, (x1 + x2) / 2., y2)
+ context.curve_to(x1, y2, x1, y2, x1, (y1 + y2) / 2.)
+
+ # eye ball
+ context.set_source_rgb(1, 1, 1)
+ roundrect(outlineWidth,
+ outlineWidth,
+ rect.width - outlineWidth,
+ rect.height - outlineWidth)
+ context.fill()
+
+ # outline
+ context.set_source_rgb(0, 0, 0)
+ context.set_line_width(outlineWidth)
+ roundrect(outlineWidth,
+ outlineWidth,
+ rect.width - outlineWidth,
+ rect.height - outlineWidth)
+ #roundrect(0,0, rect.width,rect.height)
+ context.stroke()
+
+ # pupil
+ context.arc(pupilX, pupilY, pupilSize, 0, 360)
+ context.set_source_rgb(0, 0, 0)
+ context.fill()
+
+ return True \ No newline at end of file
diff --git a/face.py b/face.py
index 7dd0498..6e208a5 100644
--- a/face.py
+++ b/face.py
@@ -31,7 +31,8 @@ import sugar3.graphics.style as style
import espeak
import eye
-import glasses
+from eye import Eye
+from eye import Glasses
from mouth import Mouth
from mouth import FFTMouth
from mouth import WaveformMouth
@@ -52,7 +53,7 @@ class Status():
self.mouth = Mouth
def serialize(self):
- eyes = {eye.Eye: 1, glasses.Glasses: 2}
+ eyes = {Eye: 1, Glasses: 2}
mouths = {Mouth: 1,
FFTMouth: 2,
@@ -67,7 +68,7 @@ class Status():
'mouth': mouths[self.mouth]})
def deserialize(self, buf):
- eyes = {1: eye.Eye, 2: glasses.Glasses}
+ eyes = {1: Eye, 2: Glasses}
mouths = {1: Mouth,
2: FFTMouth,
@@ -141,11 +142,13 @@ class View(Gtk.EventBox):
if status: self.status = status
- for eye in self._eyes:
- self._eyebox.remove(eye)
+ for child in self._eyebox.get_children():
+ self._eyebox.remove(child)
+ child.destroy()
for child in self._mouthbox.get_children():
self._mouthbox.remove(child)
+ child.destroy()
self._eyes = []
for i in self.status.eyes:
diff --git a/glasses.py b/glasses.py
deleted file mode 100644
index c491085..0000000
--- a/glasses.py
+++ /dev/null
@@ -1,92 +0,0 @@
-# Speak.activity
-# A simple front end to the espeak text-to-speech engine on the XO laptop
-# http://wiki.laptop.org/go/Speak
-#
-# Copyright (C) 2008 Joshua Minor
-# This file is part of Speak.activity
-#
-# 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
-# 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.
-#
-# Speak.activity 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 Speak.activity. If not, see <http://www.gnu.org/licenses/>.
-
-from eye import *
-
-
-class Glasses(Eye):
- def __init__(self, fill_color):
- Eye.__init__(self, fill_color)
-
- def do_draw(self, context):
- bounds = self.get_allocation()
-
- eyeSize = min(bounds.width, bounds.height)
- 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
-
- self.context = context
- #self.context.set_antialias(cairo.ANTIALIAS_NONE)
-
- #set a clip region for the expose event.
- # This reduces redrawing work (and time)
- self.context.rectangle(bounds.x,
- bounds.y,
- bounds.width,
- bounds.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.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.)
-
- # eye ball
- 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(0,0, bounds.width,bounds.height)
- 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.fill()
-
- return True