Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/exercises/en/Exercise20.activity/exercise20.py
blob: 766f4539cc94897928890710110ffd92438a2a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding=utf-8

"""Package a Sugar activity to produce a bundle.

Below is a simple Sugar activity which displays a static image. It is very
boring, but does not need changing. In this exercise, you must add the relevant
files to git and then build a bundle for the activity and install it on a
physical XO laptop.

Before packaging the activity, an icon needs to be created.

 1. Open Inkscape and create a new 48×48 pixel icon (‘icon_48x48’ template).
 2. Draw the icon, using only a single stroke colour and a single background
    colour. Save it as activity/activity.svg.
 3. Open the created SVG file with a text editor and replace the stroke colours
    as described in the ‘Create An Icon’ here:
        http://en.flossmanuals.net/make-your-own-sugar-activities/package-the-activity/
 4. Execute the following commands in a terminal open in the
    Exercise20.activity/ directory. They will add the relevant files to git:
        git init
        git status
        git add .gitignore exercise20.py setup.py images/logonew2.png
        git add activity/activity.info
        git add activity/activity.svg
        git status
        git commit
    They create a new git repository in the current directory, check its
    status, add the required files to the repository, check its status again
    to ensure we don’t commit anything we don’t mean to, then commit the new
    files and changes to the repository.

    The .gitignore file is a special file which lists files that git shouldn’t
    allow you to add to the repository, and which will be hidden from the
    output of `git status`.
 5. Run ‘./setup.py dist_xo’ to build an XO bundle.
 6. Copy the dist/Exercise20-1.xo file to a USB stick and install it on a
    physical XO laptop.
"""

from gi.repository import Gtk
from sugar3.activity import activity, widgets
from sugar3.graphics.toolbarbox import ToolbarBox
import os


class Exercise20Activity(activity.Activity):
    """A simple window which displays a static image."""
    def __init__(self, handle):
        super(Exercise20Activity, self).__init__(handle)

        # Create the standard activity toolbox.
        toolbar_box = ToolbarBox()
        self.set_toolbar_box(toolbar_box)
        toolbar_box.show()

        main_toolbar = toolbar_box.toolbar

        activity_toolbar_button = widgets.ActivityToolbarButton(self)
        main_toolbar.insert(activity_toolbar_button, 0)
        activity_toolbar_button.show()

        stop_button = widgets.StopButton(self)
        stop_button.show()
        main_toolbar.insert(stop_button, -1)

        # Add an image to the window.
        box = Gtk.Box()
        box.show()
        self.set_canvas(box)

        image = Gtk.Image()
        filename = os.path.join(os.path.dirname(__file__),
                                'images', 'logonew2.png')
        image.set_from_file(filename)
        image.show()
        box.pack_start(image, True, True, 8)