Example #1
0
    def start(self):
        self.board_paused = False
        self.game_start = False
        # 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())
        land_rootitem = goocanvas.Group(parent=self.rootitem)

        # Set a background image
        level = str(self.gcomprisBoard.level)
        image = 'land_safe/background' + level + '.jpg'
        gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
                                image)

        #Set the land
        image = 'land_safe/land' + str(level) + '.png'
        pixbuf = gcompris.utils.load_pixmap(image)
        land = goocanvas.Image(parent=land_rootitem,
                               pixbuf=pixbuf,
                               x=-550,
                               y=gcompris.BOARD_HEIGHT - 125)
        land.lower(None)

        # Text for Gravity
        gravity = str(0.58 * self.gcomprisBoard.level)
        text = _('Gravity: %s') % (gravity)
        gravity_text = goocanvas.Text(parent=self.rootitem,
                                      x=760,
                                      y=50,
                                      fill_color="white",
                                      anchor=gtk.ANCHOR_E,
                                      alignment=pango.ALIGN_CENTER,
                                      text=_(text))
        bounds = gravity_text.get_bounds()
        gap = 20

        gravity_back = goocanvas.Rect(parent=self.rootitem,
                                      radius_x=6,
                                      radius_y=6,
                                      x=bounds.x1 - gap,
                                      y=bounds.y1 - gap,
                                      width=bounds.x2 - bounds.x1 + gap * 2,
                                      height=bounds.y2 - bounds.y1 + gap * 2,
                                      stroke_color_rgba=0xFFFFFFFFL,
                                      fill_color_rgba=0xCCCCCC44L)

        # Load spaceship
        self.space_ship = Spaceship(self, self.rootitem, land_rootitem,
                                    self.gcomprisBoard.level)

        gcompris.bar_set_level(self.gcomprisBoard)

        # Set the buttons we want in the bar
        gcompris.bar_set(gcompris.BAR_LEVEL)
        gcompris.bar_location(2, -1, 0.5)

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

    svghandle = gcompris.utils.load_svg("hangman/back.svgz")
    goocanvas.Svg(
      parent = self.backitem,
      svg_handle = svghandle,
      pointer_events = goocanvas.EVENTS_NONE
      )

    # 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.backitem)

    # Get the name of the language for the current locale
    self.wordlist = None
    try:
      self.language = gcompris.gcompris_gettext( gcompris.get_locale_name(gcompris.get_locale()) )
      self.wordlist = gcompris.get_wordlist("wordsgame/default-$LOCALE.xml")
    except:
      pass

    if not self.wordlist:
      # Fallback to english
      self.wordlist = gcompris.get_wordlist("wordsgame/default-en.xml")
      self.language = _("English")

    if not self.wordlist:
      gcompris.utils.dialog(_("Could not find the list of words."),
                            stop_board)
      return;

    self.gcomprisBoard.level = 1
    self.gcomprisBoard.maxlevel = self.wordlist.number_of_level * 3
    self.gcomprisBoard.sublevel = 1
    self.gcomprisBoard.number_of_sublevel = 10

    # Set the buttons we want in the bar
    gcompris.bar_set(gcompris.BAR_LEVEL)
    gcompris.bar_location(gcompris.BOARD_WIDTH - 160, -1, 0.6)

    # Set a background image
    gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())

    self.display_level()
    def __init__(self, rootitem, game, x, y, planet_instance):
        self.game = game
        self.planet_instance = planet_instance
        self.height = 60
        self.button_width = 20
        self.x = x
        self.y = y
        self.rootitem = goocanvas.Group(parent=rootitem)
        line = goocanvas.Polyline(parent=self.rootitem,
                                  points=goocanvas.Points([
                                      (x, y + self.button_width / 2.0),
                                      (x, y + self.button_width / 2.0 +
                                       self.height)
                                  ]),
                                  stroke_color="grey",
                                  width=2.0)

        # This is the relative position of the scale from 0 to 1
        # 0 is the bottom
        self.scale_value = 0.5
        slider_y = y + self.height / 2.0
        self.sliding_bar(
            goocanvas.Points([(x - 5, slider_y), (x + 5, slider_y)]))
        self.button(self.x, self.y, self.button_width, '+', 0.1)
        self.button(self.x, self.y + self.height, self.button_width, '-', -0.1)

        self.planet_instance.set_scale(self.scale_value)
    def load_asteroid(self):
        self.count = 1
        self.asteroid_rootitem = goocanvas.Group(parent=self.rootitem)

        space_shuttle_x = 200.0
        right_asteroid_x = 550.0
        space_shuttle_y = 530
        right_asteroid_y = -20

        # Load the space shuttle
        self.space_shuttle = goocanvas.Image(
            parent=self.asteroid_rootitem,
            pixbuf=gcompris.utils.load_pixmap(
                "intro_gravity/space_shuttle.svg"),
            x=space_shuttle_x,
            y=space_shuttle_y)

        # Pick a random asteroid and load image
        asteroid = random.choice([0, 1, 2, 3, 4])
        image = "intro_gravity/asteroid" + str(asteroid) + ".jpg"
        self.asteroid = goocanvas.Image(
            parent=self.asteroid_rootitem,
            pixbuf=gcompris.utils.load_pixmap(image),
            x=right_asteroid_x,
            y=right_asteroid_y)

        self.asteroid_rootitem.lower(self.ship_instance.tux_spaceship)
        gobject.timeout_add(30, self.check_asteroid)
 def __init__(self, next_link, base_node, link_node, base_route_table,
              mterp, msecp, parent_canvas_item, color, path, viz):
     self.base_node = base_node
     self.link_node = link_node
     self.base_route_table = base_route_table
     self.mterp = mterp
     self.msecp = msecp
     self.canvas_item = goocanvas.Group(parent=parent_canvas_item)
     # self.line = goocanvas.Polyline(parent=self.canvas_item, line_width=1.0, stroke_color_rgba=0xC00000FF, start_arrow=True, arrow_length=10,arrow_width=8)
     self.line = goocanvas.Polyline(parent=self.canvas_item,
                                    line_width=2.0,
                                    stroke_color_rgba=color,
                                    start_arrow=True,
                                    close_path=False,
                                    end_arrow=False,
                                    arrow_length=15,
                                    arrow_width=15)
     self.line.raise_(None)
     self.label = goocanvas.Text()  #, fill_color_rgba=0x00C000C0)
     self.label.props.pointer_events = 0
     self.label.set_property("parent", self.canvas_item)
     self.label.raise_(None)
     self.canvas_item.set_data("pyviz-object", self)
     self.canvas_item.lower(None)
     self.way_index = 0
     self.next_link = next_link
     self.path = path
     self.viz = viz
