# Launcher.py Launches the program in Sugar environment # #This file is part of LearningWriting. # #LearningWriting 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. # #LearningWriting 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 LearningWriting. If not, see . from gettext import gettext as _ from sugar.activity import activity from MenuActions import MenuActions from TheDrawingAreaEventBox import TheDrawingAreaEventBox import pygtk pygtk.require('2.0') import gtk class Launcher(activity.Activity): ''' Launcher for sugar bundle ''' def __init__(self, handle): ''' Constructor ''' activity.Activity.__init__(self, handle) # Be carefull on the callings order !!! # => self.__wrapped_drawing_area is not defined before # self.__createAndSetCanvas() call # => self.__createAndSetToolbox need self.__menu_actions self.__createAndSetCanvas() self.__menu_actions = MenuActions(self.__wrapped_drawing_area) self.__createAndSetToolbox() def __createAndSetToolbox(self): ''' Creates and sets the tool box ''' toolbox = activity.ActivityToolbox(self) self.__addDrawingToolbarIn(toolbox) self.set_toolbox(toolbox) toolbox.show_all() def __createAndSetCanvas(self): ''' Creates and set the Canvas ''' self.__wrapped_drawing_area = TheDrawingAreaEventBox() self.set_canvas(self.__wrapped_drawing_area) self.show_all() def __manageDrawingWrite(self, menu_item): ''' Manages drawing->write menu ''' if menu_item.get_active() : self.__menu_actions.manageDrawingWrite() def __manageDrawingRead(self, menu_item): ''' Manages drawing->read menu ''' if menu_item.get_active() : self.__menu_actions.manageDrawingRead() def __addDrawingToolbarIn(self, toolbox): ''' Creates and add Drawing toolbar in toolbox => __addDrawingToolbarIn(toolbox) ''' drawing_toolbar = gtk.Toolbar() drawing_toolbar.set_style(gtk.TOOLBAR_ICONS) #---------------------- drawing_toolbar_write_button = gtk.RadioToolButton(None, gtk.STOCK_MEDIA_RECORD) drawing_toolbar_write_button.set_active(True) drawing_toolbar_write_button.connect("clicked", self.__manageDrawingWrite ) drawing_toolbar.insert(drawing_toolbar_write_button, 0) #--------------------- drawing_toolbar_read_button = gtk.RadioToolButton(drawing_toolbar_write_button, gtk.STOCK_MEDIA_PLAY) drawing_toolbar_read_button.set_active(False) drawing_toolbar_read_button.connect("clicked", self.__manageDrawingRead ) drawing_toolbar.insert(drawing_toolbar_read_button, 1) #-------------------- toolbox.add_toolbar(_('Drawing'), drawing_toolbar) drawing_toolbar.show_all() def read_file(self, file_path): ''' Manages sugar activity resume from entry journal ''' read_text_file = open(file_path, 'r') self.__wrapped_drawing_area.readFiguresFromTextFile(read_text_file) read_text_file.close() def write_file(self, file_path): ''' Manages sugar activity journal entry updating ''' self.metadata['mime_type'] = 'application/x-graph' saved_text_file = open(file_path, 'w') self.__wrapped_drawing_area.saveFiguresInTextFile(saved_text_file) saved_text_file.close()