[pygobject] Fix pygtkcompat.py to work with Python 3
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix pygtkcompat.py to work with Python 3
- Date: Mon, 19 Mar 2012 14:54:27 +0000 (UTC)
commit 1f18bcb37bdc42368ad9a07c7f348f736c2f665d
Author: Martin Pitt <martin pitt ubuntu com>
Date: Mon Mar 19 15:54:13 2012 +0100
Fix pygtkcompat.py to work with Python 3
gi/pygtkcompat.py | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/gi/pygtkcompat.py b/gi/pygtkcompat.py
index 6791bec..26f803a 100644
--- a/gi/pygtkcompat.py
+++ b/gi/pygtkcompat.py
@@ -34,7 +34,14 @@ a well behaved PyGTK application mostly unmodified on top of PyGI.
import sys
import warnings
-import UserList
+
+try:
+ # Python 3
+ from collections import UserList
+ from imp import reload
+except ImportError:
+ # Python 2 ships that in a different module
+ from UserList import UserList
import gi
from gi.repository import GObject
@@ -90,7 +97,8 @@ _unset = object()
def enable_gtk(version='2.0'):
# set the default encoding like PyGTK
reload(sys)
- sys.setdefaultencoding('utf-8')
+ if sys.version_info < (3,0):
+ sys.setdefaultencoding('utf-8')
# atk
gi.require_version('Atk', '1.0')
@@ -160,7 +168,8 @@ def enable_gtk(version='2.0'):
# Action
def set_tool_item_type(menuaction, gtype):
- print 'set_tool_item_type is not supported'
+ warnings.warn('set_tool_item_type() is not supported',
+ DeprecationWarning, stacklevel=2)
Gtk.Action.set_tool_item_type = classmethod(set_tool_item_type)
# Alignment
@@ -254,7 +263,8 @@ def enable_gtk(version='2.0'):
# Container
def install_child_property(container, flag, pspec):
- print 'install_child_property is not supported'
+ warnings.warn('install_child_property() is not supported',
+ DeprecationWarning, stacklevel=2)
Gtk.Container.install_child_property = classmethod(install_child_property)
def new_text():
@@ -297,7 +307,7 @@ def enable_gtk(version='2.0'):
Gtk.widget_get_default_direction = Gtk.Widget.get_default_direction
orig_size_request = Gtk.Widget.size_request
def size_request(widget):
- class SizeRequest(UserList.UserList):
+ class SizeRequest(UserList):
def __init__(self, req):
self.height = req.height
self.width = req.width
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]