Example #6
0
 def _createUI(self):
     self._cursor = ARROW
     root = self.get_root_item()
     self.tracks = goocanvas.Group()
     self.tracks.set_simple_transform(0, KW_LABEL_Y_OVERFLOW, 1.0, 0)
     root.add_child(self.tracks)
     self._marquee = goocanvas.Rect(
         parent=root,
         stroke_pattern=unpack_cairo_pattern(0x33CCFF66),
         fill_pattern=unpack_cairo_pattern(0x33CCFF66),
         visibility=goocanvas.ITEM_INVISIBLE)
     self._playhead = goocanvas.Rect(y=-10,
                                     parent=root,
                                     line_width=1,
                                     fill_color_rgba=0x000000FF,
                                     stroke_color_rgba=0xFFFFFFFF,
                                     width=3)
     self._playhead_controller = PlayheadController(self._playhead)
     self.connect("size-allocate", self._size_allocate_cb)
     root.connect("motion-notify-event", self._selectionDrag)
     root.connect("button-press-event", self._selectionStart)
     root.connect("button-release-event", self._selectionEnd)
     self.height = (LAYER_HEIGHT_EXPANDED + TRACK_SPACING +
                    LAYER_SPACING) * 2
     # add some padding for the horizontal scrollbar
     self.height += 21
     self.set_size_request(-1, self.height)
    def game(self):
        self.game_completed = False

        self.rootitem = goocanvas.Group(
            parent=self.gcomprisBoard.canvas.get_root_item())

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

        # Load planet on the left (saturn) and it's slider
        planet_left = Fixed_planet(self.rootitem, 70, 200, "saturn.png")
        Slider(self.rootitem, self, 20, 200, planet_left)

        # Planet on right (neptune) and it's slider
        planet_right = Fixed_planet(self.rootitem, 680, 200, "neptune.png")
        Slider(self.rootitem, self, 780, 200, planet_right)

        # Load the tux_ship
        self.ship_instance = Spaceship(self, self.rootitem,
                                       gcompris.BOARD_WIDTH / 2.0, 200,
                                       self.gcomprisBoard.level, planet_left,
                                       planet_right)
        # Set the buttons we want in the bar
        gcompris.bar_set(0)
        gcompris.bar_location(2, -1, 0.5)

        # Message button
        self.message = Message(self.rootitem, 400, 320, 20, self.tuto_event)

        self.tuto_step = 0
        self.tutorial(self.tuto_step)
Example #8
0
  def start(self):
    print "pythontemplate start"

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

    # Set a background image
    gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())

    # 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=_("This is the first plugin in GCompris coded in the Python\n"
             "Programming language."),
      fill_color="black",
      anchor = gtk.ANCHOR_CENTER,
      alignment = pango.ALIGN_CENTER
      )
Example #9
0
    def start(self, area):

        # Connect to our database
        self.con = sqlite.connect(gcompris.get_database())
        self.cur = self.con.cursor()

        # 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.canvas, )

        # Call our parent start
        module.Module.start(self)

        frame = gtk.Frame(_("Groups"))
        frame.show()

        goocanvas.Widget(parent=self.rootitem,
                         widget=frame,
                         x=area[0] + self.module_panel_ofset,
                         y=area[1] + self.module_panel_ofset,
                         width=area[2] - area[0] - 2 * self.module_panel_ofset,
                         height=area[3] - area[1] -
                         2 * self.module_panel_ofset,
                         anchor=gtk.ANCHOR_NW)

        group_list.Group_list(frame, self.con, self.cur)
