diff options
Diffstat (limited to 'gi/overrides')
-rw-r--r-- | gi/overrides/Gio.py | 17 | ||||
-rw-r--r-- | gi/overrides/Gtk.py | 21 | ||||
-rw-r--r-- | gi/overrides/__init__.py | 12 |
3 files changed, 34 insertions, 16 deletions
diff --git a/gi/overrides/Gio.py b/gi/overrides/Gio.py index 5cc12a6c..c807fe0b 100644 --- a/gi/overrides/Gio.py +++ b/gi/overrides/Gio.py @@ -21,9 +21,8 @@ import warnings from .._ossighelper import wakeup_on_signal, register_sigint_fallback -from ..overrides import override, deprecated_init +from ..overrides import override, deprecated_init, wrap_list_store_sort_func from ..module import get_introspection_module -from gi._gi import pygobject_new_full from gi import PyGIWarning from gi.repository import GLib @@ -461,16 +460,6 @@ ListModel = override(ListModel) __all__.append('ListModel') -def _wrap_list_store_sort_func(func): - - def wrap(a, b, *user_data): - a = pygobject_new_full(a, False) - b = pygobject_new_full(b, False) - return func(a, b, *user_data) - - return wrap - - if (GLib.MAJOR_VERSION, GLib.MINOR_VERSION, GLib.MICRO_VERSION) < (2, 57, 1): # The "additions" functionality in splice() was broken in older glib # https://bugzilla.gnome.org/show_bug.cgi?id=795307 @@ -487,11 +476,11 @@ else: class ListStore(Gio.ListStore): def sort(self, compare_func, *user_data): - compare_func = _wrap_list_store_sort_func(compare_func) + compare_func = wrap_list_store_sort_func(compare_func) return super(ListStore, self).sort(compare_func, *user_data) def insert_sorted(self, item, compare_func, *user_data): - compare_func = _wrap_list_store_sort_func(compare_func) + compare_func = wrap_list_store_sort_func(compare_func) return super(ListStore, self).insert_sorted( item, compare_func, *user_data) diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py index 721e5317..b1bebf77 100644 --- a/gi/overrides/Gtk.py +++ b/gi/overrides/Gtk.py @@ -26,7 +26,8 @@ from collections import abc from gi.repository import GObject from .._ossighelper import wakeup_on_signal, register_sigint_fallback from .._gtktemplate import Template -from ..overrides import override, strip_boolean_result, deprecated_init +from ..overrides import (override, strip_boolean_result, deprecated_init, + wrap_list_store_sort_func) from ..module import get_introspection_module from gi import PyGIDeprecationWarning @@ -1647,6 +1648,24 @@ class TreeModelFilter(Gtk.TreeModelFilter): TreeModelFilter = override(TreeModelFilter) __all__.append('TreeModelFilter') +if GTK4: + class CustomSorter(Gtk.CustomSorter): + + @classmethod + def new(cls, sort_func=None, user_data=None): + self = Gtk.CustomSorter.new(None, None) + if sort_func: + self.set_sort_func(sort_func, user_data) + + return self + + def set_sort_func(self, sort_func, user_data=None): + compare_func = wrap_list_store_sort_func(sort_func) + return super(CustomSorter, self).set_sort_func(compare_func, user_data) + + CustomSorter = override(CustomSorter) + __all__.append("CustomSorter") + if GTK3: class Menu(Gtk.Menu): def popup(self, parent_menu_shell, parent_menu_item, func, data, button, activate_time): diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py index 1572d251..37dfbbe5 100644 --- a/gi/overrides/__init__.py +++ b/gi/overrides/__init__.py @@ -6,7 +6,7 @@ import sys from pkgutil import get_loader from gi import PyGIDeprecationWarning -from gi._gi import CallableInfo +from gi._gi import CallableInfo, pygobject_new_full from gi._constants import \ TYPE_NONE, \ TYPE_INVALID @@ -341,3 +341,13 @@ def strip_boolean_result(method, exc_type=None, exc_str=None, fail_ret=None): raise exc_type(exc_str or 'call failed') return fail_ret return wrapped + + +def wrap_list_store_sort_func(func): + + def wrap(a, b, *user_data): + a = pygobject_new_full(a, False) + b = pygobject_new_full(b, False) + return func(a, b, *user_data) + + return wrap |