Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Launcher.py
blob: ce6893c997887d282f2337fb2deaac7dff05dce5 (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
# Launcher.py    Launches the program in Sugar environment
#
# Copyright (C) 2011 Laurent BERNABE
#
# 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

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()