summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorIvan Frade <ivan.frade@nokia.com>2011-03-28 19:28:49 +0300
committerMartyn Russell <martyn@lanedo.com>2011-04-05 12:29:46 +0100
commitc5e62d1dedf1fab04087e6ed7efb96b998e9b54a (patch)
tree88d1e02436d664399c70098f414bb8c065802772 /examples
parent54d0a683acbfdc10589c6bb4b06573f32483667a (diff)
downloadtracker-c5e62d1dedf1fab04087e6ed7efb96b998e9b54a.tar.gz
libtracker-miner, libtracker-sparql: Added introspection examples
Miner and Async query are not working as expected yet, but the code should be correct.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/introspection/python/all-async.py30
-rwxr-xr-xexamples/introspection/python/miner.py47
-rwxr-xr-xexamples/introspection/python/query-async.py25
-rwxr-xr-xexamples/introspection/python/query-sync.py9
4 files changed, 111 insertions, 0 deletions
diff --git a/examples/introspection/python/all-async.py b/examples/introspection/python/all-async.py
new file mode 100755
index 000000000..70a3b2b1f
--- /dev/null
+++ b/examples/introspection/python/all-async.py
@@ -0,0 +1,30 @@
+#!/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 ()
+
+def connection_ready_cb (object, result, user_data):
+ assert user_data
+ conn = Tracker.SparqlConnection.get_finish (result)
+
+ conn.query_async ("SELECT ?u WHERE { ?u a nie:InformationElement. }",
+ None,
+ results_ready_cb,
+ user_data)
+
+
+if __name__ == "__main__":
+ loop = GObject.MainLoop ()
+
+ Tracker.SparqlConnection.get_async (None, connection_ready_cb, loop)
+
+ loop.run ()
diff --git a/examples/introspection/python/miner.py b/examples/introspection/python/miner.py
new file mode 100755
index 000000000..b7944a95e
--- /dev/null
+++ b/examples/introspection/python/miner.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+import gi
+from gi.repository import TrackerMiner, GLib, GObject, Gio
+
+
+class MyMiner (TrackerMiner.Miner):
+ __gtype_name__ = 'MyMiner'
+
+ def __init__ (self):
+ TrackerMiner.Miner.__init__ (self,
+ name="MyMiner",
+ progress=0,
+ status="fine")
+ # This shouldn't be needed, but at the moment the
+ # overrided methods are not called
+ self.connect ("started", self.started_cb)
+
+ # Say to initable that we are ok
+ self.init (None)
+
+ def started (self, x):
+ print "override started"
+
+ def started_cb (self, x):
+ print "started as callback"
+
+ def stopped (self):
+ print "override stopped"
+
+ def resumed (self):
+ print "override resumed"
+
+ def paused (self):
+ print "override paused"
+
+ def progress (self):
+ print "override progress"
+
+ def ignore_next_update (self):
+ print "override ignore next updated"
+
+
+if __name__ == "__main__":
+ m = MyMiner ()
+ m.start ()
+
+ GObject.MainLoop().run ()
diff --git a/examples/introspection/python/query-async.py b/examples/introspection/python/query-async.py
new file mode 100755
index 000000000..be5ede51b
--- /dev/null
+++ b/examples/introspection/python/query-async.py
@@ -0,0 +1,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 ()
diff --git a/examples/introspection/python/query-sync.py b/examples/introspection/python/query-sync.py
new file mode 100755
index 000000000..cf8bfd6f6
--- /dev/null
+++ b/examples/introspection/python/query-sync.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+import gi
+from gi.repository import Tracker
+
+conn = Tracker.SparqlConnection.get (None)
+cursor = conn.query ("SELECT ?u WHERE { ?u a nie:InformationElement. }", None)
+
+while (cursor.next (None)):
+ print cursor.get_string (0)