@@ -7,17 +7,18 @@
import threading
from pprint import pprint

import pygtk
pygtk.require('2.0')
import gtk
import gobject
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
import pygame

from olpcgames import gtkEvent, util

__all__ = ['PygameCanvas']

class PygameCanvas(gtk.Layout):
class PygameCanvas(Gtk.Layout):
"""Canvas providing bridge methods to run Pygame in GTK
The PygameCanvas creates a secondary thread in which the Pygame instance will
@@ -40,12 +41,12 @@ def __init__(self, width, height):
# Build the main widget
log.info( 'Creating the pygame canvas' )
super(PygameCanvas,self).__init__()
self.set_flags(gtk.CAN_FOCUS)
self.set_can_focus(True)

# Build the sub-widgets
self._align = gtk.Alignment(0.5, 0.5)
self._inner_evb = gtk.EventBox()
self._socket = gtk.Socket()
self._align = Gtk.Alignment.new(0.5, 0.5, 0.0, 0.0)
self._inner_evb = Gtk.EventBox()
self._socket = Gtk.Socket()


# Add internal widgets
@@ -106,12 +107,12 @@ def _start(self, fn):
import olpcgames
olpcgames.widget = olpcgames.WIDGET = self
try:
import sugar.activity.activity,os
import sugar3.activity.activity,os
except ImportError, err:
log.info( """Running outside Sugar""" )
else:
try:
os.chdir(sugar.activity.activity.get_bundle_path())
os.chdir(sugar3.activity.activity.get_bundle_path())
except KeyError, err:
pass

@@ -134,16 +135,16 @@ def _start(self, fn):
eventwrap.clear()
finally:
log.info( 'Main function finished, calling main_quit' )
gtk.main_quit()
Gtk.main_quit()

source_object_id = None
def view_source(self):
"""Implement the 'view source' key by saving
datastore, and then telling the Journal to view it."""
if self.source_object_id is None:
from sugar import profile
from sugar.datastore import datastore
from sugar.activity.activity import get_bundle_name, get_bundle_path
from sugar3 import profile
from sugar3.datastore import datastore
from sugar3.activity.activity import get_bundle_name, get_bundle_path
from gettext import gettext as _
import os.path
jobject = datastore.create()
@@ -165,7 +166,7 @@ def journal_show_object(self, object_id):
"""Invoke journal_show_object from sugar.activity.activity if it
exists."""
try:
from sugar.activity.activity import show_object_in_journal
from sugar3.activity.activity import show_object_in_journal
show_object_in_journal(object_id)
except ImportError:
pass # no love from sugar.
BIN -6.53 KB olpcgames/canvas.pyc
Binary file not shown.

This file was deleted.

@@ -19,7 +19,7 @@
release a few more resources, then a bit more...
"""
import pygame
import gtk
from gi.repository import Gtk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the import needed? I see no reference to it in the file.

import Queue
import thread, threading
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see an import of Gtk and of threading. That GTK+ 3 does not support threading very well is one of the main reasons we ported from olpcgames to sugargame. Don't forget to test this on a multiprocessor system under load. Consider completing the port to sugargame.

import logging
Binary file not shown.
@@ -1,8 +1,9 @@
"""gtkEvent.py: translate GTK events into Pygame events."""
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
import pygame
from olpcgames import eventwrap
import logging
@@ -62,16 +63,17 @@ def __init__(self, mainwindow, mouselistener=None):

# Need to set our X event masks so we see mouse motion and stuff --
mainwindow.set_events(
gtk.gdk.KEY_PRESS_MASK | \
gtk.gdk.KEY_RELEASE_MASK \
Gdk.EventMask.KEY_PRESS_MASK | \
Gdk.EventMask.KEY_RELEASE_MASK | \
Gdk.EventMask.VISIBILITY_NOTIFY_MASK
)

