Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
blob: 078fcdb752e83f8185966a5e12a1a508f2c350fc (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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# QReader
# Copyright (C) 2011, 2012, Alan Aguiar
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
# Contact information:
# Alan Aguiar <alanjas@gmail.com>

import os
import sys
import gtk
sys.path.insert(0, "lib")
import pygame
import pygame.camera
import sugargame
import sugargame.canvas
from sugar.activity import activity
try:
    from sugar.graphics.toolbarbox import ToolbarBox
    from sugar.graphics.toolbutton import ToolButton
    from sugar.activity.widgets import ActivityToolbarButton
    from sugar.activity.widgets import StopButton
    have_toolbox = True
except ImportError:
    have_toolbox = False


from sugar.datastore import datastore

from gettext import gettext as _

import qreader

class Activity(activity.Activity):

    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        self.actividad = qreader.QReader(self)

        self.build_toolbar()
        self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
        self.set_canvas(self._pygamecanvas)
        self._pygamecanvas.run_pygame(self.actividad.run)

    def build_toolbar(self):


        if have_toolbox:
            toolbox = ToolbarBox()
            activity_button = ActivityToolbarButton(self)
            toolbox.toolbar.insert(activity_button, -1)
            activity_button.show()

            pano_toolbar = toolbox.toolbar

        else:
            games_toolbar = gtk.Toolbar()
            toolbox = activity.ActivityToolbox(self)
            self.set_toolbox(toolbox)
            toolbox.add_toolbar(_('Panorama'), games_toolbar)
            
            #toolbox.set_current_toolbar(1)
            pano_toolbar = games_toolbar
		

        new_button = ToolButton('stock_refresh')
        new_button.set_tooltip("New Panorama")
        new_button.connect('clicked', self.new_event)
        pano_toolbar.insert(new_button, -1)
        new_button.show()

        capture_button = ToolButton('add_capture')
        capture_button.set_tooltip("Add a capture to the Panorama")
        capture_button.connect('clicked', self.capture_event)
        pano_toolbar.insert(capture_button, -1)
        capture_button.show()

        stitch_button = ToolButton('format-columns-triple')
        stitch_button.set_tooltip("Stitch Panorama")
        stitch_button.connect('clicked', self.stitch_event)
        pano_toolbar.insert(stitch_button, -1)
        stitch_button.show()

        save_button = ToolButton('filesave')
        save_button.set_tooltip("Save Panorama")
        save_button.connect('clicked', self.save_event)
        pano_toolbar.insert(save_button, -1)
        save_button.show()


        if have_toolbox:
            separator = gtk.SeparatorToolItem()
            separator.props.draw = True
            separator.set_expand(True)
            pano_toolbar.insert(separator,5)
            #toolbox.toolbar.props.page.insert(separator, -1)

            stop_button = StopButton(self)
            stop_button.props.accelerator = '<Ctrl>q'
            pano_toolbar.insert(stop_button, 6)
            stop_button.show()

        #else:
            #caja.add_toolbar("Panoramas", pano_toolbar)
		
		    #caja.show()
		    #self.set_toolbox(toolbox)

		    #caja.show_all()
		    #self.set_toolbox(caja)

		    # que hace esto

		    #caja.set_current_toolbar(1)
        pano_toolbar.show()
        self.set_toolbar_box(toolbox)
        toolbox.show()


    def save_image(self,image):
        journalobj = datastore.create()
        journalobj.metadata['title'] = 'Panorama'
        journalobj.metadata['mime_type'] = 'image/jpeg'

        #file_path = os.path.join(olpcgames.ACTIVITY.get_activity_root(),'instance','panorama.jpg')

        file_path = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'], 'data', 'panorama.jpg')

        pygame.image.save(image,file_path)
        journalobj.set_file_path(file_path)
        datastore.write(journalobj)

        journalobj.destroy()

    def save_event(self,widget):
        pygame.event.post(pygame.event.Event(pygame.USEREVENT, action='save_button'))

    def new_event(self,widget):
        pygame.event.post(pygame.event.Event(pygame.USEREVENT, action='new_button'))

    def capture_event(self,widget):
        pygame.event.post(pygame.event.Event(pygame.USEREVENT, action='capture_button'))

    def stitch_event(self,widget):
        pygame.event.post(pygame.event.Event(pygame.USEREVENT, action='stitch_button'))