Changes

Line 1: Line 1:  +
{{Translations}}
 
{{Almanac}}
 
{{Almanac}}
 
{{Almanac TOC}}
 
{{Almanac TOC}}
 
== How do I get additional help beyond this almanac? ==
 
== How do I get additional help beyond this almanac? ==
* Looking to get started with the basics of Sugar development? Check out Christoph Derndorfer's [http://www.olpcaustria.org/mediawiki/index.php/Activity_handbook Activity Handbook].  
+
* Looking to get started with the basics of Sugar development? Check out OLPC Austria's [http://wiki.sugarlabs.org/images/5/51/Activity_Handbook_200805_online.pdf Activity Handbook] (''Please note that this handbook was last updated in May 2008 so the screenshots still show pre-8.2 design. In terms of the code itself things should still work as described. If you run into any issues please contact [[User:ChristophD|ChristophD]].'') 
 
* See also [[Development Team/Almanac/Code Snippets]]
 
* See also [[Development Team/Almanac/Code Snippets]]
       
Now, on to the actual almanac ...
 
Now, on to the actual almanac ...
 +
 +
== Where can I see the components of Sugar and their relationships? ==
 +
* [[Sugar System Stack]]
 +
* [[Sugar Platform Stack]]
    
== Where can I see API changes? ==
 
== Where can I see API changes? ==
Line 99: Line 104:  
view.modify_font(pango.FontDescription("Monospace " +
 
view.modify_font(pango.FontDescription("Monospace " +
 
                 str(style.FONT_SIZE)))
 
                 str(style.FONT_SIZE)))
 +
...
 +
 
</pre>
 
</pre>
   Line 109: Line 116:  
text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
 
text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
 
</pre>
 
</pre>
 +
 +
You will probably want to put the view in a gtk.ScrolledWindow
 +
<pre>
 +
sw = gtk.ScrolledWindow()
 +
sw.add(view)
 +
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
 +
</pre>
 +
and add the sw object instead of the view.
 +
    
You can find more in the Pippy source and in jarabe.view.sourceview.
 
You can find more in the Pippy source and in jarabe.view.sourceview.
Line 144: Line 160:  
passedTime = 0
 
passedTime = 0
   −
if (x != self.mx or y != self.my):
+
if x != self.mx or y != self.my:
 
self.hideWidgetsTime = time.time()
 
self.hideWidgetsTime = time.time()
if (self.hiddenWidgets):
+
if self.hiddenWidgets:
 
self.showWidgets()
 
self.showWidgets()
 
self.hiddenWidgets = False
 
self.hiddenWidgets = False
Line 153: Line 169:       −
if (passedTime >= 3):
+
if passedTime >= 3:
if (not self.hiddenWidgets):
+
if not self.hiddenWidgets:
 
self.hideWidgets()
 
self.hideWidgets()
 
self.hiddenWidgets = True
 
self.hiddenWidgets = True
Line 188: Line 204:     
=== How do I get the amount of free space available on disk under the /home directory tree? ===
 