self._inner_evb.set_events(
gtk.gdk.POINTER_MOTION_MASK | \
gtk.gdk.POINTER_MOTION_HINT_MASK | \
gtk.gdk.BUTTON_MOTION_MASK | \
gtk.gdk.BUTTON_PRESS_MASK | \
gtk.gdk.BUTTON_RELEASE_MASK
Gdk.EventMask.POINTER_MOTION_MASK | \
Gdk.EventMask.POINTER_MOTION_HINT_MASK | \
Gdk.EventMask.BUTTON_MOTION_MASK | \
Gdk.EventMask.BUTTON_PRESS_MASK | \
Gdk.EventMask.BUTTON_RELEASE_MASK
)

# Callback functions to link the event systems
@@ -83,8 +85,8 @@ def __init__(self, mainwindow, mouselistener=None):
self._inner_evb.connect('motion-notify-event', self._mousemove)

# You might need to do this
mainwindow.set_flags(gtk.CAN_FOCUS)
self._inner_evb.set_flags(gtk.CAN_FOCUS)
mainwindow.set_can_focus(True)
self._inner_evb.set_can_focus(True)

# Internal data
self.__stopped = False
@@ -98,7 +100,7 @@ def __init__(self, mainwindow, mouselistener=None):
self.__tick_id = None

#print "translator initialized"
self._inner_evb.connect( 'expose-event', self.do_expose_event )
self._inner_evb.connect( 'draw', self.do_expose_event )
# screen = gtk.gdk.screen_get_default()
# screen.connect( 'size-changed', self.do_resize_event )
self._inner_evb.connect( 'configure-event', self.do_resize_event )
@@ -168,7 +170,7 @@ def _keymods(self):


def _keyevent(self, widget, event, type):
key = gtk.gdk.keyval_name(event.keyval)
key = Gdk.keyval_name(event.keyval)
if key is None:
# No idea what this key is.
return False
@@ -192,7 +194,7 @@ def _keyevent(self, widget, event, type):
self.__keystate[keycode] = type == pygame.KEYDOWN
if type == pygame.KEYUP:
mod = self._keymods()
ukey = unichr(gtk.gdk.keyval_to_unicode(event.keyval))
ukey = unichr(Gdk.keyval_to_unicode(event.keyval))
if ukey == '\000':
ukey = ''
evt = eventwrap.Event(type, key=keycode, unicode=ukey, mod=mod)
@@ -229,7 +231,7 @@ def _mousemove(self, widget, event):
# if this is a hint, then let's get all the necessary
# information, if not it's all we need.
if event.is_hint:
x, y, state = event.window.get_pointer()
win, x, y, state = event.window.get_device_position(event.device)
else:
x = event.x
y = event.y
@@ -240,9 +242,9 @@ def _mousemove(self, widget, event):
self.__mouse_pos = (x, y)

self.__button_state = [
state & gtk.gdk.BUTTON1_MASK and 1 or 0,
state & gtk.gdk.BUTTON2_MASK and 1 or 0,
state & gtk.gdk.BUTTON3_MASK and 1 or 0,
state & Gdk.ModifierType.BUTTON1_MASK and 1 or 0,
state & Gdk.ModifierType.BUTTON2_MASK and 1 or 0,
state & Gdk.ModifierType.BUTTON3_MASK and 1 or 0,
]

