summaryrefslogtreecommitdiff
path: root/examples/introspection/python/query-async.py
blob: be5ede51b8e67033e8ac3e651887d6a1273e9fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
import gi
from gi.repository import Tracker, GObject

def results_ready_cb (obj, result, user_data):
    cursor = obj.query_finish (result)

    # This can also be done asynchronously
    while (cursor.next (None)):
        print cursor.get_string (0)

    user_data.quit ()


if __name__ == "__main__":
    loop = GObject.MainLoop ()

    # The connection can be requested asynchronously
    conn = Tracker.SparqlConnection.get (None)
    conn.query_async ("SELECT ?u WHERE { ?u a nie:InformationElement. }",
                      None,
                      results_ready_cb,
                      loop)

    loop.run ()