=== How do I get the amount of free space available on disk under the /home directory tree? ===
The following function uses the [http://docs.python.org/lib/module-statvfs.html statvfs] module. The following code demonstrates how to get the total amount of free space under /home.  
+
The following code demonstrates how to get the total amount of free space under /home.  
    
<pre>
 
<pre>
Line 194: Line 210:  
     def getFreespaceKb(self):
 
     def getFreespaceKb(self):
 
         stat = os.statvfs("/home")
 
         stat = os.statvfs("/home")
         freebytes  = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
+
         freebytes  = stat.f_bsize * stat.f_bavail
 
         freekb = freebytes / 1024
 
         freekb = freebytes / 1024
 
         return freekb
 
         return freekb
Line 203: Line 219:     
=== How do I know whether my activity is running on a physical XO? ===
 
=== How do I know whether my activity is running on a physical XO? ===
Sugar runs on ordinary computers as well as on XO's.  While your activity is typically going to be run on a real XO, some people will indeed run it elsewhere.  Normally you shouldn't write your activity to care whether it's on an XO or not.  If for some odd reason, you need to care, the easiest way to tell if you are on a physical XO is to check whether /sys/power/olpc-pm, an essential power management file for the XO, exists. <ref>[http://lists.laptop.org/pipermail/devel/2008-June/015923.html reliably detecting if running on an XO]</ref> <ref>OLPC [[Power Management Interface]]</ref>
+
Sugar runs on ordinary computers as well as on XO's.  While your activity is typically going to be run on a real XO, some people will indeed run it elsewhere.  Normally you shouldn't write your activity to care whether it's on an XO or not.  If for some odd reason, you need to care, the easiest way to tell if you are on a physical XO is to check whether /sys/power/olpc-pm, an essential power management file for the XO, exists. <ref>[http://lists.laptop.org/pipermail/devel/2008-June/015923.html reliably detecting if running on an XO]</ref> <ref>OLPC [[olpc:Power Management Interface]]</ref>
    
<pre>
 
<pre>
Line 224: Line 240:  
The gobject.timeout_add() function allows you to invoke a callback method after a certain amount of time. If you want to repeatedly call a method, simply keep invoking the gobject.timeout_add function in your callback itself. The code below is a simple example, where the callback function is named repeatedly_call. Note that the timing of the callbacks are approximate. To get the process going, you should make an initial call to repeatedly_call() somewhere in your code.  
 
The gobject.timeout_add() function allows you to invoke a callback method after a certain amount of time. If you want to repeatedly call a method, simply keep invoking the gobject.timeout_add function in your callback itself. The code below is a simple example, where the callback function is named repeatedly_call. Note that the timing of the callbacks are approximate. To get the process going, you should make an initial call to repeatedly_call() somewhere in your code.  
   −
You can see a more substantive example of this pattern in use when we [[Pango#How_do_I_dynamically_set_the_text_in_a_pango_layout.3F | regularly update the time displayed on a pango layout object]].  
+
You can see a more substantive example of this pattern in use when we [[olpc:Pango#How_do_I_dynamically_set_the_text_in_a_pango_layout.3F | regularly update the time displayed on a pango layout object]].  
    
<pre>
 
<pre>
Line 239: Line 255:  
There are several pages that give you instructions on how to install/update your current build.  
 
There are several pages that give you instructions on how to install/update your current build.  
   −
* If you already have a working build installed and an internet connection, first try [[olpc-update]].  
+
* If you already have a working build installed and an internet connection, first try [[olpc:olpc-update]].  
* If that doesn't work, you can look at instructions for an [[Activated upgrade]] that can be done via USB] boot.  
+
* If that doesn't work, you can look at instructions for an [[olpc:Activated upgrade]] that can be done via USB] boot.  
    
As the instructions on the pages linked above note, make sure to install your activities separately after you have upgraded to a specific base build.
 
As the instructions on the pages linked above note, make sure to install your activities separately after you have upgraded to a specific base build.
Line 247: Line 263:  
=== I am developing on an XO laptop, but my keyboard and language settings are not ideal. How can I change them? ===
 
=== I am developing on an XO laptop, but my keyboard and language settings are not ideal. How can I change them? ===
   −
Internationalized laptops will often have settings that might slow you down while developing. To change around the language settings so you can better understand environment messages, use the [[Sugar Control Panel]]
+
Internationalized laptops will often have settings that might slow you down while developing. To change around the language settings so you can better understand environment messages, use the [[olpc:Sugar Control Panel]]
   −
Keyboard settings on internationalized laptops<ref>[[Keyboard layouts#OLPC keyboard layouts]]</ref> can also be suboptimal, especially as characters like "-" and "/" are in unfamiliar positions. You can use the <tt>setxkbmap</tt> command in the [[Terminal Activity]] to reset the type of keyboard input used and then attach a standard U.S. keyboard that will allow you to type normally. The command below sets the keyboard to the US mapping (it will reset to the default internationalized mapping upon restart).  
+
Keyboard settings on internationalized laptops<ref>[[olpc:Keyboard layouts#OLPC keyboard layouts]]</ref> can also be suboptimal, especially as characters like "-" and "/" are in unfamiliar positions. You can use the <tt>setxkbmap</tt> command in the [[olpc:Terminal Activity]] to reset the type of keyboard input used and then attach a standard U.S. keyboard that will allow you to type normally. The command below sets the keyboard to the US mapping (it will reset to the default internationalized mapping upon restart).  
    
  setxkbmap us
 
  setxkbmap us
Line 267: Line 283:     
     def announce_thread(self):
 
     def announce_thread(self):
         while (self.Running):
+
         while self.Running:
 
             time.sleep(1)
 
             time.sleep(1)
 
             print "thread running"
 
             print "thread running"
Line 312: Line 328:  
<pre>
 
<pre>
 
         if self.metadata['mime_type'] == 'text/plain':
 
         if self.metadata['mime_type'] == 'text/plain':
             if not self._jobject.metadata['title_set_by_user'] == '1':
+
             if self._jobject.metadata['title_set_by_user'] != '1':
 
                 if self._browser.props.title:
 
                 if self._browser.props.title:
 
                     # Set the title of this activity to be the current  
 
                     # Set the title of this activity to be the current  
Line 345: Line 361:  
         keyname = gtk.gdk.keyval_name(event.keyval)
 
         keyname = gtk.gdk.keyval_name(event.keyval)
 
          
 
          
         if (keyname == 'KP_Page_Up'):
+
         if keyname == 'KP_Page_Up':
 
             self._chat += "\nCircle Pressed!"
 
             self._chat += "\nCircle Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
         elif (keyname == 'KP_Page_Down'):
+
         elif keyname == 'KP_Page_Down':
 
             self._chat += "\nX Pressed!"
 
             self._chat += "\nX Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
         elif (keyname == 'KP_Home'):
+
         elif keyname == 'KP_Home':
 
             self._chat += "\nSquare Pressed!"
 
             self._chat += "\nSquare Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
         elif (keyname == 'KP_End'):
+
         elif keyname == 'KP_End':
 
             self._chat += "\nCheck Pressed!"
 
             self._chat += "\nCheck Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
   −
         return False;
+
         return False
 
</pre>
 
</pre>
    +
== How do I know if the screen has been rotated? ==
 +
 +
When the screen is rotated, GTK issues a CONFIGURE event. Test for this event and grab the screen dimensions in the event handler.
 +
 +
        self.window.add_events(gtk.gdk.CONFIGURE)
 +
        self.window.connect('configure-event', self._configure_cb)
 +
 +
    def _configure_cb(self, win, event):
 +
        width = gtk.gdk.screen_width()
 +
        height = gtk.gdk.screen_height()
 +
 +
This does not tell you the orientation, however. Allegedly on the XO hardware, you can use olpc-kbdshim (currently undocumented).
    
=== How do I detect if one of the joystick buttons has been pressed? ===
 
=== How do I detect if one of the joystick buttons has been pressed? ===
Line 378: Line 406:  
         keyname = gtk.gdk.keyval_name(event.keyval)
 
         keyname = gtk.gdk.keyval_name(event.keyval)
 
          
 
          
         if (keyname == 'KP_Up'):
+
         if keyname == 'KP_Up':
 
             self._chat += "\nUp Pressed!"
 
             self._chat += "\nUp Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
         elif (keyname == 'KP_Down'):
+
         elif keyname == 'KP_Down':
 
             self._chat += "\nDown Pressed!"
 
             self._chat += "\nDown Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
         elif (keyname == 'KP_Left'):
+
         elif keyname == 'KP_Left':
 
             self._chat += "\nLeft Pressed!"
 
             self._chat += "\nLeft Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
         elif (keyname == 'KP_Right'):
+
         elif keyname == 'KP_Right':
 
             self._chat += "\nRight Pressed!"
 
             self._chat += "\nRight Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
Line 394: Line 422:  
</pre>
 
</pre>
   −
=== How do i remove an specific button from the toolbar? ===
+
=== How do I remove a specific button from the toolbar? ===
    
This is an example of the share button is removed:
 
This is an example of the share button is removed: