# 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
""" 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 = '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 = 'C'
editbar.paste.connect('clicked', self._paste_cb)
editbar.paste.props.accelerator = '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 = 'S'
activity_toolbar.stop.props.accelerator = '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()