Editing PyMaemo/Accessing APIs without Python bindings/More examples

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 3: Line 3:
This page contains some other example code using ctypes. Note that they are not complete, and assume some code already shown on the [[../|main article]].
This page contains some other example code using ctypes. Note that they are not complete, and assume some code already shown on the [[../|main article]].
-
== Searching for contacts by phone number ==
+
== Searching contacts by phone number ==
-
Searching for contacts by phone number can be done using the [http://maemo.org/api_refs/5.0/5.0-final/libosso-abook/OssoABookAggregator.html#osso-abook-aggregator-find-contacts-for-phone-number osso_abook_aggregator_find_contacts_for_phone_number()] function:
+
Searching contacts by phone number can be done using the [http://maemo.org/api_refs/5.0/5.0-final/libosso-abook/OssoABookAggregator.html#osso-abook-aggregator-find-contacts-for-phone-number osso_abook_aggregator_find_contacts_for_phone_number()] function:
-
<source lang="python">
+
-
def aggregator_ready_cb(aggregator, error, user_data):
+
-
    contacts = osso_abook.osso_abook_aggregator_find_contacts_for_phone_number(aggregator, phone_number, 1)
+
-
    if contacts:
+
-
        print "Contacts with phone number %s:" % phone_number
+
-
        for i in glist(contacts):
+
-
            contact_get_display_name = osso_abook.osso_abook_contact_get_display_name
+
-
            contact_get_display_name.restype = ctypes.c_char_p
+
-
            print contact_get_display_name(i)
+
-
        glib.g_list_free(contacts)
+
-
    else:
+
-
        print "No contacts found with phone number %s." % phone_number
+
-
    gtk.main_quit()
+
def aggregator_ready_cb(aggregator, error, user_data):
 +
    contacts = osso_abook.osso_abook_aggregator_find_contacts_for_phone_number(aggregator, phone_number, 1)
 +
    if contacts:
 +
        print "Contacts with phone number %s:" % phone_number
 +
        for i in glist(contacts):
 +
            contact_get_display_name = osso_abook.osso_abook_contact_get_display_name
 +
            contact_get_display_name.restype = ctypes.c_char_p
 +
            print contact_get_display_name(i)
 +
        glib.g_list_free(contacts)
 +
    else:
 +
        print "No contacts found with phone number %s." % phone_number
 +
 +
    gtk.main_quit()
 +
 +
aggregator = osso_abook.osso_abook_aggregator_get_default(0)
 +
wait_cb_type = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p)
 +
# Keep prototype object reference so it is not destroyed
 +
cb_proto = wait_cb_type(aggregator_ready_cb)
 +
osso_abook.osso_abook_waitable_call_when_ready(aggregator, cb_proto, 0, 0)
 +
 +
gtk.main()
-
aggregator = osso_abook.osso_abook_aggregator_get_default(0)
 
-
wait_cb_type = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p)
 
-
# Keep prototype object reference so it is not destroyed
 
-
cb_proto = wait_cb_type(aggregator_ready_cb)
 
-
osso_abook.osso_abook_waitable_call_when_ready(aggregator, cb_proto, 0, 0)
 
-
 
-
gtk.main()
 
-
</source>
 
[[Category:Python]]
[[Category:Python]]

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)