Example #10
0
    def writeText(self, txt, x=100, y=250, width=150):
        '''
        write text box with background rectangle to game
        the text is returned and must be removed by the caller
        '''

        # A group that will hold the text description and the background
        textrootitem = goocanvas.Group(parent=self.rootitem)

        t = goocanvas.Text(
            parent=textrootitem,
            x=x,
            y=y,
            width=width,
            font=gcompris.skin.get_font("gcompris/board/medium"),
            text=txt,
            anchor=gtk.ANCHOR_CENTER,
            alignment=pango.ALIGN_CENTER,
            use_markup=True)

        TG = 10
        bounds = t.get_bounds()

        rect = goocanvas.Rect(parent=textrootitem,
                              x=bounds.x1 - TG,
                              y=bounds.y1 - TG,
                              width=bounds.x2 - bounds.x1 + TG * 2,
                              height=bounds.y2 - bounds.y1 + TG * 2,
                              line_width=2.0,
                              radius_x=3.0,
                              radius_y=3.0,
                              fill_color_rgba=TEXT_BG_COLOR,
                              stroke_color="black")
        t.raise_(rect)
        return textrootitem
Example #11
0
    def __init__(self, computer, image, x, y):
        self.computer = computer
        self.canvas = computer.gcomprisBoard.canvas
        self.rootitem = computer.rootitem

        self.comp_rootitem = goocanvas.Group(parent=self.rootitem, )

        pixmap = gcompris.utils.load_pixmap(self.image)
        self.x = x
        self.y = y
        self.width = 70
        self.height = 70
        self.center_x = self.width / 2
        self.center_y = self.height / 2

        self.component_item_offset_x = 0
        self.component_item_offset_y = 0
        self.component_item = goocanvas.Image(
            parent=self.comp_rootitem,
            pixbuf=pixmap,
            x=self.x - self.center_x,
            y=self.y - self.center_y,
            width=self.width,
            height=self.height,
        )
        self.component_item.connect("button_press_event", self.component_move,
                                    self)
        self.component_item.connect("motion_notify_event", self.component_move,
                                    self)
Example #12
0
    def start(self):

        self.running = True
        self.saved_policy = gcompris.sound.policy_get()
        gcompris.sound.policy_set(gcompris.sound.PLAY_AND_INTERRUPT)
        gcompris.sound.pause()

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

        # Set a background image
        gcompris.set_default_background(
            self.gcomprisBoard.canvas.get_root_item())

        # 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())

        self.display_level(self.gcomprisBoard.level)

        if not (gcompris.get_properties().fx):
            gcompris.utils.dialog(
                _("Error: This activity cannot be \
played with the\nsound effects disabled.\nGo to the configuration \
dialogue to\nenable the sound."), None)

        readyButton = TextButton(400, 455,
                                 ' ' * 20 + _('I am Ready') + ' ' * 20,
                                 self.rootitem, 0x11AA11FFL)
        readyButton.getBackground().connect("button_press_event",
                                            self.ready_event, readyButton)
Example #13
0
    def start(self, area):
        # Connect to our database
        self.con = sqlite.connect(gcompris.get_database())
        self.cur = self.con.cursor()

        if Boards.already_loaded:
            self.rootitem.props.visibility = goocanvas.ITEM_VISIBLE
            self.boardList.show(self.con, self.cur)
            return

        Boards.already_loaded = True

        # 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.canvas, )

        module.Module.start(self)

        self.frame = gtk.Frame(_("Boards"))
        self.frame.show()

        goocanvas.Widget(parent=self.rootitem,
                         widget=self.frame,
                         x=area[0] + self.module_panel_ofset,
                         y=area[1] + self.module_panel_ofset,
                         width=area[2] - area[0] - 2 * self.module_panel_ofset,
                         height=area[3] - area[1] -
                         2 * self.module_panel_ofset,
                         anchor=gtk.ANCHOR_NW)

        self.boardList = board_list.Board_list(self.con, self.cur, self.frame)
        self.boardList.init()
