Sugar.profile: Difference between revisions

From OLPC
Jump to navigation Jump to search
(New page: = Helper Functions = = Class: Profile =)
 
No edit summary
Line 1: Line 1:
The profile package can be used to get access to user specific details such as his/her nick_name, XO colors, public key, etc. Much of these details are accessed by first creating a Profile object. However, there are several shortcut helper functions that provide access to some user details directly.

= Helper Functions =
= Helper Functions =

=== How do I get the user's nick name? ===
<pre>
from sugar import profile
...
#prof will refer to a Profile object used to access user information
prof = profile.get_profile()

# Two ways to print nickname: either through profile object, or through a helper funciton in sugar.profile
print prof.nick_name
print profile.get_nick_name()
</pre>

=== How do I get the XO colors set by the user? ===
<pre>
from sugar import profile
...
#prof will refer to a Profile object used to access user information
prof = profile.get_profile()

# Two ways to get the XO colors: through profile object or using helper function
print prof.color.to_string()
print profile.get_color().to_string()
</pre>

==- How do I access this XO's public key? ===
<pre>
from sugar import profile
...
#prof will refer to a Profile object used to access user information
prof = profile.get_profile()

#Two ways to get the public key for this XO: through Profile object or with helper function
print prof.pubkey
print profile.get_pubkey()
</pre>


= Class: Profile =
= Class: Profile =

Revision as of 17:30, 30 June 2008

The profile package can be used to get access to user specific details such as his/her nick_name, XO colors, public key, etc. Much of these details are accessed by first creating a Profile object. However, there are several shortcut helper functions that provide access to some user details directly.

Helper Functions

How do I get the user's nick name?

from sugar import profile 
...
        #prof will refer to a Profile object used to access user information
        prof = profile.get_profile()

        # Two ways to print nickname: either through profile object, or through a helper funciton in sugar.profile
        print prof.nick_name
        print profile.get_nick_name()

How do I get the XO colors set by the user?

from sugar import profile 
...
        #prof will refer to a Profile object used to access user information
        prof = profile.get_profile()

        # Two ways to get the XO colors: through profile object or using helper function
        print prof.color.to_string()
        print profile.get_color().to_string()

- How do I access this XO's public key? =

from sugar import profile 
...
        #prof will refer to a Profile object used to access user information
        prof = profile.get_profile()

        #Two ways to get the public key for this XO: through Profile object or with helper function
        print prof.pubkey
        print profile.get_pubkey()

Class: Profile