Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ToasterActivity.py
blob: 24f886d4d83ce6f0217db5dad74bebb920d0b70e (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Copyright (c) 2007 Mitchell N. Charity
# Copyright (c) 2009, Walter Bender
# Copyright (c) 2009,2010, Grant Bowman
#
# This file is part of Toaster.
#
# Toaster 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 3 of the License, or
# (at your option) any later version.
#
# Toaster 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 Toaster.  If not, see <http://www.gnu.org/licenses/>

""" Toaster Activity: create USB sticks (like Sugar on a Stick) and create a CD or DVD disc from an .iso image using a kiosk targeted user interface """

import pygtk
pygtk.require('2.0')
import gtk
import gobject
import cairo
import os.path

import sugar
from sugar.activity import activity
#try: # 0.86+ toolbar widgets
#    from sugar.bundle.activitybundle import ActivityBundle
#    from sugar.activity.widgets import ActivityToolbarButton
#    from sugar.activity.widgets import StopButton
#    from sugar.graphics.toolbarbox import ToolbarBox
#    from sugar.graphics.toolbarbox import ToolbarButton
#except ImportError:
#    pass
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.menuitem import MenuItem
from sugar.graphics.icon import Icon
from sugar.datastore import datastore
#try:
#    from sugar.graphics import style
#    GRID_CELL_SIZE = style.GRID_CELL_SIZE
#except:
GRID_CELL_SIZE = 0

import logging
_logger = logging.getLogger("toaster-activity")

from gettext import gettext as _

#import __

#
# Sugar activity
#
class ToasterActivity(activity.Activity):
    """ToasterActivity class as specified in activity.info"""

    def __init__(self, handle):
        """Setup the Toaster Activity."""
        super(ToasterActivity,self).__init__(handle)

        _font = 'helvetica 12'
        _font_bold = 'helvetica bold 12'

        #
        # We need a canvas
        #
        label = gtk.Label(_("Share Software"))
        self.set_canvas(label)
        label.show()

        _width = gtk.gdk.screen_width()
        _height = gtk.gdk.screen_height()-GRID_CELL_SIZE

        # add button detection
        self.connect('key-press-event', self._keyPressCb)

        # Read the dpi from the Journal
        try:
            dpi = self.metadata['dpi']
            _logger.debug("Read dpi: " + str(dpi))
            self._canvas.set_dpi(int(dpi))
        except:
            if os.path.exists('/sys/power/olpc-pm'):
                self._canvas.set_dpi(200) # OLPC XO
                # won't work for XO-1.5 - maybe see if /etc/olpc-release exists
                # decent _get_hardware() function in Measure.activity/measure.py
            else:
                self._canvas.set_dpi(100) # Just a guess

        # no collaboration features yet
        self.max_participants = 1

        #
        # We need some toolbars
        #
        #try:
        #    # Use 0.86 toolbar design
        #    toolbar_box = ToolbarBox()
        #
        #    # Buttons added to the Activity toolbar
        #    activity_button = ActivityToolbarButton(self)
        #    toolbar_box.toolbar.insert(activity_button, 0)
        #    activity_button.show()
        #
        #    # my buttons
        #
        #    share_button = ShareButton(self)
        #    toolbar_box.toolbar.insert(share_button, -1)
        #    share_button.show()
        #
        #    keep_button = KeepButton(self)
        #    toolbar_box.toolbar.insert(keep_button, -1)
        #    keep_button.show()
        #
        #    separator = gtk.SeparatorToolItem()
        #    separator.props.draw = False
        #    separator.set_expand(True)
        #    separator.show()
        #    toolbar_box.toolbar.insert(separator, -1)
        #
        #    # The ever-present Stop Button
        #    stop_button = StopButton(self)
        #    stop_button.props.accelerator = '<Ctrl>Q'
        #    toolbar_box.toolbar.insert(stop_button, -1)
        #    stop_button.show()
        #
        #    self.set_toolbar_box(toolbar_box)
        #    toolbar_box.show()
        #
        #except NameError:
        # Use pre-0.86 toolbar design
        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)

        self.projectToolbar = ProjectToolbar(self)
        toolbox.add_toolbar( _('Toaster'), self.projectToolbar )

        toolbox.show()
        toolbox.set_current_toolbar(1)
        # end of future pre-0.86 except block


        self.show_all()

    # 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!" # needs function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Page_Down'):
           self._chat += "\nX Pressed!" # needs function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Home'):
           self._chat += "\nSquare Pressed!" # needs function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_End'):
           self._chat += "\nCheck Pressed!" # needs function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Up'):
           self._chat += "\nUp Pressed!" # needs function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Down'):
           self._chat += "\nDown Pressed!" # needs function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Left'):
           self._chat += "\nLeft Pressed!" # needs function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Right'):
           self._chat += "\nRight Pressed!" # needs function
           self._chat_buffer.set_text(self._chat)

        return False

#    def read_file(self, filename):
#        "Read the journal item"
#    def write_file(self, filename):
#        "Save meta data for the journal item"

#
# Project toolbar for pre-0.86 toolbars
#
class ProjectToolbar(gtk.Toolbar):

    def __init__(self, pc):
        gtk.Toolbar.__init__(self)
        self.activity = pc