Example #14
0
  def draw_tools(self):

    self.root_toolitem = \
      goocanvas.Group(
        parent = self.rootitem,
      )

    goocanvas.Image(
      parent = self.root_toolitem,
      pixbuf = gcompris.utils.load_pixmap("anim/tool-selector.png"),
      x = 5,
      y = 5.0,
      width = 107.0,
      height = 517.0,
      )

    x1 = 11.0
    x2 = 56.0
    y = 11.0
    stepy = 45
    start_tool = 0

    if gcompris.sugar_detected():
        start_tool = 2

    # Display the tools
    for i in range(start_tool,len(self.tools)):

      # Exclude the anim specific buttons
      if self.gcomprisBoard.mode == 'draw':
        if self.tools[i][0]=="MOVIE" or self.tools[i][0]=="PICTURE":
          continue

      if(i%2):
        theX = x2
      else:
        theX = x1

      item = \
        goocanvas.Image(
          parent = self.root_toolitem,
          pixbuf = gcompris.utils.load_pixmap(self.tools[i][1]),
          tooltip = self.tools[i][4],
          x=theX,
          y=y
        )
      gcompris.utils.item_focus_init(item, None)
      item.connect("button_press_event", self.tool_item_event, i)
      if i%2:
        y += stepy

      if(self.tools[i][0]=="SELECT"):
        self.select_tool = item
        self.select_tool_number = i
        # Always select the SELECT item by default
        self.current_tool = i
        self.old_tool_item = item
        self.old_tool_item.props.pixbuf = \
            gcompris.utils.load_pixmap(self.tools[i][2])
        gcompris.set_cursor(self.tools[i][3]);
Example #15
0
    def set_sublevel(self, sublevel=1):
        """Start of the game at sublevel number sublevel of level n"""

        if self.MAX != 0:
            self.end()

        #Creation of canvas group use by the activity
        self.ROOT = \
        goocanvas.Group(
          parent = self.gcomprisBoard.canvas.get_root_item(),
          )

        #Setting of the first background image of the level
        gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
                                self.data[sublevel - 1].img1)

        #Initialisation of sub-elements in list
        self.POINT = []
        self.actu = 0

        #Display actual sublevel and number of sublevel of this level
        self.gcomprisBoard.sublevel = sublevel
        self.gcomprisBoard.number_of_sublevel = len(self.data)

        #Display of score
        gcompris.score.start(gcompris.score.STYLE_NOTE, 10, 485,
                             self.gcomprisBoard.number_of_sublevel)
        gcompris.score.set(self.gcomprisBoard.sublevel)

        #Set point number 0 from which the draw start. This point is equal to first one.
        self.MAX = len(self.data[sublevel - 1].points)
        self.POINT.append(
            self.point(self.data[sublevel - 1].points[0][0],
                       self.data[sublevel - 1].points[0][1]))
        self.POINT[0].props.visibility = goocanvas.ITEM_INVISIBLE

        #Data loading from global data and display of points and numbers
        i = self.MAX
        prev_point = None
        for i in range(0, self.MAX):
            diameter = 0
            if self.gcomprisBoard.level == 1:
                diameter = 45
            elif self.gcomprisBoard.level == 2:
                diameter = 30
            else:
                diameter = 20

            point = self.point(self.data[sublevel - 1].points[i][0],
                               self.data[sublevel - 1].points[i][1], diameter)
            self.POINT.append(point)
            self.POINT[i + 1].connect('button_press_event', self.action, i + 1)

            # Setting of display level to prevent covering a point with another point which
            # cause an impossibility to select it.
            self.POINT[i + 1].lower(prev_point)
            prev_point = self.POINT[i + 1]

        #Setting color of the first point to blue instead of green
        self.POINT[1].set_properties(fill_color_rgba=0x003DF5D0)
Example #16
0
    def newGame(self):
        if self.timerAnim:
            gobject.source_remove(self.timerAnim)
            self.timerAnim = None
        if self.boardItem:
            self.boardItem.remove()
        self.boardItem = \
            goocanvas.Group(
                parent = self.gcomprisBoard.canvas.get_root_item()
                )
        self.boardItem.translate((gcompris.BOARD_WIDTH - self.boardSize) / 2.0,
                                 50.0)
        self.player1 = human.Human(self.gcomprisBoard.level)
        if self.mode == 1:
            self.player2 = minmax.MinMax(self.gcomprisBoard.level,
                                         self.refreshScreen)
        self.board = board.Board()
        self.gamewon = False
        self.winLine = None
        try:
            del self.redLine
        except:
            pass
        self.keyb_column = 0
        self.cur_player = 1
        self.stone_init()
        self.update_stone2()

        self.timericon.goocanvas.props.visibility = goocanvas.ITEM_INVISIBLE
        if self.mode == 1:
            self.prof.props.visibility = goocanvas.ITEM_VISIBLE
