Commit c5e62d1d authored by Ivan Frade's avatar Ivan Frade Committed by Martyn Russell

libtracker-miner, libtracker-sparql: Added introspection examples

Miner and Async query are not working as expected yet, but the code
should be correct.
parent 54d0a683
#!/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 ()
#!/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 ()
#!/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 ()
#!/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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment