Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgnacio Rodriguez <ignacio@sugarlabs.org>2013-12-25 00:11:22 (GMT)
committer Ignacio Rodriguez <ignacio@sugarlabs.org>2013-12-25 00:11:22 (GMT)
commit520d3d62569b12123e874c2705f7fbcf816784f1 (patch)
treea9675a5782678f205ab53a4314d7d188873b379a
parent7ed2d31fa15bd8253e8139fa7e7a59f632d145d8 (diff)
A lot of fixes in gtk3 portgtk3
-rw-r--r--activity.py7
-rw-r--r--audio.py21
-rw-r--r--cardlist.py8
-rw-r--r--cardtable.py7
-rw-r--r--createcardpanel.py4
-rw-r--r--createtoolbar.py8
-rw-r--r--face.py6
-rw-r--r--game.py4
-rw-r--r--port/roundbox.py4
-rw-r--r--speak/espeak.py19
-rw-r--r--speak/espeak_gst.py4
-rw-r--r--speak/eye.py102
-rw-r--r--speak/face.py6
-rw-r--r--speak/mouth.py15
-rw-r--r--svgcard.py21
15 files changed, 85 insertions, 151 deletions
diff --git a/activity.py b/activity.py
index 75c7bae..8362a03 100644
--- a/activity.py
+++ b/activity.py
@@ -30,10 +30,13 @@ import zipfile
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
+from gi.repository import Gst
# activate threads for gst needs
+Gst.init([])
GObject.threads_init()
+
import telepathy
import telepathy.client
@@ -217,11 +220,11 @@ class MemorizeActivity(Activity):
def _change_mode_bt(self, button):
if button.get_active():
self._change_mode(_MODE_CREATE)
- button.set_named_icon('player_play')
+ button.set_icon_name('player_play')
button.set_tooltip(_('Play game'))
else:
self._change_mode(_MODE_PLAY)
- button.set_named_icon('view-source')
+ button.set_icon_name('view-source')
button.set_tooltip(_('Edit game'))
def read_file(self, file_path):
diff --git a/audio.py b/audio.py
index ddee412..edc9872 100644
--- a/audio.py
+++ b/audio.py
@@ -1,4 +1,5 @@
# Copyright (C) 2006, 2007, 2008 One Laptop Per Child
+# Copyright (C) 2013, Ignacio Rodriguez
#
# 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
@@ -15,16 +16,18 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
-import gst
+from gi.repository import Gst
import logging
_logger = logging.getLogger('memorize-activity')
+Gst.init([])
+
class Audio(object):
def __init__(self):
- self._player = gst.element_factory_make('playbin', 'player')
- fakesink = gst.element_factory_make('fakesink', 'my-fakesink')
+ self._player = Gst.ElementFactory.make('playbin', 'player')
+ fakesink = Gst.ElementFactory.make('fakesink', 'my-fakesink')
self._player.set_property('video-sink', fakesink)
self._playing = None
@@ -36,28 +39,28 @@ class Audio(object):
if filename:
_logger.debug('play audio %s' % filename)
self._player.set_property('uri', 'file://' + filename)
- self._player.set_state(gst.STATE_NULL)
+ self._player.set_state(Gst.State.NULL)
elif self._playing == None:
return
else:
_logger.debug('continue audio')
- self._player.set_state(gst.STATE_PLAYING)
+ self._player.set_state(Gst.State.PLAYING)
self._playing = True
def pause(self):
if self._playing != None:
_logger.debug('pause audio')
- self._player.set_state(gst.STATE_PAUSED)
+ self._player.set_state(Gst.State.PAUSED)
self._playing = False
def stop(self):
- self._player.set_state(gst.STATE_NULL)
+ self._player.set_state(Gst.State.NULL)
def _gstmessage_cb(self, bus, message):
message_type = message.type
- if message_type in (gst.MESSAGE_EOS, gst.MESSAGE_ERROR):
- self._player.set_state(gst.STATE_NULL)
+ if message_type in (Gst.MessageType.EOS, Gst.MessageType.ERROR):
+ self._player.set_state(Gst.State.NULL)
self._playing = None
_logger.debug('audio stoped with type %d' % message_type)
diff --git a/cardlist.py b/cardlist.py
index e645264..c516f80 100644
--- a/cardlist.py
+++ b/cardlist.py
@@ -152,8 +152,7 @@ class CardList(Gtk.EventBox):
else:
aimgfile = 'aimg' + str(pair) + '.jpg'
pair_card.set_property('aimg', aimgfile)
- aimg.save(join(temp_img_folder, aimgfile), 'jpeg',
- {'quality': '85'})
+ aimg.savev(join(temp_img_folder, aimgfile), 'jpeg', [], [])
# bimg
bimg = self.pairs[pair].get_pixbuf(2)
if bimg != None:
@@ -162,8 +161,7 @@ class CardList(Gtk.EventBox):
else:
bimgfile = 'bimg' + str(pair) + '.jpg'
pair_card.set_property('bimg', bimgfile)
- bimg.save(join(temp_img_folder, bimgfile), 'jpeg',
- {'quality': '85'})
+ bimg.savev(join(temp_img_folder, bimgfile), 'jpeg', [], [])
# asnd
asnd = self.pairs[pair].get_sound(1)
@@ -310,7 +308,7 @@ class CardPair(Gtk.EventBox):
style.STANDARD_ICON_SIZE)
align = Gtk.Alignment.new(.5, 0, 0, 0)
align.add(close_button)
- row.pack_start(align, False)
+ row.pack_start(align, False, False, 0)
self.connect('button-press-event', self.emit_selected)
self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.bg_color))
diff --git a/cardtable.py b/cardtable.py
index 141cb18..5810e26 100644
--- a/cardtable.py
+++ b/cardtable.py
@@ -1,4 +1,5 @@
# Copyright (C) 2006, 2007, 2008 One Laptop Per Child
+# Copyright (C) 2013 Ignacio Rodriguez
#
# 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
@@ -73,6 +74,12 @@ class CardTable(Gtk.EventBox):
def _allocate_cb(self, widget, allocation):
size = allocation.height
+ width = allocation.width
+
+ if size < 0:
+ size = abs(size)
+ if width < 0:
+ size = abs(width)
if size == 100:
# skip first time sizing
diff --git a/createcardpanel.py b/createcardpanel.py
index c2e04fa..1bea357 100644
--- a/createcardpanel.py
+++ b/createcardpanel.py
@@ -200,10 +200,10 @@ class CreateCardPanel(Gtk.EventBox):
self.clean(None)
if self.equal_pairs:
- if self.cardeditor2.parent:
+ if self.cardeditor2.get_parent():
self.card_box.remove(self.cardeditor2)
else:
- if not self.cardeditor2.parent:
+ if not self.cardeditor2.get_parent():
self.card_box.pack_start(self.cardeditor2, True, True, 0)
def clean(self, widget):
diff --git a/createtoolbar.py b/createtoolbar.py
index 78d1ba8..b22c945 100644
--- a/createtoolbar.py
+++ b/createtoolbar.py
@@ -99,11 +99,11 @@ class CreateToolbarBuilder(GObject.GObject):
def _emit_equal_pairs(self, widget):
if self._equal_pairs.get_active():
- self._equal_pairs.set_named_icon('pair-equals')
+ self._equal_pairs.set_icon_name('pair-equals')
self._equal_pairs.set_tooltip(_('Match identical tiles'))
self.activity.game.model.data['equal_pairs'] = '1'
else:
- self._equal_pairs.set_named_icon('pair-non-equals')
+ self._equal_pairs.set_icon_name('pair-non-equals')
self._equal_pairs.set_tooltip(_('Match different tiles'))
self.activity.game.model.data['equal_pairs'] = '0'
self.emit('create_equal_pairs', self._equal_pairs.get_active())
@@ -112,11 +112,11 @@ class CreateToolbarBuilder(GObject.GObject):
def _grouped_cb(self, widget):
if self._grouped.get_active():
- self._grouped.set_named_icon('grouped_game2')
+ self._grouped.set_icon_name('grouped_game2')
self._grouped.set_tooltip(_('Grouped tiles game'))
self.activity.game.model.data['divided'] = '1'
else:
- self._grouped.set_named_icon('grouped_game1')
+ self._grouped.set_icon_name('grouped_game1')
self._grouped.set_tooltip(_('Mixed tiles game'))
self.activity.game.model.data['divided'] = '0'
logging.debug('createtoolbar._grouped_cb')
diff --git a/face.py b/face.py
index ffbc2a1..e82edcd 100644
--- a/face.py
+++ b/face.py
@@ -44,7 +44,7 @@ class Face(Gtk.EventBox):
self.face.shut_up()
def __draw_cb(self, widget, context):
- card = self.parent.parent
+ card = self.get_parent().get_parent()
pixbuf = card._read_icon_data('front')
Gdk.cairo_set_source_pixbuf(context, pixbuf, 0, 0)
context.paint()
@@ -58,7 +58,7 @@ def look_at():
screen_, x, y, modifiers_ = display.get_pointer()
for i in _cache:
- if i.parent:
+ if i.get_parent():
i.face.look_at(x, y)
@@ -70,7 +70,7 @@ def acquire():
for i in _cache:
i.face.shut_up()
- if not i.parent:
+ if not i.get_parent():
face = i
if not face:
diff --git a/game.py b/game.py
index 4ea725c..a596652 100644
--- a/game.py
+++ b/game.py
@@ -170,7 +170,7 @@ class MemorizeGame(GObject.GObject):
def card_flipped(self, widget, identifier, signal=False):
self.model.count = self.model.count + 1
if self._flop_cards:
- source_remove(self._flop_card_timeout)
+ GObject.source_remove(self._flop_card_timeout)
self.flop_card(self._flop_cards[0], self._flop_cards[1])
# Check if is my turn
@@ -245,7 +245,7 @@ class MemorizeGame(GObject.GObject):
self.model.grid[identifier]['state'] = '1'
self.set_sensitive(False)
self._flop_cards = (identifier, self.last_flipped)
- self._flop_card_timeout = timeout_add(theme.FLOP_BACK_TIMEOUT,
+ self._flop_card_timeout = GObject.timeout_add(theme.FLOP_BACK_TIMEOUT,
self.flop_card, identifier, self.last_flipped)
self.last_flipped = -1
diff --git a/port/roundbox.py b/port/roundbox.py
index 7dd0051..8ebc569 100644
--- a/port/roundbox.py
+++ b/port/roundbox.py
@@ -30,9 +30,7 @@ class RoundBox(Gtk.HBox):
self._width = allocation.width
self._height = allocation.height
- def __draw_cb(self, widget, context):
- cr = widget.window.cairo_create()
- #cr.save()
+ def __draw_cb(self, widget, cr):
x = self._x + self._BORDER_DEFAULT / 2
y = self._y + self._BORDER_DEFAULT / 2
width = self._width - self._BORDER_DEFAULT
diff --git a/speak/espeak.py b/speak/espeak.py
index 2a03afe..08b9711 100644
--- a/speak/espeak.py
+++ b/speak/espeak.py
@@ -12,7 +12,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import gst
+from gi.repository import Gst
from gi.repository import GObject
import subprocess
@@ -34,14 +34,14 @@ class BaseAudioGrab(GObject.GObject):
def restart_sound_device(self):
self.quiet = False
- self.pipeline.set_state(gst.STATE_NULL)
- self.pipeline.set_state(gst.STATE_PLAYING)
+ self.pipeline.set_state(Gst.State.NULL)
+ self.pipeline.set_state(Gst.State.PLAYING)
def stop_sound_device(self):
if self.pipeline is None:
return
- self.pipeline.set_state(gst.STATE_NULL)
+ self.pipeline.set_state(Gst.State.NULL)
# Shut theirs mouths down
self._new_buffer('')
@@ -55,7 +55,7 @@ class BaseAudioGrab(GObject.GObject):
# build a pipeline that reads the given file
# and sends it to both the real audio output
# and a fake one that we use to draw from
- self.pipeline = gst.parse_launch(
+ self.pipeline = Gst.parse_launch(
cmd + ' ' \
'! decodebin ' \
'! tee name=tee ' \
@@ -76,7 +76,7 @@ class BaseAudioGrab(GObject.GObject):
def gstmessage_cb(bus, message):
self._was_message = True
- if message.type == gst.MESSAGE_WARNING:
+ if message.type == Gst.MessageType.WARNING:
def check_after_warnings():
if not self._was_message:
self.stop_sound_device()
@@ -86,7 +86,7 @@ class BaseAudioGrab(GObject.GObject):
self._was_message = False
GObject.timeout_add(500, self._new_buffer, str(buffer))
- elif message.type in (gst.MESSAGE_EOS, gst.MESSAGE_ERROR):
+ elif message.type in (Gst.MessageType.EOS, Gst.MessageType.ERROR):
logger.debug(message.type)
self.stop_sound_device()
@@ -103,8 +103,9 @@ class BaseAudioGrab(GObject.GObject):
# load proper espeak plugin
try:
- import gst
- gst.element_factory_make('espeak')
+ from gi.repository import Gst
+ Gst.init([])
+ Gst.ElementFactory.make('espeak')
from espeak_gst import AudioGrabGst as AudioGrab
from espeak_gst import *
logger.info('use gst-plugins-espeak')
diff --git a/speak/espeak_gst.py b/speak/espeak_gst.py
index 85cfa26..565ebab 100644
--- a/speak/espeak_gst.py
+++ b/speak/espeak_gst.py
@@ -15,7 +15,7 @@
import logging
logger = logging.getLogger('speak')
-import gst
+from gi.repository import Gst
import espeak
PITCH_MAX = 200
@@ -44,7 +44,7 @@ class AudioGrabGst(espeak.BaseAudioGrab):
def voices():
out = []
- for i in gst.element_factory_make('espeak').props.voices:
+ for i in Gst.ElementFactory.make('espeak').props.voices:
name, language, dialect = i
if name in ('en-rhotic','english_rp','english_wmids'):
# these voices don't produce sound
diff --git a/speak/eye.py b/speak/eye.py
index 426c2f1..110eca2 100644
--- a/speak/eye.py
+++ b/speak/eye.py
@@ -32,92 +32,26 @@ from gi.repository import GObject
class Eye(Gtk.DrawingArea):
def __init__(self, fill_color):
Gtk.DrawingArea.__init__(self)
-
- self.connect("draw", self.__draw_cb)
self.frame = 0
- self.blink = False
self.x, self.y = 0,0
self.fill_color = fill_color
- # listen for clicks
- self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
- self.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
- self.connect("button_press_event", self._mouse_pressed_cb)
- self.connect("button_release_event", self._mouse_released_cb)
-
- # Instead of listening for mouse move events we could poll to see if the mouse has moved
- # would let us react to the mouse even when it isn't directly over this widget.
- # Unfortunately that would cause a lot of CPU usage. So instead we rely on our parent to
- # tell us to redraw when the mouse has moved. We still need to call add_events so that
- # our parent will get mouse motion events, but we don't connect the callback for them ourselves.
- self.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
- # self.connect("motion_notify_event", self._mouse_moved_cb)
-
- def _mouse_moved_cb(self, widget, event):
- self.queue_draw()
-
- def _mouse_pressed_cb(self, widget, event):
- self.blink = True
- self.queue_draw()
-
- def _mouse_released_cb(self, widget, event):
- self.blink = False
- self.queue_draw()
-
- def look_at(self, x, y):
- self.x = x
- self.y = y
- self.queue_draw()
-
- def look_ahead(self):
- self.x = None
- self.y = None
- self.queue_draw()
-
- # Thanks to xeyes :)
- def computePupil(self):
- a = self.get_allocation()
-
- 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:
- 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)
- EYE_HWIDTH = a.width
- EYE_HHEIGHT = a.height
- BALL_DIST = EYE_HWIDTH/4
-
- dx = self.x - EYE_X
- dy = self.y - EYE_Y
-
- if dx or dy:
- angle = math.atan2(dy, dx)
- cosa = math.cos(angle)
- sina = math.sin(angle)
- h = math.hypot(EYE_HHEIGHT * cosa, EYE_HWIDTH * sina)
- x = (EYE_HWIDTH * EYE_HHEIGHT) * cosa / h
- y = (EYE_HWIDTH * EYE_HHEIGHT) * sina / h
- dist = BALL_DIST * math.hypot(x, y)
- if dist < math.hypot(dx, dy):
- dx = dist * cosa
- dy = dist * sina
-
- return a.width/2 + dx, a.height/2 + dy
-
- def __draw_cb(self, widget, context):
+ def do_draw(self, context):
self.frame += 1
bounds = self.get_allocation()
+ self.context = context
+ self.context.set_antialias(cairo.ANTIALIAS_NONE)
+
+ self.draw_eye(bounds)
+ return True
+
+ def draw_eye(self, bounds):
eyeSize = min(bounds.width, bounds.height)
outlineWidth = eyeSize/20.0
pupilSize = eyeSize/10.0
- pupilX, pupilY = self.computePupil()
+ pupilX, pupilY = ((eyeSize / 2) + pupilSize * 2, eyeSize / 2)
dX = pupilX - bounds.width/2.
dY = pupilY - bounds.height/2.
distance = math.sqrt(dX*dX + dY*dY)
@@ -126,19 +60,7 @@ class Eye(Gtk.DrawingArea):
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)
-
- #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.clip()
- # background
- self.context.set_source_rgba(*self.fill_color.get_rgba())
- 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.fill()
@@ -152,8 +74,4 @@ class Eye(Gtk.DrawingArea):
# pupil
self.context.arc(pupilX,pupilY,pupilSize,0,360)
self.context.set_source_rgb(0,0,0)
- self.context.fill()
-
- self.blink = False
-
- return True
+ self.context.fill() \ No newline at end of file
diff --git a/speak/face.py b/speak/face.py
index ded1307..c8185df 100644
--- a/speak/face.py
+++ b/speak/face.py
@@ -135,11 +135,13 @@ class View(Gtk.EventBox):
def look_ahead(self):
if self._eyes:
- map(lambda e: e.look_ahead(), self._eyes)
+ #map(lambda e: e.look_ahead(), self._eyes)
+ return
def look_at(self, x, y):
if self._eyes:
- map(lambda e, x=x, y=y: e.look_at(x,y), self._eyes)
+ #map(lambda e, x=x, y=y: e.look_at(x,y), self._eyes)
+ return
def update(self, status = None):
if not status:
diff --git a/speak/mouth.py b/speak/mouth.py
index cfda012..e5f22a4 100644
--- a/speak/mouth.py
+++ b/speak/mouth.py
@@ -69,17 +69,17 @@ class Mouth(Gtk.DrawingArea):
self.processBuffer(bounds)
#Create context, disable antialiasing
- self.context = widget.window.cairo_create()
+ 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(event.area.x, event.area.y,event.area.width, event.area.height)
- self.context.clip()
+ #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()
+ #self.context.set_source_rgba(*self.fill_color.get_rgba())
+ #self.context.rectangle(0,0, bounds.width,bounds.height)
+ #self.context.fill()
# Draw the mouth
volume = self.volume / 65535.
@@ -96,8 +96,9 @@ class Mouth(Gtk.DrawingArea):
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.set_source_rgb(0, 0, 0)
self.context.close_path()
self.context.stroke()
+ self.context.fill()
return True
diff --git a/svgcard.py b/svgcard.py
index 942e78f..f9ff574 100644
--- a/svgcard.py
+++ b/svgcard.py
@@ -1,4 +1,5 @@
# Copyright (C) 2007, 2008 One Laptop Per Child
+# Copyright (C) 2013, Ignacio Rodriguez
#
# Muriel de Souza Godoi - muriel@laptop.org
#
@@ -26,6 +27,7 @@ from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
from gi.repository import Pango
+from gi.repository import PangoCairo
from sugar3.util import LRU
@@ -105,10 +107,8 @@ class SvgCard(Gtk.EventBox):
self.add(self.workspace)
self.show_all()
- #gc.collect()
-
def _realize_cb(self, widget):
- self.gc = widget.window.new_gc()
+ self.gc = self.get_window().cairo_create()
def __draw_cb(self, widget, context):
pixbuf = self._read_icon_data(self.current_face)
@@ -116,10 +116,9 @@ class SvgCard(Gtk.EventBox):
context.paint()
if self.show_jpeg:
- print 'draw'
- Gdk.cairo_set_source_pixbuf(context, self.jpeg, 0, 0)
+ Gdk.cairo_set_source_pixbuf(context, self.jpeg,
+ theme.SVG_PAD, theme.SVG_PAD)
context.paint()
- # FIXME theme.SVG_PAD, theme.SVG_PAD)
if self.show_text:
props = self.props[self.flipped and 'front_text' or 'back_text']
@@ -137,9 +136,13 @@ class SvgCard(Gtk.EventBox):
elif self.align == '3': # bottom
y = self.size - height
- widget.window.draw_layout(self.gc, layout=layout,
- x=(self.size - width) / 2, y=y,
- foreground=Gdk.color_parse(props['text_color']))
+ x = (self.size - width) / 2
+ context.set_source_rgb(1, 1, 1)
+ context.translate(x, y)
+ PangoCairo.update_layout(context, layout)
+ PangoCairo.show_layout(context, layout)
+ context.fill()
+
return False