Example #17
0
    def __init__(self, animitem):
        self.animitem = animitem

        self.anchorgroup = None

        self.anchorgroup = \
          goocanvas.Group(
            parent = animitem.anim.doc.rootitem,
          )

        self.anchorbound = \
            goocanvas.Rect(
                parent = self.anchorgroup,
                stroke_color_rgba = 0x000000FFL,
                line_width = 3)

        self.down = \
            goocanvas.Image(
            parent = self.anchorgroup,
            pixbuf = gcompris.utils.load_pixmap("anim/down.png"),
            )
        self.down.connect("button_press_event",
                    self.animitem.down_size, False)

        self.up = \
            goocanvas.Image(
            parent = self.anchorgroup,
            pixbuf = gcompris.utils.load_pixmap("anim/up.png"),
            )
        self.up.connect("button_press_event",
                    self.animitem.up_size, False)
 def __init__(self, parent_canvas_item, sta, dev):
     """! Initialize function.
     @param self The object pointer.
     @param parent_canvas_item: parent canvas
     @param sta The STA node
     @param dev The dev
     """
     self.node1 = sta
     self.dev = dev
     self.node2 = None  # ap
     self.canvas_item = goocanvas.Group(parent=parent_canvas_item)
     self.invisible_line = goocanvas.Polyline(
         parent=self.canvas_item,
         line_width=25.0,
         visibility=goocanvas.ITEM_HIDDEN)
     self.visible_line = goocanvas.Polyline(parent=self.canvas_item,
                                            line_width=1.0,
                                            stroke_color_rgba=0xC00000FF,
                                            line_dash=goocanvas.LineDash(
                                                [2.0, 2.0]))
     self.invisible_line.props.pointer_events = (
         goocanvas.EVENTS_STROKE_MASK
         | goocanvas.EVENTS_FILL_MASK
         | goocanvas.EVENTS_PAINTED_MASK)
     self.canvas_item.set_data("pyviz-object", self)
     self.canvas_item.lower(None)
     self.set_ap(None)
Example #19
0
    def start(self, area):
        # Connect to our database
        self.con = sqlite.connect(gcompris.get_database())
        self.cur = self.con.cursor()

        # 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.canvas, )

        module.Module.start(self)

        frame = gtk.Frame(_("Logins"))

        goocanvas.Widget(parent=self.rootitem,
                         widget=frame,
                         x=area[0] + self.module_panel_ofset,
                         y=area[1] + self.module_panel_ofset,
                         width=area[2] - area[0] - 2 * self.module_panel_ofset,
                         height=area[3] - area[1] -
                         2 * self.module_panel_ofset,
                         anchor=gtk.ANCHOR_NW)

        self.profile_widget = profile_widget.ProfileWidget(
            self.con, self.cur, gcompris.sugar_get_profile_id(), False)
        frame.add(self.profile_widget)

        frame.show_all()
    def start(self):
        # Set the buttons we want in the bar
        gcompris.bar_set(gcompris.BAR_LEVEL)
        gcompris.bar_set_level(self.gcomprisBoard)
        gcompris.bar_location(275, -1, 0.8)

        self.saved_policy = gcompris.sound.policy_get()
        gcompris.sound.policy_set(gcompris.sound.PLAY_AND_INTERRUPT)
        gcompris.sound.pause()
        # Set a background image
        gcompris.set_default_background(
            self.gcomprisBoard.canvas.get_root_item())

        # 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())

        self.display_level(self.gcomprisBoard.level)

        if not (gcompris.get_properties().fx):
            gcompris.utils.dialog(
                _("Error: This activity cannot be \
played with the\nsound effects disabled.\nGo to the configuration \
dialogue to\nenable the sound."), None)
Example #21
0
    def drawNoteButtons(self):
        '''
        draw the note buttons seen on the screen, optionally make them color-coded or black
        '''
        if hasattr(self, 'noteButtonsRootItem'):
            self.noteButtonsRootItem.remove()

        self.noteButtonsRootItem = goocanvas.Group(parent=self.rootitem,
                                                   x=0,
                                                   y=0)

        def drawNoteButton(x, y, numID, play_sound_on_click):
            '''
            local method to draw one button
            '''
            if self.colorButtons:
                color = NOTE_COLOR_SCHEME[numID]
            else:
                color = 'white'
            text = getKeyNameFromID(numID, self.sharpNotation)
            vars(self)[str(numID)] = goocanvas.Text(
                parent=self.rootitem,
                x=x,
                y=y,
                text=text,
                fill_color='black',
                font=gcompris.skin.get_font("gcompris/board/small"),
                anchor=gtk.ANCHOR_CENTER,
                alignment=pango.ALIGN_CENTER,
                pointer_events="GOO_CANVAS_EVENTS_NONE")

            rect = goocanvas.Rect(parent=self.rootitem,
                                  x=x - 12.5,
                                  y=y - 10,
                                  width=25,
                                  height=20,
                                  line_width=.5,
                                  fill_color=color)
            vars(self)[str(numID)].raise_(None)
            vars(self)[str(numID)].scale(2.0, 2.0)
            vars(self)[str(numID)].translate(-250, -150)
            rect.scale(2, 2)
            rect.translate(-250, -150)
            rect.connect("button_press_event", play_sound_on_click, numID)
            rect.set_data('numID', numID)
            gcompris.utils.item_focus_init(rect, None)
            gcompris.utils.item_focus_init(vars(self)[str(numID)], None)

        x = 420
        y = 220
        random.shuffle(self.pitchPossibilities)
        for numID in self.pitchPossibilities:
            if numID != 8:
                # do not draw another C-button, since this is ambiguous, because
                # we have a c' and a c"
                drawNoteButton(x, y, numID, self.play_sound_on_click)
                y += 30
                if y > 320:
                    y = 220
                    x = x + 40