evt = eventwrap.Event(pygame.MOUSEMOTION,
BIN -11.1 KB olpcgames/gtkEvent.pyc
Binary file not shown.
@@ -121,7 +121,7 @@
import olpcgames
from olpcgames.util import get_traceback
try:
from sugar.presence.tubeconn import TubeConnection
from sugar3.presence.tubeconn import TubeConnection
except ImportError, err:
TubeConnection = object
try:
@@ -136,7 +136,7 @@
telepathy = None

try:
import sugar.presence.presenceservice
import sugar3.presence.presenceservice
except Exception, err:
pass
import pygame.event as PEvent
@@ -416,7 +416,7 @@ def _get_presence_service( ):
log.debug( """About to import sugar.presence.presenceservice""" )
try:
log.debug( 'About to retrieve presence service instance' )
pservice = sugar.presence.presenceservice.get_instance()
pservice = sugar3.presence.presenceservice.get_instance()
try:
log.debug( ' Retrieved presence service instance: %s', pservice )
name, path = pservice.get_preferred_connection()
BIN -24 KB olpcgames/mesh.pyc
Binary file not shown.
@@ -47,7 +47,8 @@
import logging
import pangocairo
import pygame.rect, pygame.image
import gtk
from gi.repository import Gtk
from gi.repository import Gdk
import struct
from pygame import surface
from pygame.font import Font
@@ -202,7 +203,7 @@ def get_underline( self ):
def _createLayout( self, text ):
"""Produces a Pango layout describing this text in this font"""
# create layout
layout = pango.Layout(gtk.gdk.pango_context_get())
layout = pango.Layout(Gdk.pango_context_get())
layout.set_font_description(self.fd)
if self.underline:
attrs = layout.get_attributes()
@@ -8,7 +8,7 @@
NON_SUGAR_ROOT = '~/.sugar/default/olpcgames'

try:
from sugar.activity.activity import get_bundle_path as _get_bundle_path
from sugar3.activity.activity import get_bundle_path as _get_bundle_path
def get_bundle_path( ):
"""Retrieve bundle path from activity with fix for silly registration bug"""
path = _get_bundle_path()
BIN -3.49 KB olpcgames/util.pyc
Binary file not shown.
@@ -14,10 +14,13 @@
import olpcgames
from olpcgames import _gtkmain

import pygtk
pygtk.require('2.0')
import gtk
import gst
import gi
gi.require_version('Gtk', '3.0')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a duplicate. Please put all the necessary require_version calls in the main program?

from gi.repository import Gtk
from gi.repository import Gdk
gi.require_version('Gst', '1.0')
from gi.repository import Gst
Gst.init(None)

class VideoWidget(gtk.DrawingArea):
"""Widget to render GStreamer video over our Pygame Canvas
@@ -102,7 +105,7 @@ def __init__(self, videowidget, pipe_desc=pipe_desc):
self._playing = False
self._videowidget = videowidget

self._pipeline = gst.parse_launch(pipe_desc)
self._pipeline = Gst.parse_launch(pipe_desc)

bus = self._pipeline.get_bus()
bus.enable_sync_message_emission()
@@ -113,19 +116,19 @@ def __init__(self, videowidget, pipe_desc=pipe_desc):
def play(self):
log.info( 'Play' )
if self._playing == False:
self._pipeline.set_state(gst.STATE_PLAYING)
self._pipeline.set_state(Gst.State.PLAYING)
self._playing = True

def pause(self):
log.info( 'Pause' )
if self._playing == True:
if self._synchronized:
log.debug( ' pause already sync\'d' )
self._pipeline.set_state(gst.STATE_PAUSED)
self._pipeline.set_state(Gst.State.PAUSED)
self._playing = False
def stop( self ):
"""Stop all playback"""
self._pipeline.set_state( gst.STATE_NULL )
self._pipeline.set_state(Gst.State.NULL)

def on_sync_message(self, bus, message):
log.info( 'Sync: %s', message )
@@ -138,7 +141,7 @@ def on_sync_message(self, bus, message):
def on_message(self, bus, message):
log.info( 'Message: %s', message )
t = message.type
if t == gst.MESSAGE_ERROR:
if t == Gst.MessageType.ERROR:
err, debug = message.parse_error()
log.warn("Video error: (%s) %s" ,err, debug)
self._playing = False
@@ -1,4 +1,4 @@
#!/usr/bin/env python
from sugar.activity import bundlebuilder
from sugar3.activity import bundlebuilder
if __name__ == "__main__":
bundlebuilder.start("FoodForce2")