Changes

Jump to navigation Jump to search
Line 216: Line 216:     
In SimCity, I have tested this to make sure it works in the *old* XO software releases as well as the new ones.  The documentation for these threads_init functions is really bad, and doesn't say whether you can call them twice, nor does it say how you can tell if they've already been called so you could avoid calling them twice.  Apparently it's pretty harmless in release 650.
 
In SimCity, I have tested this to make sure it works in the *old* XO software releases as well as the new ones.  The documentation for these threads_init functions is really bad, and doesn't say whether you can call them twice, nor does it say how you can tell if they've already been called so you could avoid calling them twice.  Apparently it's pretty harmless in release 650.
 +
 +
 +
=== How do I customize the title that is displayed for each instance of my activity? ===
 +
 +
By default, activity titles are just the generic activity names that you specify in your activity.info file. In some applications, you may want the activity title to be more dynamic.
 +
 +
For example, it makes sense to set the title for different browser sessions to the active web page being visited. That way, when you look back in the journal at the different browser sessions you have run in the previous few days, you can identify unique sessions based on the website you happened to be visiting at the time.
 +
 +
The code below shows how you can set the metadata for your activity to reflect a dynamic title based on whatever session criteria you feel is important. This example is adapted from the Browse activity, which sets activity instance titles based on the title of the current web page being visited.
 +
 +
<pre>
 +
        if self.metadata['mime_type'] == 'text/plain':
 +
            if not self._jobject.metadata['title_set_by_user'] == '1':
 +
                if self._browser.props.title:
 +
                    # Set the title of this activity to be the current
 +
                    # title of the page being visited by the browser.
 +
                    self.metadata['title'] = self._browser.props.title
 +
</pre>
 +
 +
=== What packages are available on sugar to support game development? ===
 +
 +
If your activity will require tools that are typically needed to develop robust and clean video games, then you should utilize the [http://www.pygame.org/ pygame package]. It can be readily imported into any activity:
 +
 +
<pre>
 +
import pygame
 +
...
 +
</pre>
 +
 +
=== How do I detect when one of the game buttons on the laptop have been pressed? ===
 +
 +
The laptop game buttons (the circle, square, x, and check buttons next to the LCD) are encoded as page up, home, page down and end respectively. So, you can detect their press by listening for these specific events. For example, the code below listens for button presses and then just writes to an output widget which button was pressed.
 +
 +
<pre>
 +
...
 +
    #### Initialize this activity.
 +
    def __init__(self, handle):
 +
        ...
 +
        self.connect('key-press-event', self._keyPressCb)
 +
        ...
 +
 +
    #### Method _keyPressCb, which catches any presses of the game buttons.
 +
    def _keyPressCb(self, widget, event):
 +
 +
        keyname = gtk.gdk.keyval_name(event.keyval)
 +
       
 +
        if (keyname == 'KP_Page_Up'):
 +
            self._chat + "\nCircle Pressed!"
 +
            self._chat_buffer.set_text(self._chat)
 +
        elif (keyname == 'KP_Page_Down'):
 +
            self._chat + "\nX Pressed!"
 +
            self._chat_buffer.set_text(self._chat)
 +
        elif (keyname == 'KP_Home'):
 +
            self._chat + "\nSquare Pressed!"
 +
            self._chat_buffer.set_text(self._chat)
 +
        elif (keyname == 'KP_End'):
 +
            self._chat + "\nCheck Pressed!"
 +
            self._chat_buffer.set_text(self._chat)
 +
 +
        return False;
 +
</pre>
    
== Notes ==
 
== Notes ==
Anonymous user

Navigation menu