Example #22
0
    def display_game(self):
        self.rootitem = \
          goocanvas.Group(parent = self.gcomprisBoard.canvas.get_root_item())

        self.create_components(self.gcomprisBoard.level)

        # Display the tools
        x = 12
        y = 10

        for i in range(0, len(self.tools)):
            item = goocanvas.Image(parent=self.rootitem,
                                   pixbuf=gcompris.utils.load_pixmap(
                                       self.tools[i][1]),
                                   x=x,
                                   y=y)
            x += 45
            item.connect("button_press_event", self.tool_item_event, i)

            if (self.tools[i][0] == "SELECT"):
                self.select_tool = item
                self.select_tool_number = i
                # Always select the SELECT item by default
                self.current_tool = i
                self.old_tool_item = item
                self.old_tool_item.props.pixbuf = gcompris.utils.load_pixmap(
                    self.tools[i][2])
                gcompris.set_cursor(self.tools[i][3])

            # Add the item in self.tools for later use
            self.tools[i].append(item)
Example #23
0
  def draw_playing_area(self):

    x1=self.playing_area[0]
    y1=self.playing_area[1]
    x2=self.playing_area[2]
    y2=self.playing_area[3]


    # The CanvasGroup for the playing area.
    self.root_playingitem = \
      goocanvas.Group(
        parent = self.rootitem,
      )
    self.root_playingitem.props.visibility = goocanvas.ITEM_INVISIBLE

    # intervall = 1000 / anim_speed
    self.anim_speed=5

    run = \
      goocanvas.Image(
        parent = self.root_playingitem,
      pixbuf = gcompris.utils.load_pixmap("anim/down.png"),
      x = 15,
      y = 410,
      width = 20,
      height = 20,
      )
    run.connect("button_press_event", self.speed_event,False)

    self.speed_item = \
      goocanvas.Text(
        parent = self.root_playingitem,
      text=self.anim_speed,
      font = gcompris.skin.get_font("gcompris/board/medium"),
      x=52,
      y=420,
      anchor=gtk.ANCHOR_CENTER,
      )


    run = \
      goocanvas.Image(
        parent = self.root_playingitem,
      pixbuf = gcompris.utils.load_pixmap("anim/up.png"),
      x = 70,
      y = 410,
      width = 20,
      height = 20,
      )
    run.connect("button_press_event", self.speed_event,True)

    # And finaly a STOP icon
    run = \
      goocanvas.Image(
        parent = self.root_playingitem,
      pixbuf = gcompris.utils.load_pixmap("anim/draw.svg"),
      x = 16,
      y = 110,
      )
    run.connect("button_press_event", self.stop_event, True)
Example #24
0
    def __init__(self, board, root, x, y, index,
                 board_size,
                 scale):
      self.board = board

      self.itemgroup = goocanvas.Group(parent = root)
      self.itemgroup.translate(x, y)
      self.scale = scale

      if (index == (board_size-1)):
        pixbuf_case = self.board.pixmap_case_last
        pixbuf_mask = self.board.pixmap_mask_last
      else:
        pixbuf_case = self.board.pixmap_case
        pixbuf_mask = self.board.pixmap_mask


      item = goocanvas.Image(
        parent = self.itemgroup,
        pixbuf = pixbuf_case,
        x=0,
        y=0)
      bounds = item.get_bounds()
      # Add a little zoom offset to make sure items stick well
      item.scale(scale + 0.01, scale)

      self.ombre = goocanvas.Image(
        parent = self.itemgroup,
        pixbuf = self.board.pixmap_ombre,
        x=0,
        y=0)
      self.ombre.props.visibility = goocanvas.ITEM_INVISIBLE
      bounds = self.ombre.get_bounds()
      self.ombre.scale(scale, scale)

      self.ball = goocanvas.Image(
        parent = self.itemgroup,
        x=0,
        y=0)
      self.ball.props.visibility = goocanvas.ITEM_INVISIBLE

      item = goocanvas.Image(
        parent = self.itemgroup,
        pixbuf = pixbuf_mask,
        x=0,
        y=0)
      bounds = item.get_bounds()
      item.scale(scale, scale)

      if ((index+1)%5 == 0):
        goocanvas.Text(
          parent = self.itemgroup,
          x = (bounds.x2-bounds.x1)/2,
          y = -10,
          fill_color_rgba = 0x000000ffL,
          font=gcompris.skin.get_font("gcompris/board/small bold"),
          anchor = gtk.ANCHOR_CENTER,
          text = index + 1)
