Control neighboring object in GCompris activity coded in Python
<p>I am trying to develop an activity for GCompris. Problem is that I want to rotate the needles with pluses
and minuses (when I click on minus - the needle will rotate to the left), but I do not know how to manipulate with neighboring
object. I have tried to search in another python source codes in GCompris, but any of them contains method for this issue. Thank you very much for the help.</p>

<p>Screenshot:
<a href="http://i.imgur.com/l4fsLJj.png" rel="nofollow">activity.png</a></p>

<pre><code>import gtk
import gtk.gdk
import gcompris
import gcompris.utils
import gcompris.skin
import gcompris.bonus
import gcompris.score
import gcompris.sound
import goocanvas
import pango

from gcompris import gcompris_gettext as _

#
# The name of the class is important. It must start with the prefix
# 'Gcompris_' and the last part 'jana' here is the name of
# the activity and of the file in which you put this code. The name of
# the activity must be used in your menu.xml file to reference this
# class like this: type="python:jana"
#
class Gcompris_jana:
  """Empty gcompris Python class"""

  def paint_image (self, i, x2, y2):
    if (self.distance&gt;700):
      self.distance = self.distance / 1.9
    return goocanvas.Image(parent = self.rootitem, pixbuf = self.pixlist[i], x = self.leftx+x2*self.distance, y = y2)

#    self.planet_A = goocanvas.Image(parent = self.rootitem, pixbuf=pixbuf, height=30, width=80, x=45, y=350)

  def __init__(self, gcomprisBoard):
    print "jana init"
    self.distance = 80
    self.leftx = 90

    # Save the gcomprisBoard, it defines everything we need
    # to know from the core
    self.gcomprisBoard = gcomprisBoard

    # Needed to get key_press
    gcomprisBoard.disable_im_context = True

  def start(self):
    print "jana start"

    # Set the buttons we want in the bar
    gcompris.bar_set(gcompris.BAR_LEVEL)

    # Set a background image
    gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(), "colors/wall.png")

    # 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.rootitem = goocanvas.Group(parent = self.gcomprisBoard.canvas.get_root_item())

    goocanvas.Text(
      parent = self.rootitem,
      x=400.0,
      y=100.0,
      text=_("Primary light colors"),
      fill_color="black",
      anchor = gtk.ANCHOR_CENTER,
      alignment = pango.ALIGN_CENTER
      )

    self.itemlist = ["colors/down.png", "colors/needle.png", "colors/up.png", "colors/down.png", "colors/needle.png", "colors/up.png", "colors/down.png", "colors/needle.png", "colors/up.png"]
    self.pixlist = []
    count = 0
    for i in range (len(self.itemlist)):
      print "obr"
      #if (count &gt;= len(self.itemlist)):
      #    count = 0
      pixbuf2 = gcompris.utils.load_pixmap(self.itemlist [i])
      h2 = 30
      w2 = pixbuf2.get_width()*h2/pixbuf2.get_height()
      if (w2&gt;50):
          w2 = pixbuf2.get_width()
      self.pixlist.append (pixbuf2.scale_simple(w2, h2, gtk.gdk.
      INTERP_BILINEAR))
      del pixbuf2
      count = count + 1   

#    pixbuf = gcompris.utils.load_pixmap("colors/needle.png")
#    self.planet_A = goocanvas.Image(parent = self.rootitem, pixbuf=pixbuf, height=30, width=80, x=45, y=350)
    self.display_current_level()

  def end(self):
    print "jana end"
    # Remove the root item removes all the others inside it
    self.rootitem.remove()


  def ok(self):
    print("jana ok.")


  def repeat(self):
    print("jana repeat.")


  #mandatory but unused yet
  def config_stop(self):
    pass

  # Configuration function.
  def config_start(self, profile):
    print("jana config_start.")

  def key_press(self, keyval, commit_str, preedit_str):
    utf8char = gtk.gdk.keyval_to_unicode(keyval)
    strn = u'%c' % utf8char

    print("Gcompris_jana key press keyval=%i %s" % (keyval, strn))

  def pause(self, pause):
    print("jana pause. %i" % pause)


  def set_level(self, level):
    print("jana set level. %i" % level)

  def display_current_level(self):
    for i in range(len(self.itemlist)):
      s = self.paint_image(i, i ,400)
      print i, "# boom"         # i=number of items
      if (i % 3 == 1):      # condition which provides clicking on + and -
        continue

      if(i%3 == 0):
        s.connect ("button_press_event", self.item_click1)
    gcompris.utils.item_focus_init(s, None)

      if(i%3 == 2):
        s.connect ("button_press_event", self.item_click2)
    gcompris.utils.item_focus_init(s, None)

  def item_click1(self,widget,target,event=None,index=0):
    if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
        target =  self.paint_image(index+1, 1 ,400)
        # There should be needle instead of target, but I do not know how to get it.
        gcompris.utils.item_rotate(target, -30);


  def item_click2(self,widget,target,event=None,index=0):
    if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
        target =  self.paint_image(index+1, 1 ,400)
# There should be needle instead of target, but I do not know how to get it.
        gcompris.utils.item_rotate(target, 30);
</code></pre>
