Sugar almanac: Difference between revisions
No edit summary |
No edit summary |
||
| Line 7: | Line 7: | ||
= Package: sugar = |
= Package: sugar = |
||
* [[sugar.env]] |
* [[sugar.env]] |
||
* [[sugar.profile]] |
|||
= Package: sugar.activity = |
= Package: sugar.activity = |
||
Revision as of 17:14, 30 June 2008
|
Sugar Almanac for Developers |
|---|
|
Sugar Almanac Main Page Package: sugar |
|
Package: sugar.activity |
|
Package: sugar.graphics |
|
Package: sugar.datastore |
|
Logging |
|
Notes on using Python Standard Logging in Sugar |
|
Internationalization |
How do I get additional help beyond this almanac?
- Looking to get started with the basics of sugar development? Check out Christoph Derndorfer's Activity Handbook.
Now, on to the actual almanac ...
Package: sugar
Package: sugar.activity
Package: sugar.datastore
Package: sugar.graphics
Internationalization
MISCELLANEOUS
The tasks below are random useful techniques that have come up as I write code and documentation for this reference. They have yet to be categorized, but will be as a sufficient set of related entries are written.
How do I write to a log in my activity code?
Sugar uses python's standard logging. The following code shows how to output something at the debug log level.
import logging
_logger = logging.getLogger('annotate-activity')
...
_logger.debug('starting activity')
How do I know when my activity is "active" or not?
You can set an event using the VISIBILITY_NOTIFY_MASK constant in order to know when your activity changes visibility. Then in the callback for this event, you simply compare the event's state to gtk-defined variables for activity visibility. See the GDK Visibility State Constants section of gtk.gdk.Constants for more information.
#Notify when the visibility state changes by calling self._visibleNotifyCb
#(PUT THIS IN YOUR ACTIVITY CODE - EG. THE __init__() METHOD)
self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
self.connect("visibility-notify-event", self._visibleNotifyCb)
...
#Callback method for when the activity's visibility changes
def _visibleNotifyCb(self, widget, event):
if (event.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED):
print "I am not visible"
elif (event.state == gtk.gdk.VISIBILITY_UNOBSCURED):
print "I am visible"
How do I get the amount of free space available on disk under the /home directory tree?
The following function uses the statvfs module. The following code demonstrates how to get the total amount of free space under /home.
#### Method: getFreespaceKb, returns the available freespace in kilobytes.
def getFreespaceKb(self):
stat = os.statvfs("/home")
freebytes = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
freekb = freebytes / 1024
return freekb
Notes
- See also Sugar Code Snippets
<references />