Example #25
0
  def __init__(self, rootitem, move_back_callback):

      rootitem = goocanvas.Group(parent = rootitem)
      item = \
          goocanvas.Rect(parent = rootitem,
                         x = 30,
                         y = 20,
                         width = 740,
                         height = 460,
                         stroke_color_rgba = 0x222222CCL,
                         fill_color_rgba = 0x999999EEL,
                         radius_x = 5.0,
                         radius_y = 5.0,
                         line_width = 2.0)
      item.connect("button_press_event", move_back_callback)

      # Place alphabets & numbers in array format
      for index, letter in enumerate(string.ascii_uppercase[:10]):
          BrailleChar(rootitem, index*(CELL_WIDTH+40)+60,
                              40, 38, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
                              CIRCLE_STROKE,True ,False ,True , None)
      for index, letter in enumerate(string.ascii_uppercase[10:20]):
          BrailleChar(rootitem, index*(CELL_WIDTH+40)+60,
                              130, 38, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
                              CIRCLE_STROKE,True ,False ,True , None)
      # Put the W at the end to align the braille codes properly
      for index, letter in enumerate(['U', 'V', 'X', 'Y', 'Z']):
          BrailleChar(rootitem, index*(CELL_WIDTH+40)+60,
                              220, 38, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
                              CIRCLE_STROKE,True ,False ,True , None)
      BrailleChar(rootitem, (index + 2) *(CELL_WIDTH+40)+60,
                  220, 38, 'W' ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
                  CIRCLE_STROKE,True ,False ,True , None)

      # The number line (Keep it aligned with the ASCII in the Braille sense)
      for index in range(0, 9):
          BrailleChar(rootitem, index *(CELL_WIDTH + 40)+60,
                      310, 38, index + 1,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
                      CIRCLE_STROKE, True ,False ,True , None)
      BrailleChar(rootitem, 9 *(CELL_WIDTH + 40)+60,
                  310, 38, 0 ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
                  CIRCLE_STROKE, True ,False ,True , None)

      # The math operators +-*/
      for index, value in enumerate( SYMBOL ):
        BrailleChar(rootitem,index * (CELL_WIDTH + 40) + 60,
                    400 , 38, SYMBOL[index], COLOR_ON, COLOR_OFF, CIRCLE_FILL,
                    CIRCLE_STROKE,True ,False ,True , None)

      # Move back item
      item = goocanvas.Image(parent = rootitem,
                             pixbuf = gcompris.utils.load_pixmap("braille_alphabets/back.svg"),
                             x = 430,
                             y = 400,
                             tooltip = _("Back to the activity")
                             )
      gcompris.utils.item_focus_init(item, None)
      item.connect("button_press_event", move_back_callback)
 def __init__(self, lang, parentitem, lesson):
     self.lang = lang
     self.lesson = lesson
     self.triplets = list(lesson.getTriplets())
     random.shuffle(self.triplets)
     self.rootitem = goocanvas.Group(parent=parentitem)
     self.gameroot = None
     self.currentIndex = 0
     self.tripletToFind = None
Example #27
0
  def __init__(self, game_instance, rootitem, land_rootitem, level):
    self.rootitem = rootitem
    self.game = game_instance
    self.level = level
    self.flame_rootitem = goocanvas.Group(parent = rootitem)
    self.land_rootitem = land_rootitem
    self.land_rootitem.lower(self.flame_rootitem)
    x = gcompris.BOARD_WIDTH/2
    y = 10

    # Load flames and hide them
    self.flame(x + 15, y)
    self.flame_1.props.visibility = goocanvas.ITEM_INVISIBLE
    self.flame_2.props.visibility = goocanvas.ITEM_INVISIBLE
    self.flame_3.props.visibility = goocanvas.ITEM_INVISIBLE
    self.flame_left.props.visibility = goocanvas.ITEM_INVISIBLE
    self.flame_right.props.visibility = goocanvas.ITEM_INVISIBLE

    # Load landing area
    self.land_x = random.randrange(100, 400)
    self.landing_red = goocanvas.Image(
      parent = self.land_rootitem,
      pixbuf = gcompris.utils.load_pixmap("land_safe/landing_area_red.png"),
      width = 145 - (self.level * 12),
      x = self.land_x,
      y = 365)
    self.landing_red.props.visibility = goocanvas.ITEM_INVISIBLE

    self.landing_green = goocanvas.Image(
      parent = self.land_rootitem,
      pixbuf = gcompris.utils.load_pixmap("land_safe/landing_area_green.png"),
      width = 145 - (self.level * 12),
      x = self.land_x,
      y = 365)

    # Load spaceship
    pixbuf = gcompris.utils.load_pixmap("land_safe/rocket.png")
    self.spaceship_image = goocanvas.Image(
      parent = rootitem,
      pixbuf = pixbuf,
      x = x,
      y = y
      )

    # Declaring variables
    self.y = 0.005
    self.x = 0
    self.key_vertical = 4
    self.zoom_out = False
    self.scale = 1

    # Load fuel, altitude and landing area
    self.info = Display(self, rootitem)

    # Set to true to stop the timeout
    self.done = False
