[gom] python: Override the Sorting constructor
- From: Mathieu Bridon <mbridon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gom] python: Override the Sorting constructor
- Date: Sat, 8 Aug 2015 12:14:30 +0000 (UTC)
commit 27b4d00a70468b5479c3c082724e88e634735b41
Author: Mathieu Bridon <bochecha daitauha fr>
Date: Sat Aug 1 16:33:08 2015 +0200
python: Override the Sorting constructor
In C, the gom_sorting_new constructor allows passing all the sorting
arguments to the created GomSorting object.
This allows doing exactly the same thing in Python as well, without
having to first create the Gom.Sorting object, then adding all the
sorting arguments.
https://bugzilla.gnome.org/show_bug.cgi?id=753137
bindings/python/gi/overrides/Gom.py | 16 ++++++++++++++++
examples/gom.py | 3 +--
2 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/bindings/python/gi/overrides/Gom.py b/bindings/python/gi/overrides/Gom.py
index fde0746..0da42d9 100644
--- a/bindings/python/gi/overrides/Gom.py
+++ b/bindings/python/gi/overrides/Gom.py
@@ -16,6 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from itertools import zip_longest
+
from ..module import get_introspection_module
from ..overrides import override
@@ -25,6 +27,7 @@ Gom = get_introspection_module('Gom')
__all__ = [
'ResourceGroup',
+ 'Sorting',
]
@@ -39,4 +42,17 @@ class ResourceGroupOverride(Gom.ResourceGroup):
return self.get_index(index)
+class SortingOverride(Gom.Sorting):
+ def __init__(self, *args):
+ super().__init__()
+
+ def grouper(n, iterable):
+ args = [iter(iterable)] * n
+ return zip_longest(fillvalue=None, *args)
+
+ for type_, prop_name, sorting_mode in grouper(3, args):
+ self.add(type_, prop_name, sorting_mode)
+
+
ResourceGroup = override(ResourceGroupOverride)
+Sorting = override(SortingOverride)
diff --git a/examples/gom.py b/examples/gom.py
index f6ea9c5..1e4ce9f 100755
--- a/examples/gom.py
+++ b/examples/gom.py
@@ -46,8 +46,7 @@ if __name__ == '__main__':
# Fetch them all with a None filter, ordered by name
names = ['item2', 'item1']
- sorting = Gom.Sorting()
- sorting.add(ItemResource, "name", Gom.SortingMode.DESCENDING)
+ sorting = Gom.Sorting(ItemResource, "name", Gom.SortingMode.DESCENDING)
group = repository.find_sorted_sync(ItemResource, None, sorting)
count = len(group)
assert count == 2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]