Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/OficinaActivity.py
blob: 6e9dea7129504bd41ab5d7a989ecfc2600a8a238 (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
# -*- coding: utf-8 -*-
"""
OficinaActivity.py

Create Oficina Activity


Copyright 2007, NATE-LSI-EPUSP

Oficina is developed in Brazil at Escola Politécnica of 
Universidade de São Paulo. NATE is part of LSI (Integrable
Systems Laboratory) and stands for Learning, Work and Entertainment
Research Group. Visit our web page: 
www.lsi.usp.br/nate
Suggestions, bugs and doubts, please email oficina@lsi.usp.br

Oficina 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 version 2 of 
the License.

Oficina 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 Oficina; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 
Boston, MA  02110-1301  USA.
The copy of the GNU General Public License is found in the 
COPYING file included in the source distribution.


Authors:

Joyce Alessandra Saul               (joycealess@gmail.com)
Andre Mossinato                     (andremossinato@gmail.com)
Nathalia Sautchuk Patrício          (nathalia.sautchuk@gmail.com)
Pedro Kayatt                        (pekayatt@gmail.com)
Rafael Barbolo Lopes                (barbolo@gmail.com)
Alexandre A. Gonçalves Martinazzo   (alexandremartinazzo@gmail.com)

Colaborators:
Bruno Gola                          (brunogola@gmail.com)

Group Manager:
Irene Karaguilla Ficheman           (irene@lsi.usp.br)

Cientific Coordinator:
Roseli de Deus Lopes                (roseli@lsi.usp.br)

"""


import os
from gettext import gettext as _

import gtk

from sugar.activity import activity

from toolbox import Toolbox
from Area import Area
import logging

class OficinaActivity(activity.Activity):
    def __init__(self, handle):
        """Initialize the OficinaActivity object.

            Keyword arguments:
            self -- 
            handle --

        """
        activity.Activity.__init__(self, handle)
        self.set_title(_('Paint'))
        
        logging.debug('Starting Paint activity (Oficina)')

        os.chdir(activity.get_bundle_path())
        #print activity.get_bundle_path()
        
        self._fixed = gtk.Fixed()   
        self._area = Area(self) 
        
        toolbox = Toolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()       
  

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        
        color = gtk.gdk.color_parse("white")
        self._fixed.modify_bg(gtk.STATE_NORMAL, color)

        self.bg = gtk.Image()
        self.bg.set_from_file('./icons/bg.svg')
        self._fixed.put(self.bg, 200, 100)
        self.bg.show()

        #FIXME: use a textview instead of an Entry
        self._textview = gtk.TextView()
        # If we use this, text viewer will have constant size, we don't want that
        #self._textview.set_size_request(100,100)
        #self._textview = gtk.Entry()
        
        self._fixed.put(self._area, 200 , 100)
        # Area size increased
        #self._fixed.put(self._area, 0 , 0)
        
        sw.add_with_viewport(self._fixed)
        self._area.show()
        self._fixed.show()


        self._fixed.put(self._textview, 0, 0)
        self._textview.hide()
        sw.show()

        # setting scrolledwindow as activity canvas...
        self.set_canvas(sw)
        
        # Setting a default tool
        self._area.tool = 'pencil'

    def read_file(self, file_path):
        '''Read file from Sugar Journal.

        self --
        file_path --

        '''
        logging.debug('reading file %s', file_path)
#         logging.debug(file_path)
        
        self._area.loadImage(file_path, self._area, False)
        
        # Does this work?
#         self._area.undo_times = 1
#         self._area.redo_times = 0


    def write_file(self, file_path):
        '''Save file on Sugar Journal.

        self --
        file_path -- 

        '''
        logging.debug('saving as PNG')
        logging.debug('writting file %s', file_path)
        
        width, height = self._area.window.get_size()
        pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
        pixbuf.get_from_drawable(self._area.pixmap, gtk.gdk.colormap_get_system(), 0, 0, 0, 0, -1, -1)
        self.metadata['mime_type'] = 'image/png'
        pixbuf.save(file_path, 'png', {})