Example #28
0
  def newGame(self):
    self.cleanup()

    width_ref = 256

    scale = self.scales[self.gcomprisBoard.sublevel-1]

    self.last_played = -1
    self.finished_sublevel = False
    self.game_won = False
    self.list_win = self.calculate_win_places()


    # Create root item canvas for the board
    self.rootitem = goocanvas.Group(parent = self.gcomprisBoard.canvas.get_root_item())

    # background
    gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
                            backgrounds[self.gcomprisBoard.level - 1])

    self.profbutton.set_prof(profs[self.gcomprisBoard.level - 1])

    for i in range(self.board_size[self.gcomprisBoard.sublevel-1]):
      self.holes.append(self.hole(self,
                                  self.rootitem,
                                  i * width_ref * scale,
                                  gcompris.BOARD_HEIGHT - 140, i,
                                  self.board_size[self.gcomprisBoard.sublevel-1],
                                  scale))

    for i in range(self.number_balls[self.gcomprisBoard.sublevel-1][1]):
      self.balls.append(self.ball(self.rootitem,
                                  i * width_ref * scale + 150,
                                  gcompris.BOARD_HEIGHT - 200,
                                  scale,
                                  self.pixmap_blue_ball))
      self.balls.append(self.ball(self.rootitem,
                                  i * width_ref * scale +150,
                                  gcompris.BOARD_HEIGHT-90,
                                  scale,
                                  self.pixmap_green_ball))

    self.answer.set_number_of_balls(self.number_balls[self.gcomprisBoard.sublevel-1])

    # The OK Button
    item = goocanvas.Svg(parent = self.rootitem,
                         svg_handle = gcompris.skin.svg_get(),
                         svg_id = "#OK"
                         )
    item.translate(item.get_bounds().x1 * -1
                   + gcompris.BOARD_WIDTH - (item.get_bounds().x2 - item.get_bounds().x1) - 10,
                   item.get_bounds().y1 * -1
                   + gcompris.BOARD_HEIGHT - 230)

    item.connect("button_press_event", self.ok_event)
    gcompris.utils.item_focus_init(item, None)
Example #29
0
    def start(self):
        self.gcomprisBoard.level = 1
        self.gcomprisBoard.maxlevel = 4
        self.gcomprisBoard.sublevel = 1
        self.gcomprisBoard.number_of_sublevel = 1

        self.board_paused = False

        # 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())

        gcompris.set_default_background(
            self.gcomprisBoard.canvas.get_root_item())

        self.display_sea_area()

        self.root_weather_item = goocanvas.Group(parent=self.rootitem)

        # Display the weather now
        self.display_weather()

        # And finaly the players boats
        self.init_boats()

        gcompris.bar_set(gcompris.BAR_LEVEL | gcompris.BAR_REPEAT)

        # The OK Button
        item = goocanvas.Svg(parent=self.rootitem,
                             svg_handle=gcompris.skin.svg_get(),
                             svg_id="#OK")
        zoom = 0.7
        item.translate(
            (item.get_bounds().x1 * -1) +
            (gcompris.BOARD_WIDTH / 2 + 25) / zoom,
            (item.get_bounds().y1 * -1) + (gcompris.BOARD_HEIGHT - 135) / zoom)
        item.scale(zoom, zoom)
        item.connect("button_press_event", self.ok_event)
        gcompris.utils.item_focus_init(item, None)

        gcompris.bar_set_level(self.gcomprisBoard)
        gcompris.bar_location(gcompris.BOARD_WIDTH / 2 - 105, -1, 0.6)
Example #30
0
    def init(self, index, select_area, callback):
        height = 90
        x   = select_area[0] + (select_area[2] - select_area[0]) / 2
        y1  = select_area[1] + height * index + 2
        y2  = select_area[1] + height * (index + 1) + 1

        # 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_select_item = goocanvas.Group(
            parent = self.canvas,
            )

        self.select_item = goocanvas.Rect(
            parent = self.root_select_item,
            x = select_area[0]+2,
            y = y1,
            width = select_area[2] - select_area[0] - 4,
            height = y2 - y1,
            fill_color="white",
            stroke_color="white",
            line_width = 1.0
            )
        self.select_item.connect("button_press_event", callback, self)

        y1 += 5

        itemimg = goocanvas.Svg(
            parent = self.root_select_item,
            svg_handle = gcompris.utils.load_svg("administration/config_" +
                                                self.module_name +
                                                 ".svgz")
            )

        bounds = itemimg.get_bounds()
        centered_x = x - (bounds.x2 - bounds.x1)/2
        itemimg.translate(centered_x, y1);
        itemimg.connect("button_press_event", callback, self)
        gcompris.utils.item_focus_init(itemimg, None)

        y1 += bounds.y2 - bounds.y1 + 3

        item = goocanvas.Text(
            parent = self.root_select_item,
            text=_(self.module_label),
            font = "Sans 8",
            x = centered_x,
            y = y1,
            fill_color="black"
            )
        bounds = item.get_bounds()
        centered_x = x - (bounds.x2 - bounds.x1)/2
        item.props.x = centered_x
        item.connect("button_press_event", callback, self)
        gcompris.utils.item_focus_init(item, itemimg)