Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
blob: e73dcdb2d28c798f6ed44f9587cf9ad9d06f3b5f (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- coding: UTF-8 -*-
# Copyright 2007-2008 One Laptop Per Child
# Copyright 2007 Gerard J. Cerchio <www.circlesoft.com>
# Copyright 2008 Andrés Ambrois <andresambrois@gmail.com>
# Copyright 2010 Marcos Orfila <www.marcosorfila.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import logging
import sugar.logger
import gtk
import pygtk
from gettext import gettext as _
from sugar.activity.activity import Activity, ActivityToolbox
import pango
import os
import commands
import sys


logger = logging.getLogger('JRE')


class JreActivity(Activity):

    # Folder where the JRE has been unpacked
    jre_folder = "jre"


    def __init__(self, handle):
        # Initialize the parent
        Activity.__init__(self, handle)
        logger.debug('Initiating JRE')
     
   
        
        # Set the activity toolbox
        toolbox = ActivityToolbox(self)
        self.set_toolbox(toolbox)

        self.ceibaljam_icon_path = os.getenv("SUGAR_BUNDLE_PATH") + "/images/ceibaljam.png"

	#
	# There's a good explanation of the use of boxes in PyGTK here:
	# http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html
	#
 
        box_canvas = gtk.VBox(False, 0)
        self.set_canvas(box_canvas)


        # Title

        box_title = gtk.VBox(False, 0)
        label_title = gtk.Label(_("Java Runtime Environment"))
        label_title.set_justify(gtk.JUSTIFY_CENTER)
        label_title.modify_font(pango.FontDescription("Arial 18"))
        label_copyright1 = gtk.Label(_("Copyright © 2010 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,"))
        label_copyright2 = gtk.Label(_("California 95054, U.S.A.  All rights reserved."))
        label_copyright1.set_justify(gtk.JUSTIFY_CENTER)
        label_copyright2.set_justify(gtk.JUSTIFY_CENTER)

        box_title.add(gtk.Label(""))
        box_title.add(gtk.Label(""))
        box_title.add(label_title)
        box_title.add(gtk.Label(""))
        box_title.add(gtk.Label(""))
        box_title.add(label_copyright1)
        box_title.add(label_copyright2)
        box_title.add(gtk.Label(""))

	# Version

        box_version = gtk.VBox(False, 0)
        #label_version_title = gtk.Label(_("Version information"))
        #label_version_title.modify_font(pango.FontDescription("Arial 12"))
        #label_version_title.set_justify(gtk.JUSTIFY_LEFT)
        version_information = commands.getoutput(os.path.dirname(os.path.abspath(__file__)) + "/" + self.jre_folder + "/bin/java -version")
        label_version_info = gtk.Label(version_information)
        label_version_info.set_justify(gtk.JUSTIFY_CENTER)

        #box_version.add(gtk.Label(""))
        #box_version.add(box_version_title)
        box_version.add(gtk.Label(""))
        box_version.add(label_version_info)
        box_version.add(gtk.Label(""))

	# Usage explanation

        box_usage = gtk.VBox(False, 0)
        label_usage1 = gtk.Label(_("To use this JRE in your activity, add the following line to your script:"))
        label_usage2 = gtk.Label('<b>PATH=/home/olpc/Activities/Java.activity/' + self.jre_folder + '/bin:$PATH</b>')
        label_usage2.set_use_markup(True)
        label_usage1.set_justify(gtk.JUSTIFY_CENTER)
        label_usage2.set_justify(gtk.JUSTIFY_CENTER)
        box_usage.add(gtk.Label(""))
        box_usage.add(label_usage1)
        box_usage.add(label_usage2)
        box_usage.add(gtk.Label(""))

        # Credits

        box_credits = gtk.VBox(False, 0)
        box_credits.add(gtk.Label(""))
        box_credits.add(gtk.Label(_('Sugarized by %(THE_AUTHOR)s') % { 'THE_AUTHOR': 'Marcos Orfila' }))
        label_my_website = gtk.Label('<b>http://www.marcosorfila.com</b>')
        label_my_website.set_use_markup(True)
        box_credits.add(label_my_website)
        box_credits.add(gtk.Label(""))

        # Footer box (Activities on CeibalJAM! website)

        box_footer = gtk.VBox(False, 0)
        box_footer.add(gtk.Label(""))
        box_footer.add(gtk.Label(_('Find more activities on %(CEIBALJAM)s website:') % { 'CEIBALJAM': 'CeibalJAM!'}))
        label_ceibaljam_website = gtk.Label('<b>http://activities.ceibaljam.org</b>')
        label_ceibaljam_website.set_use_markup(True)
        box_footer.add(label_ceibaljam_website)
        box_footer.add(gtk.Label(""))

        # CeibalJAM! image

        box_ceibaljam_image = gtk.VBox(False, 0)
        image_ceibaljam = gtk.Image()
        image_ceibaljam.set_from_file(self.ceibaljam_icon_path)
        box_ceibaljam_image.pack_end(image_ceibaljam, False, False, 0)


	# Get all the boxes together

        box_canvas.pack_start(box_title, False, False, 0)
        box_canvas.pack_start(box_version, False, False, 0)
        box_canvas.pack_start(box_usage, False, False, 0)
        box_canvas.pack_end(box_footer, False, False, 0)
        box_canvas.pack_end(box_ceibaljam_image, False, False, 0)
        box_canvas.pack_end(box_credits, False, False, 0)




        # Test to show some environment variables
        """
        box_footer = gtk.VBox(False, 0)
        box_footer.add(gtk.Label(""))
        box_footer.add(gtk.Label("TUXMATH_SCRIPT = '" + os.getenv("TUXMATH_SCRIPT") + "'"))
        box_footer.add(gtk.Label(""))
        box_canvas.pack_end(box_footer, False, False, 0)
        """

        self.show_all()