Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ToasterActivity.py
blob: 3f34724ed9cb6616d92b83dbcb8042b40cb57692 (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# 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 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

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."""
        activity.Activity.__init__(self, handle)
        self.set_title(_('Toaster Activity'))
        self._logger = logging.getLogger("toaster-activity")
        self.chosenImage  = 'hard_coded'
        self.chosenTarget = 'hard_coded'

        # initial button to move to the next screen
        # self.button = gtk.Button(_('Choose Target'))
        # self.button.connect('clicked', self.chooseTarget, None))

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

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

        # 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.set_canvas.set_dpi(200) # OLPC XO, error when setting - TODO fix
                # 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
        # add the toolbox to the activity frame
        toolbox = activity.ActivityToolbox(self)

        editbar = activity.EditToolbar()
        editbar.undo.props.visible = False
        editbar.redo.props.visible = False
        editbar.separator.props.visible = False
        editbar.copy.connect('clicked', self._copy_cb)
        editbar.copy.props.accelerator = '<Ctrl><Shift>C'
        editbar.paste.connect('clicked', self._paste_cb)
        editbar.paste.props.accelerator = '<Ctrl><Shift>V'
        toolbox.add_toolbar(_('Edit'), editbar)
        editbar.show()

        choosebtn = sugar.graphics.toolbutton.ToolButton('choose')
        choosebtn.set_tooltip(_('Image/Target'))
        #choosebtn.connect('clicked', self._chooseImage())

        tabsep = gtk.SeparatorToolItem()
        tabsep.set_expand(True)
        tabsep.set_draw(False)

        createcopybtn = sugar.graphics.toolbutton.ToolButton('toaster')
        createcopybtn.set_tooltip(_('Create Copy'))
        #createcopybtn.connect('clicked', self._createCopy())

        createbar = gtk.Toolbar()
        createbar.insert(tabsep, -1)
        createbar.insert(createcopybtn, -1)
        createbar.show_all()
        toolbox.add_toolbar(_('Create'), createbar)

        activity_toolbar = toolbox.get_activity_toolbar()
        activity_toolbar.share.props.visible = False
        activity_toolbar.keep.props.visible = False
        activity_toolbar.keep.props.accelerator = '<Ctrl><Shift>S'
        activity_toolbar.stop.props.accelerator = '<Ctrl><Shift>Q'
        activity_toolbar.share.hide()
        activity_toolbar.keep.hide()

        self.set_toolbox(toolbox)

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

        self.notebook = gtk.Notebook()
        self.notebook.set_property("tab-pos", gtk.POS_BOTTOM)
        self.notebook.set_scrollable(True)
        self.notebook.show()

        self.show_all()

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


    # Method _keyPressEventCb, which catches any presses of the game buttons.
    def _keyPressEventCb(self, widget, event):
        keyname = gtk.gdk.keyval_name(event.keyval)
        if (keyname == 'KP_Page_Up'):
           self._chat += "\nCircle Pressed!" # ? needs "Back" function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Page_Down'):
           self._chat += "\nX Pressed!" # ? needs "Forward" function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Home'):
           self._chat += "\nSquare Pressed!" # needs "Back" function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_End'):
           self._chat += "\nCheck Pressed!" # needs "Forward" function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Up'):
           self._chat += "\nUp Pressed!" # ? needs "Back" function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Down'):
           self._chat += "\nDown Pressed!" # ? needs "Forward" function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Left'):
           self._chat += "\nLeft Pressed!" # needs "Back" function
           self._chat_buffer.set_text(self._chat)
        elif (keyname == 'KP_Right'):
           self._chat += "\nRight Pressed!" # needs "Forward" function
           self._chat_buffer.set_text(self._chat)

        return False

#    def read_file(self, filename):
#        "Read journal data" unpickle histories
#    def write_file(self, filename):
#        "Save journal data" unpickle histories
#    def can_close(self):
#        "Make sure no burn is in progress before closing Activity"
#    def handle_view_source(self):
#        "not many Activities implement this"
#    def _chooseImage(self):
#        ""
        # forward
        # self.button = gtk.Button(_('Choose Target'))
        # self.button.connect('clicked', self.chooseTarget, None))
#    def _chooseTarget(self):
#        ""
        # back
        # self.button = gtk.Button(_('Choose Image'))
        # self.button.connect('clicked', self.chooseImage, None))
        # forward
        # self.button = gtk.Button(_('Begin Creation'))
        # self.button.connect('clicked', self.chooseCreation, None))
#    def _createCopy(self):
#        ""
        # back
        # self.button = gtk.Button(_('Choose Target'))
        # self.button.connect('clicked', self.chooseTarget, None))

    def _copy_cb(self, buttom):
        vt = self.notebook.get_nth_page(self.notebook.get_current_page()).vt
        if vt.get_has_selection():
            vt.copy_clipboard()

    def _paste_cb(self, buttom):
        vt = self.notebook.get_nth_page(self.notebook.get_current_page()).vt
        vt.paste_clipboard()