[gcompris/gcomprisbraille: 2/2] Completed the ordering exercice.



commit df5e601fde45a13384b7854e490c9ce4ed5cbb15
Merge: c24055b 63b7893
Author: Bruno Coudoin <bruno coudoin free fr>
Date:   Wed Aug 24 00:29:30 2011 +0200

    Completed the ordering exercice.

 src/louis_braille-activity/init_path.sh            |    2 +-
 src/louis_braille-activity/louis_braille.py        |   50 +-
 src/louis_braille-activity/louis_braille.xml.in    |    2 +-
 .../resources/louis_braille/braile.jpg             |  Bin 43376 -> 43376 bytes
 .../resources/louis_braille/braille_ball.jpg       |  Bin 13440 -> 13440 bytes
 .../resources/louis_braille/chart.png              |  Bin 29639 -> 29639 bytes
 .../resources/louis_braille/fireplace.jpg          |  Bin 20493 -> 20493 bytes
 .../resources/louis_braille/night_printing.jpg     |  Bin 8368 -> 8368 bytes
 .../resources/louis_braille/piano.svg              | 1695 +++-----------------
 .../resources/louis_braille/rnib.jpg               |  Bin 52337 -> 52337 bytes
 .../resources/louis_braille/statue.jpg             |  Bin 48687 -> 48687 bytes
 .../resources/louis_braille/teach.jpg              |  Bin 55242 -> 55242 bytes
 .../resources/louis_braille/workshop.jpg           |  Bin 25726 -> 25726 bytes
 13 files changed, 221 insertions(+), 1528 deletions(-)
---
diff --cc src/louis_braille-activity/louis_braille.py
index f102feb,f66ae2f..e4f6b39
--- a/src/louis_braille-activity/louis_braille.py
+++ b/src/louis_braille-activity/louis_braille.py
@@@ -1,6 -1,6 +1,6 @@@
  #  gcompris - louis_braille.py
  #
- # Copyright (C) 2003, 2008 Bruno Coudoin
 -# Copyright (C) 2003, 2008 Bruno Coudoin | Srishti Sethi
++# Copyright (C) 2011 Bruno Coudoin | 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
@@@ -36,9 -36,13 +36,6 @@@ CIRCLE_FILL = "white
  CELL_WIDTH = 30
  
  LOUIS_BRAILLE_NAME = ['L','O','U','I','S','B','R','A','I','L','L','E']
- NUMBER_SEQUENCE = [[1,'a'],[2,'b'],[3,'c'],[4,'d'],[5,'e'],[6,'f'],
-                    [7,'g'],[8,'h'],[9,'i'],[10,'j'],[11,'k']]
- random.shuffle(NUMBER_SEQUENCE)
 -NUMBERS = [12,13,14,15,16,17,18,19,20,21,22]
 -SEQUENCE = ['a','b','c','d','e','f','g','h','i','j','k']
 -NUMBER_SEQUENCE = [[1,'a'],[2,'b'],[3,'c'],[4,'d'],[5,'e'],[6,'f'],
 -                   [7,'g'],[8,'h'],[9,'i'],[10,'j'],[11,'k']]
 -
 -random.shuffle(NUMBERS)
 -random.shuffle(NUMBER_SEQUENCE)
  
  class Gcompris_louis_braille:
    """Empty gcompris python class"""
@@@ -221,11 -257,51 +217,8 @@@
                                   y = 120,
                                   )
  
-   def enter_callback(self, event, widget, index):
-       print self.widget_array[index].get_text()
--
 -  def component_drag(self, widget, target, event, index):
 -      groupitem = target.get_parent()
 -      groupitem.raise_(None)
 -
 -
 -      if event.type == gtk.gdk.BUTTON_PRESS:
 -        bounds = groupitem.get_bounds()
 -        self.offset_y = event.y
 -        print (self.groupitem_array[index].get_bounds().y1 + self.groupitem_array[index].get_bounds().y2 )/ 2
 -
 -      elif ( event.type == gtk.gdk.MOTION_NOTIFY
 -             and event.state & gtk.gdk.BUTTON1_MASK ):
 -          groupitem.translate(0, event.y - self.offset_y)
 -
 -      elif event.type == gtk.gdk.BUTTON_RELEASE:
 -        bounds = groupitem.get_bounds()
 -        self.mid_bounds = (bounds.y1 + bounds.y2) / 2
 -
 -
 -        # Must find the closer stop to drop this item
 -        while(self.item < 11):
 -          if (self.coorditem_array[self.item] < self.mid_bounds and self.coorditem_array[self.item + 1] \
 -               > self.mid_bounds):
 -              if( self.mid_bounds - self.coorditem_array[self.item] < self.coorditem_array[self.item + 1] \
 -                   - self.mid_bounds ) :
 -                  #TODO
 -                  #Here I want to translate the group item to calculated bound
 -                  #But it goes somewhere else
 -                  groupitem.translate(0, self.coorditem_array[self.item])
 -                  print self.coorditem_array[self.item]
 -              else :
 -                  groupitem.translate(0, self.coorditem_array[self.item + 1])
 -                  print self.coorditem_array[self.item + 1]
 -          self.item += 1
 -      self.item = 0
 -
 -  def enter_callback(self, event, widget, index):
 -      print self.widget_array[index].get_text()
 -
    def ok_event(self, event ,target ,item):
 -      for index in range(11):
 -          if(self.widget_array[index].get_text() == NUMBER_SEQUENCE[index][1]):
 -              self.won +=1
 -      if (self.won == 11):
 +      if ( self.reordering.is_done() ):
            gcompris.bonus.display(gcompris.bonus.WIN,gcompris.bonus.TUX)
            self.gamewon = 1
        else :
