summaryrefslogtreecommitdiff
path: root/gi/overrides
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:49 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:52 +0900
commited14d55c2e6e867dceed5b50d601d4d83a838619 (patch)
tree5c86789730b159290064228379a48aa47781d52d /gi/overrides
parent265684897ba0b24e28710a988cab901acbec1775 (diff)
downloadpygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.tar.gz
pygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.tar.bz2
pygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.zip
Imported Upstream version 3.7.91.1
Change-Id: I3dcc605b8af37b73443f8f89d884b7b9659959c8 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi/overrides')
-rw-r--r--gi/overrides/GLib.py4
-rw-r--r--gi/overrides/GObject.py256
-rw-r--r--gi/overrides/Gdk.py28
-rw-r--r--gi/overrides/Gtk.py157
-rw-r--r--gi/overrides/Makefile.in6
-rw-r--r--gi/overrides/__init__.py22
6 files changed, 236 insertions, 237 deletions
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index b3f1563..3e660d1 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -539,6 +539,10 @@ class Source(GLib.Source):
setattr(source, '__pygi_custom_source', True)
return source
+ def __del__(self):
+ if hasattr(self, '__pygi_custom_source'):
+ self.unref()
+
# Backwards compatible API for optional arguments
def attach(self, context=None):
id = super(Source, self).attach(context)
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 2176d84..eea8928 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -3,7 +3,7 @@
#
# Copyright (C) 2012 Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
-# Copyright (C) 2012 Simon Feltman <sfeltman@src.gnome.org>
+# Copyright (C) 2012-2013 Simon Feltman <sfeltman@src.gnome.org>
# Copyright (C) 2012 Bastian Winkler <buz@netbuz.org>
#
# This library is free software; you can redistribute it and/or
@@ -23,6 +23,7 @@
import sys
import warnings
+import functools
from collections import namedtuple
import gi.overrides
@@ -193,20 +194,14 @@ __all__ += ['GBoxed', 'GEnum', 'GFlags', 'GInterface', 'GObject',
'Warning']
-add_emission_hook = _gobject.add_emission_hook
features = _gobject.features
list_properties = _gobject.list_properties
new = _gobject.new
pygobject_version = _gobject.pygobject_version
-remove_emission_hook = _gobject.remove_emission_hook
-signal_accumulator_true_handled = _gobject.signal_accumulator_true_handled
-signal_new = _gobject.signal_new
threads_init = _gobject.threads_init
type_register = _gobject.type_register
-__all__ += ['add_emission_hook', 'features', 'list_properties',
- 'new', 'pygobject_version', 'remove_emission_hook',
- 'signal_accumulator_true_handled',
- 'signal_new', 'threads_init', 'type_register']
+__all__ += ['features', 'list_properties', 'new',
+ 'pygobject_version', 'threads_init', 'type_register']
class Value(GObjectModule.Value):
@@ -225,31 +220,33 @@ class Value(GObjectModule.Value):
self.unset()
def set_value(self, py_value):
- if self.g_type == _gobject.TYPE_INVALID:
+ gtype = self.g_type
+
+ if gtype == _gobject.TYPE_INVALID:
raise TypeError("GObject.Value needs to be initialized first")
- elif self.g_type == TYPE_BOOLEAN:
+ elif gtype == TYPE_BOOLEAN:
self.set_boolean(py_value)
- elif self.g_type == TYPE_CHAR:
+ elif gtype == TYPE_CHAR:
self.set_char(py_value)
- elif self.g_type == TYPE_UCHAR:
+ elif gtype == TYPE_UCHAR:
self.set_uchar(py_value)
- elif self.g_type == TYPE_INT:
+ elif gtype == TYPE_INT:
self.set_int(py_value)
- elif self.g_type == TYPE_UINT:
+ elif gtype == TYPE_UINT:
self.set_uint(py_value)
- elif self.g_type == TYPE_LONG:
+ elif gtype == TYPE_LONG:
self.set_long(py_value)
- elif self.g_type == TYPE_ULONG:
+ elif gtype == TYPE_ULONG:
self.set_ulong(py_value)
- elif self.g_type == TYPE_INT64:
+ elif gtype == TYPE_INT64:
self.set_int64(py_value)
- elif self.g_type == TYPE_UINT64:
+ elif gtype == TYPE_UINT64:
self.set_uint64(py_value)
- elif self.g_type == TYPE_FLOAT:
+ elif gtype == TYPE_FLOAT:
self.set_float(py_value)
- elif self.g_type == TYPE_DOUBLE:
+ elif gtype == TYPE_DOUBLE:
self.set_double(py_value)
- elif self.g_type == TYPE_STRING:
+ elif gtype == TYPE_STRING:
if isinstance(py_value, str):
py_value = str(py_value)
elif sys.version_info < (3, 0):
@@ -262,75 +259,77 @@ class Value(GObjectModule.Value):
raise ValueError("Expected string but got %s%s" %
(py_value, type(py_value)))
self.set_string(py_value)
- elif self.g_type == TYPE_PARAM:
+ elif gtype == TYPE_PARAM:
self.set_param(py_value)
- elif self.g_type.is_a(TYPE_ENUM):
+ elif gtype.is_a(TYPE_ENUM):
self.set_enum(py_value)
- elif self.g_type.is_a(TYPE_FLAGS):
+ elif gtype.is_a(TYPE_FLAGS):
self.set_flags(py_value)
- elif self.g_type.is_a(TYPE_BOXED):
+ elif gtype.is_a(TYPE_BOXED):
self.set_boxed(py_value)
- elif self.g_type == TYPE_POINTER:
+ elif gtype == TYPE_POINTER:
self.set_pointer(py_value)
- elif self.g_type.is_a(TYPE_OBJECT):
+ elif gtype.is_a(TYPE_OBJECT):
self.set_object(py_value)
- elif self.g_type == TYPE_UNICHAR:
+ elif gtype == TYPE_UNICHAR:
self.set_uint(int(py_value))
- # elif self.g_type == TYPE_OVERRIDE:
+ # elif gtype == TYPE_OVERRIDE:
# pass
- elif self.g_type == TYPE_GTYPE:
+ elif gtype == TYPE_GTYPE:
self.set_gtype(py_value)
- elif self.g_type == TYPE_VARIANT:
+ elif gtype == TYPE_VARIANT:
self.set_variant(py_value)
- elif self.g_type == TYPE_PYOBJECT:
+ elif gtype == TYPE_PYOBJECT:
self.set_boxed(py_value)
else:
- raise TypeError("Unknown value type %s" % self.g_type)
+ raise TypeError("Unknown value type %s" % gtype)
def get_value(self):
- if self.g_type == TYPE_BOOLEAN:
+ gtype = self.g_type
+
+ if gtype == TYPE_BOOLEAN:
return self.get_boolean()
- elif self.g_type == TYPE_CHAR:
+ elif gtype == TYPE_CHAR:
return self.get_char()
- elif self.g_type == TYPE_UCHAR:
+ elif gtype == TYPE_UCHAR:
return self.get_uchar()
- elif self.g_type == TYPE_INT:
+ elif gtype == TYPE_INT:
return self.get_int()
- elif self.g_type == TYPE_UINT:
+ elif gtype == TYPE_UINT:
return self.get_uint()
- elif self.g_type == TYPE_LONG:
+ elif gtype == TYPE_LONG:
return self.get_long()
- elif self.g_type == TYPE_ULONG:
+ elif gtype == TYPE_ULONG:
return self.get_ulong()
- elif self.g_type == TYPE_INT64:
+ elif gtype == TYPE_INT64:
return self.get_int64()
- elif self.g_type == TYPE_UINT64:
+ elif gtype == TYPE_UINT64:
return self.get_uint64()
- elif self.g_type == TYPE_FLOAT:
+ elif gtype == TYPE_FLOAT:
return self.get_float()
- elif self.g_type == TYPE_DOUBLE:
+ elif gtype == TYPE_DOUBLE:
return self.get_double()
- elif self.g_type == TYPE_STRING:
+ elif gtype == TYPE_STRING:
return self.get_string()
- elif self.g_type == TYPE_PARAM:
+ elif gtype == TYPE_PARAM:
return self.get_param()
- elif self.g_type.is_a(TYPE_ENUM):
+ elif gtype.is_a(TYPE_ENUM):
return self.get_enum()
- elif self.g_type.is_a(TYPE_FLAGS):
+ elif gtype.is_a(TYPE_FLAGS):
return self.get_flags()
- elif self.g_type.is_a(TYPE_BOXED):
+ elif gtype.is_a(TYPE_BOXED):
return self.get_boxed()
- elif self.g_type == TYPE_POINTER:
+ elif gtype == TYPE_POINTER:
return self.get_pointer()
- elif self.g_type.is_a(TYPE_OBJECT):
+ elif gtype.is_a(TYPE_OBJECT):
return self.get_object()
- elif self.g_type == TYPE_UNICHAR:
+ elif gtype == TYPE_UNICHAR:
return self.get_uint()
- elif self.g_type == TYPE_GTYPE:
+ elif gtype == TYPE_GTYPE:
return self.get_gtype()
- elif self.g_type == TYPE_VARIANT:
+ elif gtype == TYPE_VARIANT:
return self.get_variant()
- elif self.g_type == TYPE_PYOBJECT:
+ elif gtype == TYPE_PYOBJECT:
pass
else:
return None
@@ -417,6 +416,20 @@ def signal_query(id_or_name, type_=None):
__all__.append('signal_query')
+def _get_instance_for_signal(obj):
+ if isinstance(obj, GObjectModule.Object):
+ return obj.__gpointer__
+ else:
+ raise TypeError('Unsupported object "%s" for signal function' % obj)
+
+
+def _wrap_signal_func(func):
+ @functools.wraps(func)
+ def wrapper(obj, *args, **kwargs):
+ return func(_get_instance_for_signal(obj), *args, **kwargs)
+ return wrapper
+
+
class _HandlerBlockManager(object):
def __init__(self, obj, handler_id):
self.obj = obj
@@ -426,7 +439,101 @@ class _HandlerBlockManager(object):
pass
def __exit__(self, exc_type, exc_value, traceback):
- self.obj.handler_unblock(self.handler_id)
+ signal_handler_unblock(self.obj, self.handler_id)
+
+
+def signal_handler_block(obj, handler_id):
+ """Blocks the signal handler from being invoked until handler_unblock() is called.
+
+ Returns a context manager which optionally can be used to
+ automatically unblock the handler:
+
+ >>> with GObject.signal_handler_block(obj, id):
+ >>> pass
+ """
+ GObjectModule.signal_handler_block(_get_instance_for_signal(obj), handler_id)
+ return _HandlerBlockManager(obj, handler_id)
+
+__all__.append('signal_handler_block')
+
+
+# The following functions wrap GI functions but coerce the first arg into
+# something compatible with gpointer
+
+signal_handler_unblock = _wrap_signal_func(GObjectModule.signal_handler_unblock)
+signal_handler_disconnect = _wrap_signal_func(GObjectModule.signal_handler_disconnect)
+signal_handler_is_connected = _wrap_signal_func(GObjectModule.signal_handler_is_connected)
+signal_stop_emission = _wrap_signal_func(GObjectModule.signal_stop_emission)
+signal_stop_emission_by_name = _wrap_signal_func(GObjectModule.signal_stop_emission_by_name)
+signal_has_handler_pending = _wrap_signal_func(GObjectModule.signal_has_handler_pending)
+signal_get_invocation_hint = _wrap_signal_func(GObjectModule.signal_get_invocation_hint)
+signal_connect_closure = _wrap_signal_func(GObjectModule.signal_connect_closure)
+signal_connect_closure_by_id = _wrap_signal_func(GObjectModule.signal_connect_closure_by_id)
+signal_handler_find = _wrap_signal_func(GObjectModule.signal_handler_find)
+signal_handlers_destroy = _wrap_signal_func(GObjectModule.signal_handlers_destroy)
+signal_handlers_block_matched = _wrap_signal_func(GObjectModule.signal_handlers_block_matched)
+signal_handlers_unblock_matched = _wrap_signal_func(GObjectModule.signal_handlers_unblock_matched)
+signal_handlers_disconnect_matched = _wrap_signal_func(GObjectModule.signal_handlers_disconnect_matched)
+
+__all__ += ['signal_handler_unblock',
+ 'signal_handler_disconnect', 'signal_handler_is_connected',
+ 'signal_stop_emission', 'signal_stop_emission_by_name',
+ 'signal_has_handler_pending', 'signal_get_invocation_hint',
+ 'signal_connect_closure', 'signal_connect_closure_by_id',
+ 'signal_handler_find', 'signal_handlers_destroy',
+ 'signal_handlers_block_matched', 'signal_handlers_unblock_matched',
+ 'signal_handlers_disconnect_matched']
+
+
+def signal_parse_name(detailed_signal, itype, force_detail_quark):
+ """Parse a detailed signal name into (signal_id, detail).
+
+ :Raises ValueError:
+ If the given signal is unknown.
+
+ :Returns:
+ Tuple of (signal_id, detail)
+ """
+ res, signal_id, detail = GObjectModule.signal_parse_name(detailed_signal, itype,
+ force_detail_quark)
+ if res:
+ return signal_id, detail
+ else:
+ raise ValueError('%s: unknown signal name: %s' % (itype, detailed_signal))
+
+__all__.append('signal_parse_name')
+
+
+def remove_emission_hook(obj, detailed_signal, hook_id):
+ signal_id, detail = signal_parse_name(detailed_signal, obj, True)
+ GObjectModule.signal_remove_emission_hook(signal_id, hook_id)
+
+__all__.append('remove_emission_hook')
+
+
+# GObject accumulators with pure Python implementations
+# These return a tuple of (continue_emission, accumulation_result)
+
+def signal_accumulator_first_wins(ihint, return_accu, handler_return, user_data=None):
+ # Stop emission but return the result of the last handler
+ return (False, handler_return)
+
+__all__.append('signal_accumulator_first_wins')
+
+
+def signal_accumulator_true_handled(ihint, return_accu, handler_return, user_data=None):
+ # Stop emission if the last handler returns True
+ return (not handler_return, handler_return)
+
+__all__.append('signal_accumulator_true_handled')
+
+
+# Statically bound signal functions which need to clobber GI (for now)
+
+add_emission_hook = _gobject.add_emission_hook
+signal_new = _gobject.signal_new
+
+__all__ += ['add_emission_hook', 'signal_new']
class _FreezeNotifyManager(object):
@@ -500,21 +607,6 @@ class Object(GObjectModule.Object):
__copy__ = _gobject.GObject.__copy__
__deepcopy__ = _gobject.GObject.__deepcopy__
- def handler_block(self, handler_id):
- """Blocks the signal handler from being invoked until handler_unblock() is called.
-
- Returns a context manager which optionally can be used to
- automatically unblock the handler:
-
- >>> with obj.handler_block(id):
- >>> pass
- """
- GObjectModule.signal_handler_block(self.__gpointer__, handler_id)
- return _HandlerBlockManager(self, handler_id)
-
- def handler_unblock(self, handler_id):
- GObjectModule.signal_handler_unblock(self.__gpointer__, handler_id)
-
def freeze_notify(self):
"""Freezes the object's property-changed notification queue.
@@ -530,27 +622,25 @@ class Object(GObjectModule.Object):
super(Object, self).freeze_notify()
return _FreezeNotifyManager(self)
- def handler_disconnect(self, handler_id):
- GObjectModule.signal_handler_disconnect(self.__gpointer__, handler_id)
-
- def handler_is_connected(self, handler_id):
- return bool(GObjectModule.signal_handler_is_connected(self.__gpointer__, handler_id))
-
- def stop_emission_by_name(self, detailed_signal):
- GObjectModule.signal_stop_emission_by_name(self.__gpointer__, detailed_signal)
-
#
# Aliases
#
- disconnect = handler_disconnect
+
+ disconnect = signal_handler_disconnect
+ handler_block = signal_handler_block
+ handler_unblock = signal_handler_unblock
+ handler_disconnect = signal_handler_disconnect
+ handler_is_connected = signal_handler_is_connected
+ stop_emission_by_name = signal_stop_emission_by_name
#
# Deprecated Methods
#
+
def stop_emission(self, detailed_signal):
"""Deprecated, please use stop_emission_by_name."""
warnings.warn(self.stop_emission.__doc__, PyGIDeprecationWarning, stacklevel=2)
- return self.stop_emission_by_name(detailed_signal)
+ return signal_stop_emission_by_name(self, detailed_signal)
emit_stop_by_name = stop_emission
diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py
index ceda261..14edc70 100644
--- a/gi/overrides/Gdk.py
+++ b/gi/overrides/Gdk.py
@@ -19,7 +19,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
-from ..overrides import override
+from ..overrides import override, strip_boolean_result
from ..module import get_introspection_module
import sys
@@ -251,19 +251,6 @@ gsuccess_mask_funcs = ['get_state',
'get_root_coords']
-def _gsuccess_mask(func):
- def cull_success(*args):
- result = func(*args)
- success = result[0]
- if not success:
- return None
- else:
- if len(result) == 2:
- return result[1]
- else:
- return result[1:]
- return cull_success
-
for event_class in event_member_classes:
override_class = type(event_class, (getattr(Gdk, event_class),), {})
# add the event methods
@@ -276,7 +263,7 @@ for event_class in event_member_classes:
# use the _gsuccess_mask decorator if this method is whitelisted
if name in gsuccess_mask_funcs:
- event_method = _gsuccess_mask(event_method)
+ event_method = strip_boolean_result(event_method)
setattr(override_class, name, event_method)
setattr(module, event_class, override_class)
@@ -335,15 +322,8 @@ class Cursor(Gdk.Cursor):
Cursor = override(Cursor)
__all__.append('Cursor')
-_Gdk_color_parse = Gdk.color_parse
-
-
-@override(Gdk.color_parse)
-def color_parse(color):
- success, color = _Gdk_color_parse(color)
- if not success:
- return None
- return color
+color_parse = strip_boolean_result(Gdk.color_parse)
+__all__.append('color_parse')
# Note, we cannot override the entire class as Gdk.Atom has no gtype, so just
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 002f22b..ab09a26 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -21,7 +21,7 @@
import sys
from gi.repository import GObject
-from ..overrides import override
+from ..overrides import override, strip_boolean_result
from ..module import get_introspection_module
from gi import PyGIDeprecationWarning
@@ -66,11 +66,7 @@ __all__.append('_construct_target_list')
class Widget(Gtk.Widget):
- def translate_coordinates(self, dest_widget, src_x, src_y):
- success, dest_x, dest_y = super(Widget, self).translate_coordinates(
- dest_widget, src_x, src_y)
- if success:
- return (dest_x, dest_y,)
+ translate_coordinates = strip_boolean_result(Gtk.Widget.translate_coordinates)
def render_icon(self, stock_id, size, detail=None):
return super(Widget, self).render_icon(stock_id, size, detail)
@@ -107,10 +103,8 @@ class Container(Gtk.Container, Widget):
# alias for Python 2.x object protocol
__nonzero__ = __bool__
- def get_focus_chain(self):
- success, widgets = super(Container, self).get_focus_chain()
- if success:
- return widgets
+ get_focus_chain = strip_boolean_result(Gtk.Container.get_focus_chain)
+
Container = override(Container)
__all__.append('Container')
@@ -119,16 +113,10 @@ __all__.append('Container')
class Editable(Gtk.Editable):
def insert_text(self, text, position):
- pos = super(Editable, self).insert_text(text, -1, position)
+ return super(Editable, self).insert_text(text, -1, position)
- return pos
+ get_selection_bounds = strip_boolean_result(Gtk.TextBuffer.get_selection_bounds, fail_ret=())
- def get_selection_bounds(self):
- success, start_pos, end_pos = super(Editable, self).get_selection_bounds()
- if success:
- return (start_pos, end_pos,)
- else:
- return tuple()
Editable = override(Editable)
__all__.append("Editable")
@@ -333,11 +321,7 @@ __all__.append('UIManager')
class ComboBox(Gtk.ComboBox, Container):
-
- def get_active_iter(self):
- success, aiter = super(ComboBox, self).get_active_iter()
- if success:
- return aiter
+ get_active_iter = strip_boolean_result(Gtk.ComboBox.get_active_iter)
ComboBox = override(ComboBox)
__all__.append('ComboBox')
@@ -611,20 +595,9 @@ class IconView(Gtk.IconView):
def __init__(self, model=None, **kwds):
Gtk.IconView.__init__(self, model=model, **kwds)
- def get_item_at_pos(self, x, y):
- success, path, cell = super(IconView, self).get_item_at_pos(x, y)
- if success:
- return (path, cell,)
-
- def get_visible_range(self):
- success, start_path, end_path = super(IconView, self).get_visible_range()
- if success:
- return (start_path, end_path,)
-
- def get_dest_item_at_pos(self, drag_x, drag_y):
- success, path, pos = super(IconView, self).get_dest_item_at_pos(drag_x, drag_y)
- if success:
- return path, pos
+ get_item_at_pos = strip_boolean_result(Gtk.IconView.get_item_at_pos)
+ get_visible_range = strip_boolean_result(Gtk.IconView.get_visible_range)
+ get_dest_item_at_pos = strip_boolean_result(Gtk.IconView.get_dest_item_at_pos)
IconView = override(IconView)
__all__.append('IconView')
@@ -640,22 +613,14 @@ __all__.append('ToolButton')
class IMContext(Gtk.IMContext):
-
- def get_surrounding(self):
- success, text, cursor_index = super(IMContext, self).get_surrounding()
- if success:
- return (text, cursor_index,)
+ get_surrounding = strip_boolean_result(Gtk.IMContext.get_surrounding)
IMContext = override(IMContext)
__all__.append('IMContext')
class RecentInfo(Gtk.RecentInfo):
-
- def get_application_info(self, app_name):
- success, app_exec, count, time = super(RecentInfo, self).get_application_info(app_name)
- if success:
- return (app_exec, count, time,)
+ get_application_info = strip_boolean_result(Gtk.RecentInfo.get_application_info)
RecentInfo = override(RecentInfo)
__all__.append('RecentInfo')
@@ -739,12 +704,7 @@ class TextBuffer(Gtk.TextBuffer):
Gtk.TextBuffer.insert_at_cursor(self, text, length)
- def get_selection_bounds(self):
- success, start, end = super(TextBuffer, self).get_selection_bounds()
- if success:
- return (start, end)
- else:
- return ()
+ get_selection_bounds = strip_boolean_result(Gtk.TextBuffer.get_selection_bounds, fail_ret=())
TextBuffer = override(TextBuffer)
__all__.append('TextBuffer')
@@ -752,21 +712,8 @@ __all__.append('TextBuffer')
class TextIter(Gtk.TextIter):
- def forward_search(self, string, flags, limit):
- success, match_start, match_end = super(TextIter, self).forward_search(string,
- flags, limit)
- if success:
- return (match_start, match_end)
- else:
- return None
-
- def backward_search(self, string, flags, limit):
- success, match_start, match_end = super(TextIter, self).backward_search(string,
- flags, limit)
- if success:
- return (match_start, match_end)
- else:
- return None
+ forward_search = strip_boolean_result(Gtk.TextIter.forward_search)
+ backward_search = strip_boolean_result(Gtk.TextIter.backward_search)
def begins_tag(self, tag=None):
return super(TextIter, self).begins_tag(tag)
@@ -831,6 +778,13 @@ class TreeModel(Gtk.TreeModel):
def __iter__(self):
return TreeModelRowIter(self, self.get_iter_first())
+ get_iter_first = strip_boolean_result(Gtk.TreeModel.get_iter_first)
+ iter_children = strip_boolean_result(Gtk.TreeModel.iter_children)
+ iter_nth_child = strip_boolean_result(Gtk.TreeModel.iter_nth_child)
+ iter_parent = strip_boolean_result(Gtk.TreeModel.iter_parent)
+ get_iter_from_string = strip_boolean_result(Gtk.TreeModel.get_iter_from_string,
+ ValueError, 'invalid tree path')
+
def get_iter(self, path):
path = self._coerce_path(path)
success, aiter = super(TreeModel, self).get_iter(path)
@@ -838,17 +792,6 @@ class TreeModel(Gtk.TreeModel):
raise ValueError("invalid tree path '%s'" % path)
return aiter
- def get_iter_first(self):
- success, aiter = super(TreeModel, self).get_iter_first()
- if success:
- return aiter
-
- def get_iter_from_string(self, path_string):
- success, aiter = super(TreeModel, self).get_iter_from_string(path_string)
- if not success:
- raise ValueError("invalid tree path '%s'" % path_string)
- return aiter
-
def iter_next(self, aiter):
next_iter = aiter.copy()
success = super(TreeModel, self).iter_next(next_iter)
@@ -861,21 +804,6 @@ class TreeModel(Gtk.TreeModel):
if success:
return prev_iter
- def iter_children(self, aiter):
- success, child_iter = super(TreeModel, self).iter_children(aiter)
- if success:
- return child_iter
-
- def iter_nth_child(self, parent, n):
- success, child_iter = super(TreeModel, self).iter_nth_child(parent, n)
- if success:
- return child_iter
-
- def iter_parent(self, aiter):
- success, parent_iter = super(TreeModel, self).iter_parent(aiter)
- if success:
- return parent_iter
-
def _convert_row(self, row):
# TODO: Accept a dictionary for row
# model.append(None,{COLUMN_ICON: icon, COLUMN_NAME: name})
@@ -957,12 +885,7 @@ __all__.append('TreeModel')
class TreeSortable(Gtk.TreeSortable, ):
- def get_sort_column_id(self):
- success, sort_column_id, order = super(TreeSortable, self).get_sort_column_id()
- if success:
- return (sort_column_id, order,)
- else:
- return (None, None,)
+ get_sort_column_id = strip_boolean_result(Gtk.TreeSortable.get_sort_column_id, fail_ret=(None, None))
def set_sort_func(self, sort_column_id, sort_func, user_data=None):
super(TreeSortable, self).set_sort_func(sort_column_id, sort_func, user_data)
@@ -1318,20 +1241,9 @@ class TreeView(Gtk.TreeView, Container):
if model:
self.set_model(model)
- def get_path_at_pos(self, x, y):
- success, path, column, cell_x, cell_y = super(TreeView, self).get_path_at_pos(x, y)
- if success:
- return (path, column, cell_x, cell_y,)
-
- def get_visible_range(self):
- success, start_path, end_path = super(TreeView, self).get_visible_range()
- if success:
- return (start_path, end_path,)
-
- def get_dest_row_at_pos(self, drag_x, drag_y):
- success, path, pos = super(TreeView, self).get_dest_row_at_pos(drag_x, drag_y)
- if success:
- return (path, pos,)
+ get_path_at_pos = strip_boolean_result(Gtk.TreeView.get_path_at_pos)
+ get_visible_range = strip_boolean_result(Gtk.TreeView.get_visible_range)
+ get_dest_row_at_pos = strip_boolean_result(Gtk.TreeView.get_dest_row_at_pos)
def enable_model_drag_source(self, start_button_mask, targets, actions):
target_entries = _construct_target_list(targets)
@@ -1381,10 +1293,7 @@ class TreeViewColumn(Gtk.TreeViewColumn):
for (name, value) in attributes.items():
self.add_attribute(cell_renderer, name, value)
- def cell_get_position(self, cell_renderer):
- success, start_pos, width = super(TreeViewColumn, self).cell_get_position(cell_renderer)
- if success:
- return (start_pos, width,)
+ cell_get_position = strip_boolean_result(Gtk.TreeViewColumn.cell_get_position)
def set_cell_data_func(self, cell_renderer, func, func_data=None):
super(TreeViewColumn, self).set_cell_data_func(cell_renderer, func, func_data)
@@ -1587,16 +1496,8 @@ _Gtk_main_quit = Gtk.main_quit
def main_quit(*args):
_Gtk_main_quit()
-_Gtk_stock_lookup = Gtk.stock_lookup
-
-
-@override(Gtk.stock_lookup)
-def stock_lookup(*args):
- success, item = _Gtk_stock_lookup(*args)
- if not success:
- return None
-
- return item
+stock_lookup = strip_boolean_result(Gtk.stock_lookup)
+__all__.append('stock_lookup')
initialized, argv = Gtk.init_check(sys.argv)
sys.argv = list(argv)
diff --git a/gi/overrides/Makefile.in b/gi/overrides/Makefile.in
index 59b1b35..feed8d4 100644
--- a/gi/overrides/Makefile.in
+++ b/gi/overrides/Makefile.in
@@ -55,8 +55,10 @@ DIST_COMMON = $(pygioverrides_PYTHON) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
- $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/python.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 0bd94b8..99cb152 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -85,3 +85,25 @@ def deprecated(fn, replacement):
PyGIDeprecationWarning, stacklevel=2)
return fn(*args, **kwargs)
return wrapped
+
+
+def strip_boolean_result(method, exc_type=None, exc_str=None, fail_ret=None):
+ '''Translate method's return value for stripping off success flag.
+
+ There are a lot of methods which return a "success" boolean and have
+ several out arguments. Translate such a method to return the out arguments
+ on success and None on failure.
+ '''
+ @functools.wraps(method)
+ def wrapped(*args, **kwargs):
+ ret = method(*args, **kwargs)
+ if ret[0]:
+ if len(ret) == 2:
+ return ret[1]
+ else:
+ return ret[1:]
+ else:
+ if exc_type:
+ raise exc_type(exc_str or 'call failed')
+ return fail_ret
+ return wrapped