From 1315986303a98f0f93087c8c36af1886c86e4d1c Mon Sep 17 00:00:00 2001 From: Kshitij Date: Tue, 25 Dec 2012 14:23:06 +0000 Subject: PyGI changes --- diff --git a/activity.py b/activity.py index 3190496..8fc96df 100755 --- a/activity.py +++ b/activity.py @@ -3,7 +3,7 @@ import logging import olpcgames import pygame -import gtk +from gi.repository import Gtk from olpcgames import mesh from olpcgames import util diff --git a/olpcgames/_gtkmain.py b/olpcgames/_gtkmain.py index 33a6a83..1715aef 100644 --- a/olpcgames/_gtkmain.py +++ b/olpcgames/_gtkmain.py @@ -30,7 +30,7 @@ class _TrackLoop( object ): self.count -= 1 def loop( self ): """Little thread loop that replicates the gtk mainloop""" - import gtk + from gi.repository import Gtk while self.count >= 1: log.debug( 'GTK loop restarting' ) while gtk.events_pending(): diff --git a/olpcgames/activity.py b/olpcgames/activity.py index 1304551..3667d32 100644 --- a/olpcgames/activity.py +++ b/olpcgames/activity.py @@ -27,9 +27,9 @@ logging.root.setLevel( logging.WARN ) log = logging.getLogger( 'olpcgames.activity' ) ##log.setLevel( logging.DEBUG ) -import pygtk -pygtk.require('2.0') -import gtk +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk import gtk.gdk import os @@ -172,9 +172,9 @@ class PygameActivity(activity.Activity): gtk.gdk.threads_init() return self._pgc else: - import hippo + from gi.repository import Hippo self._drawarea = gtk.DrawingArea() - canvas = hippo.Canvas() + canvas = Hippo.Canvas() canvas.grab_focus() self.set_canvas(canvas) self.show_all() diff --git a/olpcgames/canvas.py b/olpcgames/canvas.py index 588682c..a5a5a89 100644 --- a/olpcgames/canvas.py +++ b/olpcgames/canvas.py @@ -7,10 +7,10 @@ log = logging.getLogger( 'olpcgames.canvas' ) 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 GObject import pygame from olpcgames import gtkEvent, util diff --git a/olpcgames/eventwrap.py b/olpcgames/eventwrap.py index 402109c..24baab6 100644 --- a/olpcgames/eventwrap.py +++ b/olpcgames/eventwrap.py @@ -19,7 +19,7 @@ Extensions: release a few more resources, then a bit more... """ import pygame -import gtk +from gi.repository import Gtk import Queue import thread, threading import logging diff --git a/olpcgames/gtkEvent.py b/olpcgames/gtkEvent.py index 6b20102..aad1098 100644 --- a/olpcgames/gtkEvent.py +++ b/olpcgames/gtkEvent.py @@ -1,8 +1,8 @@ """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 GObject import pygame from olpcgames import eventwrap import logging @@ -233,7 +233,7 @@ class Translator(object): else: x = event.x y = event.y - state = event.state + state = event.get_state() rel = (x - self.__mouse_pos[0], y - self.__mouse_pos[1]) diff --git a/olpcgames/pangofont.py b/olpcgames/pangofont.py index 441dfd1..c56c0f7 100644 --- a/olpcgames/pangofont.py +++ b/olpcgames/pangofont.py @@ -43,11 +43,11 @@ Note: PangoFont -- is the Pango-specific rendering engine which allows for the more involved cross-lingual rendering operations. """ -import pango +from gi.repository import Pango import logging import pangocairo import pygame.rect, pygame.image -import gtk +from gi.repository import Gtk import struct from pygame import surface from pygame.font import Font @@ -76,25 +76,25 @@ class PangoFont(object): STYLE_* -- parameters for use with set_style """ - WEIGHT_BOLD = pango.WEIGHT_BOLD - WEIGHT_HEAVY = pango.WEIGHT_HEAVY - WEIGHT_LIGHT = pango.WEIGHT_LIGHT - WEIGHT_NORMAL = pango.WEIGHT_NORMAL - WEIGHT_SEMIBOLD = pango.WEIGHT_SEMIBOLD - WEIGHT_ULTRABOLD = pango.WEIGHT_ULTRABOLD - WEIGHT_ULTRALIGHT = pango.WEIGHT_ULTRALIGHT - STYLE_NORMAL = pango.STYLE_NORMAL - STYLE_ITALIC = pango.STYLE_ITALIC - STYLE_OBLIQUE = pango.STYLE_OBLIQUE + WEIGHT_BOLD = Pango.Weight.BOLD + WEIGHT_HEAVY = Pango.Weight.HEAVY + WEIGHT_LIGHT = Pango.Weight.LIGHT + WEIGHT_NORMAL = Pango.Weight.NORMAL + WEIGHT_SEMIBOLD = Pango.Weight.SEMIBOLD + WEIGHT_ULTRABOLD = Pango.Weight.ULTRABOLD + WEIGHT_ULTRALIGHT = Pango.Weight.ULTRALIGHT + STYLE_NORMAL = Pango.Style.NORMAL + STYLE_ITALIC = Pango.Style.ITALIC + STYLE_OBLIQUE = Pango.Style.OBLIQUE def __init__(self, family=None, size=None, bold=False, italic=False, underline=False, fd=None): - """If you know what pango.FontDescription (fd) you want, pass it in as + """If you know what Pango.FontDescription (fd) you want, pass it in as 'fd'. Otherwise, specify any number of family, size, bold, or italic, and we will try to match something up for you.""" # Always set the FontDescription (FIXME - only set it if the user wants # to change something?) if fd is None: - fd = pango.FontDescription() + fd = Pango.FontDescription() if family is not None: fd.set_family(family) if size is not None: @@ -173,7 +173,7 @@ class PangoFont(object): return self.fd.get_weight() def get_bold( self ): """Return whether our font's weight is bold (or above)""" - return self.fd.get_weight() >= pango.WEIGHT_BOLD + return self.fd.get_weight() >= Pango.Weight.BOLD def set_italic( self, italic=True ): """Set our "italic" value (style)""" @@ -202,13 +202,13 @@ class PangoFont(object): 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(gtk.gdk.pango_context_get()) layout.set_font_description(self.fd) if self.underline: attrs = layout.get_attributes() if not attrs: - attrs = pango.AttrList() - attrs.insert(pango.AttrUnderline(pango.UNDERLINE_SINGLE, 0, 32767)) + attrs = Pango.AttrList() + attrs.insert(Pango.AttrUnderline(Pango.Underline.SINGLE, 0, 32767)) layout.set_attributes( attrs ) layout.set_text(text) return layout @@ -227,7 +227,7 @@ class PangoFont(object): ## """Determine inter-line spacing for the font""" ## font = self.get_context().load_font( self.fd ) ## metrics = font.get_metrics() -## return pango.PIXELS( metrics.get_ascent() ) +## return Pango.PIXELS( metrics.get_ascent() ) ## def get_height( self ): ## def get_ascent( self ): ## def get_descent( self ): @@ -237,12 +237,12 @@ class SysFont(PangoFont): """Construct a PangoFont from a font description (name), size in pixels, bold, and italic designation. Similar to SysFont from Pygame.""" def __init__(self, name, size, bold=False, italic=False): - fd = pango.FontDescription(name) - fd.set_absolute_size(size*pango.SCALE) + fd = Pango.FontDescription(name) + fd.set_absolute_size(size*Pango.SCALE) if bold: - fd.set_weight(pango.WEIGHT_BOLD) + fd.set_weight(Pango.Weight.BOLD) if italic: - fd.set_style(pango.STYLE_OBLIQUE) + fd.set_style(Pango.Style.OBLIQUE) super(SysFont, self).__init__(fd=fd) # originally defined a new class, no reason for that... @@ -256,7 +256,7 @@ def fontByDesc(desc="",bold=False,italic=False): """Constructs a FontDescription from the given string representation. The format of the fontByDesc string representation is passed directly -to the pango.FontDescription constructor and documented at: +to the Pango.FontDescription constructor and documented at: http://www.pygtk.org/docs/pygtk/class-pangofontdescription.html#constructor-pangofontdescription @@ -300,11 +300,11 @@ Expanded Extra-Expanded Ultra-Expanded the widest width """ - fd = pango.FontDescription(name) + fd = Pango.FontDescription(name) if bold: - fd.set_weight(pango.WEIGHT_BOLD) + fd.set_weight(Pango.Weight.BOLD) if italic: - fd.set_style(pango.STYLE_OBLIQUE) + fd.set_style(Pango.Style.OBLIQUE) return PangoFont(fd=fd) def get_init(): diff --git a/olpcgames/video.py b/olpcgames/video.py index 032aa13..5aa5cc8 100644 --- a/olpcgames/video.py +++ b/olpcgames/video.py @@ -14,9 +14,9 @@ import weakref import olpcgames from olpcgames import _gtkmain -import pygtk -pygtk.require('2.0') -import gtk +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk import gst class VideoWidget(gtk.DrawingArea): -- cgit v0.9.1