@@@ -275,109 -351,4 +268,124 @@@
          self.start()
  
    def set_level(self, level):
 -    print("louis_braille set level. %i" % level)
 +    print("louis_braille set level. %i" % level)
 +
 +class Reordering:
 +  """This class manages the reordering activity"""
 +
 +  def __init__(self, louisbraille, max_item):
 +    self.louisbraille = louisbraille
 +    self.rootitem = louisbraille.rootitem
 +    self.index = 0
 +    self.randoms = range(max_item)
 +    random.shuffle(self.randoms)
 +    self.orders = range(max_item)
 +
 +  def dump(self):
 +    for index, item in enumerate(self.orders):
 +      print index, item.get_data("index")
 +
 +  # Return True if all the items are properly placed
 +  def is_done(self):
 +     self.dump()
 +     for index, item in enumerate(self.orders):
 +       group_index = item.get_data("index")
 +       if ( group_index != index ):
 +         return False
 +     return True
 +
 +  def add_line(self, text):
-     group_item = goocanvas.Group(parent = self.rootitem)
++    position = self.randoms[ self.index ]
++    y = (position + 0.5) * 43
++    group_item = goocanvas.Group(parent = self.rootitem,
++                                 y = y)
 +    # Save in the item itself where is its correct position
 +    group_item.set_data("index", self.index)
 +    # Create Rounded Rectangles for each story
-     position = self.randoms[ self.index ]
-     y = (position + 0.5) * 43
 +    goocanvas.Rect(parent = group_item,
 +                   x = 100,
-                    y = y,
++                   y = 0,
 +                   width = 550,
 +                   height = 40,
 +                   radius_x = 17,
 +                   radius_y = 17,
 +                   stroke_color = "orange",
 +                   fill_color = "white",
 +                   line_width = 2.0)
 +    self.orders[ position ] = group_item
 +
 +    # Displaying the STORY
 +    goocanvas.Text(parent = group_item,
 +                   x = 370.0,
-                    y = (position + 1) * 43,
++                   y = 20,
 +                   text = text,
 +                   fill_color = "black",
 +                   anchor = gtk.ANCHOR_CENTER,
 +                   alignment = pango.ALIGN_CENTER,
 +                   font = 'SANS 9',
 +                   width = 500,
 +                   )
 +    # It is hard to manage focus when we move the item
 +    # gcompris.utils.item_focus_init(self.dragText, self.dragRect)
 +    group_item.connect("button_press_event", self.component_drag)
 +    group_item.connect("motion_notify_event", self.component_drag)
 +    group_item.connect("button_release_event", self.component_drag)
 +
 +    self.index += 1
 +
 +  # Return the index in self.orders of the given group
 +  def get_group_index(self, group):
 +    return self.orders.index(group)
 +
 +  def move_group(self, from_index, to_index):
 +    from_item = self.orders[from_index]
++    (from_x, from_y) = from_item.get_properties('x', 'y')
++    print "from", from_x, from_y
 +    to_item = self.orders[to_index]
- 
++    to_x = to_item.get_data('xref')
++    to_y = to_item.get_data('yref')
++    print "to", to_x, to_y
++    from_item.set_properties(x = to_x, y = to_y)
++    to_item.set_data("xref", from_x)
++    to_item.set_data("yref", from_y)
++    self.orders[from_index], self.orders[to_index] = self.orders[to_index], self.orders[from_index]
 +
 +  def swap_with_group_near(self, group, y):
 +    for index, item in enumerate(self.orders):
 +      bounds = item.get_bounds()
 +      if ( group != item and
 +           y < bounds.y2 and y > bounds.y1 ):
 +        print "got it at index " + str(index)
 +        print self.get_group_index(group)
++        self.move_group( index, self.get_group_index(group) )
 +        return
 +
 +
 +  def component_drag(self, widget, target, event):
 +      groupitem = target.get_parent()
 +      groupitem.raise_(None)
 +
 +      if event.type == gtk.gdk.BUTTON_PRESS:
 +        bounds = groupitem.get_bounds()
 +        self.offset_y = event.y
++        # We save the x and y coord in xref and yref for future use
++        (x, y) = groupitem.get_properties('x', 'y')
++        groupitem.set_data("xref", x)
++        groupitem.set_data("yref", y)
 +
 +      elif ( event.type == gtk.gdk.MOTION_NOTIFY
 +             and event.state & gtk.gdk.BUTTON1_MASK ):
 +          groupitem.translate(0, event.y - self.offset_y)
 +
 +          (x, y) = self.louisbraille.gcomprisBoard.canvas.\
 +              convert_from_item_space(groupitem, event.x, event.y)
 +          self.swap_with_group_near(groupitem, y)
 +
 +      elif event.type == gtk.gdk.BUTTON_RELEASE:
-         pass
-         # Must find the closer stop to drop this item
++        self.dump()
++        groupitem.set_transform(None)
++        to_x = groupitem.get_data('xref')
++        to_y = groupitem.get_data('yref')
++        groupitem.set_properties(x = to_x, y = to_y)
 +
 +      return True
- 
- 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]