Development Team/Almanac/sugar.profile: Difference between revisions
No edit summary |
|||
| (11 intermediate revisions by 8 users not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{Almanac}} | ||
'''Note:''' | |||
sugar.profile is largely depreciated. We are now using gconf for accessing most profile information. | |||
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. | 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. | ||
| Line 6: | Line 11: | ||
=== How do I get the user's nick name? === | === How do I get the user's nick name? === | ||
<pre> | |||
import gconf | |||
client = gconf.client_get_default() | |||
username = client.get_string("/desktop/sugar/user/nick") | |||
</pre> | |||
The following code is depreciated: | |||
<pre> | <pre> | ||
from sugar import profile | from sugar import profile | ||
| Line 12: | Line 27: | ||
prof = profile.get_profile() | prof = profile.get_profile() | ||
# Two ways to print nickname: either through profile object, or through a helper | # Two ways to print nickname: either through profile object, or through a helper function in sugar.profile | ||
print prof.nick_name | print prof.nick_name | ||
print profile.get_nick_name() | print profile.get_nick_name() | ||
| Line 18: | Line 33: | ||
=== How do I get the XO colors set by the user? === | === How do I get the XO colors set by the user? === | ||
<pre> | |||
import gconf | |||
client = gconf.client_get_default() | |||
color = client.get_string("/desktop/sugar/user/color") | |||
stroke,fill = color.split(",") | |||
</pre> | |||
The following code is depreciated: | |||
<pre> | <pre> | ||
from sugar import profile | from sugar import profile | ||
| Line 46: | Line 71: | ||
See the documentation for [[#Helper Functions | Helper Functions]]. | See the documentation for [[#Helper Functions | Helper Functions]]. | ||
=== How do I get the school server with which this child is associated | === How do I get the school server with which this child is associated? === | ||
Method on the 82: DEPRECATED | |||
<pre> | <pre> | ||
from sugar import profile | from sugar import profile | ||
| Line 58: | Line 84: | ||
#Print out whether this XO is actually registered with a school server | #Print out whether this XO is actually registered with a school server | ||
print prof.jabber_registered | print prof.jabber_registered | ||
</pre> | |||
Get school server with both older and new implementations. | |||
<pre> | |||
from sugar import profile | |||
... | |||
prof = profile.get_profile() | |||
jabber_serv = None | |||
if hasattr(profile, 'jabber_server'): | |||
jabber_serv = profile.jabber_server | |||
else: | |||
import gconf | |||
client = gconf.client_get_default() | |||
jabber_serv = client.get_string("/desktop/sugar/collaboration/jabber_server") | |||
</pre> | </pre> | ||