This file is indexed.

/usr/share/gcompris/python/braille_fun.py is in gcompris-data 15.02-1.1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#  gcompris - braille_fun.py
#
# Copyright (C) 2011 Srishti Sethi
#
#   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/>.
#
# braille_fun activity.
import gtk
import gtk.gdk
import gcompris
import gobject
import gcompris.utils
import gcompris.skin
import gcompris.sound
import gcompris.bonus
import gcompris.score
import goocanvas
import pango
import random
from BrailleChar import *
from BrailleMap import *
from gcompris import gcompris_gettext as _


class Gcompris_braille_fun:
  """Empty gcompris python class"""


  def __init__(self, gcomprisBoard):
    # Save the gcomprisBoard, it defines everything we need
    # to know from the core
    self.gcomprisBoard = gcomprisBoard
    self.gcomprisBoard.level=1
    self.gcomprisBoard.sublevel=1
    self.gcomprisBoard.number_of_sublevel = 26
    self.gcomprisBoard.maxlevel = 3
    self.text_color = 0X0000FFFFL
    self.counter = 0
    self.timerAnim = 0

    #Boolean variable declaration
    self.mapActive = False

    # These are used to let us restart only after the bonus is displayed.
    # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
    self.board_paused  = 0
    self.gamewon       = False

    #Array declaration
    self.letter_array = []
    self.alphabet_array = []
    self.tile_array = []
    self.tile_index_array = []

    # Needed to get key_press
    gcomprisBoard.disable_im_context = True

  def start(self):
    self.reseted = False
    # Set the buttons we want in the bar
    gcompris.bar_set(gcompris.BAR_LEVEL)
    gcompris.bar_location(300,-1,0.6)
    gcompris.bar_set_level(self.gcomprisBoard)

    #REPEAT ICON
    pixmap = gcompris.utils.load_svg("braille_alphabets/target.svg")
    gcompris.bar_set_repeat_icon(pixmap)
    gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_REPEAT_ICON)
    gcompris.bar_location(300,-1,0.7)

    # Create our rootitem. We put each canvas item in it so at the end we
    # only have to kill it. The canvas deletes all the items it contains
    # automaticaly.
    self.root = goocanvas.Group(parent =
                                    self.gcomprisBoard.canvas.get_root_item())
    #To create a group item for horizontal and vertical text
    self.horizontalTextRoot = goocanvas.Group(parent =
                                    self.gcomprisBoard.canvas.get_root_item())
    self.verticalTextRoot = goocanvas.Group(parent =
                                    self.gcomprisBoard.canvas.get_root_item())

    # The root item for the help
    self.map_rootitem = \
        goocanvas.Group( parent = self.gcomprisBoard.canvas.get_root_item() )
    BrailleMap(self.map_rootitem, self.move_back)
    self.map_rootitem.props.visibility = goocanvas.ITEM_INVISIBLE

    # Display the sublevel
    gcompris.score.start(gcompris.score.STYLE_NOTE, 530, 460,
                         self.gcomprisBoard.number_of_sublevel)

    # Set a background image
    gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
                            "braille_fun/hillside.svg")

    self.display_game(self.gcomprisBoard.level)

  def move_back(self,event,target,item):
    self.map_rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
    self.mapActive = False

  def display_game(self, level):

      gcompris.score.set(self.gcomprisBoard.sublevel)

      self.planeroot = goocanvas.Group( parent =
                                        self.root )
      # SVG Handle for TUX Plane
      svghandle = gcompris.utils.load_svg("braille_fun/plane.svg")
      self.tuxplane = goocanvas.Svg(
                                     parent = self.planeroot,
                                     svg_handle = svghandle,
                                     svg_id = "#PLANE"
                                     )
      self.tuxplane.translate(50 * level, 40 )

      # Animated Tux plane.Move from left to right
      self.planeroot.animate(900,
                             20 ,
                             1,
                             1,
                             True,
                             25000 + level * 9000,
                             100,
                             goocanvas.ANIMATE_FREEZE)

      string = "abcdefghijklmnopqrstuvwxyz"
      for index in range (level):
      	   # Select a random letter and append it to self.letter_array
           if (level == 1):
           	letter = string[self.gcomprisBoard.sublevel - 1]
           elif(level == 2):
           	letter = random.choice(string[random.randint(0, 9)])
           elif(level == 3):
           	letter = random.choice(string[random.randint(10,19)])
           elif(level == 4):
           	letter = random.choice(string[random.randint(20, 25)])
           else :
           	letter = random.choice(string[random.randint(0,25)])

           self.play_letter(letter)
           self.letter_array.append( letter.upper() )

           # Defining Object to BrailleChar Instance to produce braille_tile
           self.tile_array.append( \
               BrailleChar(self.root,
                           300 + 90 * index , 150, 80,
                           '', 0xFF0000FFL, 0xFFFFFFFFL,
                           "white", "black",
                           True, True, True, callback = self.letter_change) )

      # Display alphabets for TUX_PLANE horizontally and vertically
      animateString = "".join(self.letter_array)
      for index in range( len(animateString) ):
          goocanvas.Text(
            parent = self.planeroot,
            x =  50 * index  ,
            y = 60.0 ,
            text = animateString[index],
            fill_color="black",
            anchor = gtk.ANCHOR_CENTER,
            alignment = pango.ALIGN_CENTER,
            font = gcompris.skin.get_font("gcompris/board/huge")
            )
          self.alphabet_vertical = goocanvas.Text(
                         parent = self.verticalTextRoot,
                         x = 50.0 + 50 * index ,
                         y = 130.0 ,
                         text = animateString[index],
                         fill_color = "black",
                         anchor = gtk.ANCHOR_CENTER,
                         alignment = pango.ALIGN_CENTER,
                         font = gcompris.skin.get_font("gcompris/board/huge")
                         )
          self.alphabet_array.append(self.alphabet_vertical)

      # Animate or move letters vertically
      self.verticalTextRoot.animate( 5,
                                     415,
                                     1,
                                     1,
                                     True,
                                     30000 + level * 5000,
                                     100,
                                     goocanvas.ANIMATE_FREEZE )

      # To call a function when animation finishes
      self.verticalTextRoot.connect("animation-finished", self.animationFinished)


  def letter_change(self, letter):
      self.letter = letter
      for index in range(self.gcomprisBoard.level):
          # Change the text color of alphabet correctly identified in the braille tile
          if (self.tile_array[index].get_letter() == self.letter_array[index]):

              # The user just found this letter, let's play it to give a
              # success feedback
              if self.alphabet_array[index].get_property("fill_color_rgba") != self.text_color:
                self.play_letter(self.letter_array[index])

              self.alphabet_array[index].set_property("fill_color_rgba",
                                                      self.text_color)

          # If an alphabet's color changes to blue the counter is increased
          # and the index number of tile is appended to a self.tile_index_array
          if self.alphabet_array[index].get_property("fill_color_rgba") == self.text_color \
              and index not in self.tile_index_array :
              self.tile_index_array.append(index)
              self.counter +=1

      # If counter equals level number then call a timer_loop
      if (self.counter == self.gcomprisBoard.level) :
          self.timerAnim = gobject.timeout_add(1000, self.timer_loop)

  # This timer loop is to wait for milliseconds before calling a Bonus API
  def timer_loop(self):
    self.gamewon = True
    gcompris.bonus.display(gcompris.bonus.WIN,gcompris.bonus.SMILEY)

  def animationFinished(self, item, status):
      if self.reseted:
        return
      print "animationFinished"
      if (self.counter != self.gcomprisBoard.level) :
          self.gamewon = False
          gcompris.bonus.display(gcompris.bonus.LOOSE,gcompris.bonus.SMILEY)

  def end(self):
    self.reseted = True
    # Remove the root item removes all the others inside it
    self.root.remove()
    self.map_rootitem.remove()
    self.horizontalTextRoot.remove()
    self.verticalTextRoot.remove()
    gcompris.score.end()

  def ok(self):
    pass

  def repeat(self):
      if(self.mapActive):
          self.map_rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
          self.mapActive = False
      else :
          self.map_rootitem.props.visibility = goocanvas.ITEM_VISIBLE
          self.mapActive = True


  def config(self):
    pass

  def key_press(self, keyval, commit_str, preedit_str):
    pass

  def pause(self, pause):
    self.board_paused = pause
    # This is to hide the Repeat board
    if self.mapActive == True:
        self.root.props.visibility = goocanvas.ITEM_INVISIBLE

    if (self.board_paused):
        self.verticalTextRoot.stop_animation()
        self.planeroot.stop_animation()
        return

    self.reset_level()
    if self.gamewon:
      self.increment_level()
    self.gamewon = False
    self.end()
    self.start()

  def reset_level(self):
    self.letter_array = []
    self.tile_array = []
    self.alphabet_array = []
    self.tile_index_array = []
    self.counter = 0

  def increment_level(self):
    self.reset_level()
    self.gcomprisBoard.sublevel += 1
    if(self.gcomprisBoard.sublevel>self.gcomprisBoard.number_of_sublevel):
        self.gcomprisBoard.sublevel=1
        self.gcomprisBoard.level += 1
        if(self.gcomprisBoard.level > self.gcomprisBoard.maxlevel):
            self.gcomprisBoard.level = 1

  def set_level(self, level):
    #This is to hide the Repeat board in case set_level button gets pressed
    if self.mapActive == True:
        self.root.props.visibility = goocanvas.ITEM_INVISIBLE
    self.reset_level()
    self.gcomprisBoard.level = level
    self.gcomprisBoard.sublevel = 1
    gcompris.bar_set_level(self.gcomprisBoard)
    self.end()
    self.start()

  def play_letter(self, letter):
    # Play the letter
    filename = 'voices/$LOCALE/alphabet/U%04X.ogg' % ord(letter.lower())
    gcompris.sound.play_ogg(filename)