Esempio n. 1
0
 def __init__(self, rootitem, svghandle, update_conso_count, switch_on,
              switch_off, target_on, target_off, power):
     self.power_count = power
     self.consumption = 0
     self.update_conso_count = update_conso_count
     self.switch_on = goocanvas.Svg(parent=rootitem,
                                    svg_handle=svghandle,
                                    svg_id=switch_on,
                                    visibility=goocanvas.ITEM_INVISIBLE)
     self.switch_on.connect("button_press_event",
                            self.lightbutton_item_event_on)
     gcompris.utils.item_focus_init(self.switch_on, None)
     self.switch_off = goocanvas.Svg(parent=rootitem,
                                     svg_handle=svghandle,
                                     svg_id=switch_off,
                                     visibility=goocanvas.ITEM_INVISIBLE)
     self.switch_off.connect("button_press_event",
                             self.lightbutton_item_event_off)
     gcompris.utils.item_focus_init(self.switch_off, None)
     self.target_on = goocanvas.Svg(parent=rootitem,
                                    svg_handle=svghandle,
                                    svg_id=target_on,
                                    visibility=goocanvas.ITEM_INVISIBLE)
     if target_off:
         self.target_off = goocanvas.Svg(
             parent=rootitem,
             svg_handle=svghandle,
             svg_id=target_off,
             visibility=goocanvas.ITEM_INVISIBLE)
     else:
         self.target_off = None
     # Is there power comming in
     self.power = False
     # Is the light is switched on
     self.is_on = False
Esempio n. 2
0
  def __init__(self, penalty, svghandle, x, y):

    self.penalty = penalty
    self.rootitem = penalty.rootitem
    self.x = x
    self.y = y

    # Balloon shadow
    self.shadow = goocanvas.Svg(
      parent = self.rootitem,
      svg_handle = svghandle,
      svg_id = "#BALLOON_SHADOW"
      )

    # Balloon
    self.item = goocanvas.Svg(
      parent = self.rootitem,
      svg_handle = svghandle,
      svg_id = "#BALLOON"
      )

    bounds = self.item.get_bounds()
    self.size = bounds.y2 - bounds.y1

    # Save the original position of the balloon
    self.item_bounds = self.item.get_bounds()
Esempio n. 3
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)
Esempio n. 4
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)
 def __init__(self, rootitem, svghandle, svg_id, tooltip, x, y):
     self.item = goocanvas.Svg(parent=rootitem,
                               svg_handle=svghandle,
                               svg_id=svg_id,
                               tooltip="\n\n\n" + tooltip)
     self.text = goocanvas.Text(parent=rootitem,
                                x=x,
                                y=y,
                                font="Sans 8",
                                text="0W",
                                tooltip="\n\n\n" + tooltip)
Esempio n. 6
0
 def show_play_button(self):
     # Create an audio button to let the user ear again the letter to find
     self.play_item = goocanvas.Svg(parent=self.rootitem,
                                    svg_handle=gcompris.skin.svg_get(),
                                    svg_id="#SOUND")
     item = self.play_item
     item.translate(
         item.get_bounds().x1 * -1 + gcompris.BOARD_WIDTH -
         (item.get_bounds().x2 - item.get_bounds().x1) - 30,
         item.get_bounds().y1 * -1 + 430)
     item.connect("button_press_event", self.play_event)
     gcompris.utils.item_focus_init(item, None)
Esempio n. 7
0
 def __init__(self, rootitem, svghandle, svg_id, tooltip, x, y):
     self.item = goocanvas.Svg(parent=rootitem,
                               svg_handle=svghandle,
                               svg_id=svg_id,
                               tooltip="\n\n\n" + tooltip)
     self.text = goocanvas.Text(
         parent=rootitem,
         x=x,
         y=y,
         font=gcompris.skin.get_font("gcompris/board/minuscule"),
         text="0W",
         tooltip="\n\n\n" + tooltip)
Esempio n. 8
0
 def display_ok(self):
   # The OK Button
   item = goocanvas.Svg(parent = self.rootitem,
                        svg_handle = gcompris.skin.svg_get(),
                        svg_id = "#OK"
                        )
   zoom = 0.8
   item.translate( (item.get_bounds().x1 * -1)
                    + ( gcompris.BOARD_WIDTH - 300 ) / zoom,
                   (item.get_bounds().y1 * -1) + 190.0 / zoom)
   item.scale(zoom, zoom)
   item.connect("button_press_event", self.ok_event)
   gcompris.utils.item_focus_init(item, None)
Esempio n. 9
0
    def waitOK(self, rootitem):
        # The OK Button
        self.ok_item = goocanvas.Svg(parent=rootitem,
                                     svg_handle=gcompris.skin.svg_get(),
                                     svg_id="#OK")
        item = self.ok_item
        item.translate(
            item.get_bounds().x1 * -1 + gcompris.BOARD_WIDTH -
            (item.get_bounds().x2 - item.get_bounds().x1) - 30,
            item.get_bounds().y1 * -1 + 65)

        item.connect("button_press_event", self.ok_event, None)
        gcompris.utils.item_focus_init(item, None)
Esempio n. 10
0
  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()
Esempio n. 11
0
  def __init__(self, rootitem, svghandle):
    """
    Constructor
        rootitem    : The goocanvas item to add the mouse to
        svghandle   : Handle of the svg file, containing the graphics
    """

    self.circle_img = goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#CURSOR_TARGET",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      )

    self.cursor_img = goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#MOUSE_CURSOR",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      )

    # initialize and document instance variables

    self.circle_x = 0.0
    """ x position of the center of the cursor target in screen coordinates (800 x 520) """

    self.circle_y = 0.0
    """ y position of the center of the cursor target in screen coordinates (800 x 520) """

    self.cursor_x = 0.0
    """ x position of the center of the ghost mouse cursor in screen coordinates (800 x 520) """

    self.cursor_y = 0.0
    """ y position of the center of the ghost mouse cursor in screen coordinates (800 x 520) """
Esempio n. 12
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)
Esempio n. 13
0
    def decorate_viewport(self, number_of_decorations):
        """ Fill the viewport with some decorations """

        assert (self.decoration_group == None)
        self.decoration_group = goocanvas.Group(parent=self.viewport_gc_group)

        for i in range(number_of_decorations):
            # select random decoration
            self.current_decoration_id = random.randrange(4)
            svg_id = self.decoration_types[
                self.current_decoration_id]['svg_id']

            # create decoration
            decoration = goocanvas.Svg(
                parent=self.decoration_group,
                svg_handle=self.svghandle,
                svg_id=svg_id,
            )

            self.placer.place(decoration, self.__place_decoration)
Esempio n. 14
0
    def __init__(self, svghandle, parent):
        """
    Constructor:
      svghandle : handle to the svg file, holding the pictures
      parent    : GooCanvas parent item of this spark
    """

        # initialize and document instance variables

        self.spark = goocanvas.Svg(
            parent=parent,
            svg_handle=svghandle,
            svg_id="#SPARK",

            # start invisible, since x/y are not set properly yet
            visibility=goocanvas.ITEM_INVISIBLE)
        """ the spark image in the GooCanvas """

        self.x = 0.0
        """ x position of the spark (in the rockwall/gc_group) """

        self.y = 0.0
        """ y position of the spark (in the rockwall/gc_group) """

        self.angle = 0
        """ rotation (in degrees) """

        self.rot_delta = 0
        """ the amount to rotate at every animation step """

        self.scale = 0
        """ the sparks current scale factor """

        self.timer = None
        """ the timer object, firing timeout-events for our animation """

        self.pause_ticks_current = 0
        """ counts the number of elapsed pause ticks between two spark-phases """
Esempio n. 15
0
    def __init__(self, svghandle, parent):
        """
    Constructor:
      svghandle      : handle to the svg file, holding the pictures
      parent         : GooCanvas parent item of the gold nugget
    """

        # initialize and document instance variables

        self.x = 0.0
        """ x position of the nugget (in the rockwall/gc_group) """

        self.y = 0.0
        """ y position of the nugget (in the rockwall/gc_group) """

        self.nugget_img = goocanvas.Svg(
            parent=parent,
            svg_handle=svghandle,
            svg_id="#NUGGET",

            # start invisible, since x/y are not set properly yet
            visibility=goocanvas.ITEM_INVISIBLE)
        """ picture of the nugget """
Esempio n. 16
0
    def __init__(self, svghandle, rootitem):
        """
    Constructor:
      svghandle          : handle of the svg file, containing graphics data
      rootitem           : the root item to attach goo-object to
    """

        self.lorry_img = goocanvas.Svg(
            parent=rootitem,
            svg_handle=svghandle,
            svg_id="#LORRY",
        )

        self.text = goocanvas.Text(
            parent=rootitem,
            font=gcompris.skin.get_font("gcompris/board/medium"),
            x=self.x + 9,
            y=self.y + 2,
            anchor=gtk.ANCHOR_CENTER,
            fill_color="white",
            text="-/-")

        self.__update_transformation()
Esempio n. 17
0
    def drawLocations(self):
        '''
        draw image on the map, one for each section in content.desktop.in at the
        location specified in the file by 'x' and 'y'.
        '''
        if self.gcomprisBoard.level == 1:
            method = self.goto_location
        else:
            method = self.checkAnswer

        for section in self.sectionNames:

            item = goocanvas.Svg(
                parent=self.rootitem,
                svg_handle=self.svghandle,
                svg_id=self.data.get(section, 'svgId'),
            )

            gcompris.utils.item_focus_init(item, None)
            item.set_data('sectionNum', section)
            item.set_data('seen', False)
            # Set the proper callback depending on the level
            item.connect("button_press_event", method)
Esempio n. 18
0
    def __init__(self, computer, components_class):
        self.computer = computer
        self.rootitem = computer.rootitem

        goocanvas.Svg(parent=self.rootitem,
                      svg_handle=gcompris.skin.svg_get(),
                      svg_id="#SELECTOR")

        self.x = 15
        self.y = 60

        index_y = 10
        gap = 20
        width = 70
        height = 70
        self.init_coord = {}
        self.offset_x = self.offset_y = 0

        for component_class in components_class:
            pixmap = gcompris.utils.load_pixmap(component_class.icon)
            item = goocanvas.Image(parent=self.rootitem,
                                   pixbuf=pixmap,
                                   width=width,
                                   height=height,
                                   x=self.x,
                                   y=self.y + index_y)

            self.init_coord[component_class] = (self.x, self.y + index_y)
            index_y += height + gap

            item.connect("button_press_event", self.component_click,
                         component_class)
            item.connect("button_release_event", self.component_click,
                         component_class)
            item.connect("motion_notify_event", self.component_click,
                         component_class)
Esempio n. 19
0
    def display_game(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.rootitem = goocanvas.Group(
            parent=self.gcomprisBoard.canvas.get_root_item())

        self.min = 1
        self.max = 10
        if (self.gcomprisBoard.level == 2):
            self.max = 100
        elif (self.gcomprisBoard.level == 3):
            self.max = 500
        elif (self.gcomprisBoard.level == 4):
            self.max = 1000

        # Select the number to find
        self.solution = random.randint(self.min, self.max)

        text = _("Guess a number between {0} and {1}").format(
            self.min, self.max)

        goocanvas.Text(
            parent=self.rootitem,
            x=10.0,
            y=30.0,
            font=gcompris.skin.get_font("gcompris/subtitle"),
            text=(text),
            fill_color_rgba=0x1514c4ffL,
        )

        self.indicator = goocanvas.Text(
            parent=self.rootitem,
            x=400.0,
            y=70.0,
            width=700,
            font=gcompris.skin.get_font("gcompris/subtitle"),
            text=(""),
            fill_color_rgba=0xff0006ffL,
            anchor=gtk.ANCHOR_CENTER,
            alignment=pango.ALIGN_CENTER,
        )

        text_item = self.entry_text()

        #
        # Display the helico
        #
        pixmap = gcompris.utils.load_pixmap("guessnumber/tuxhelico.png")
        self.helico_width = pixmap.get_width()
        self.helico_height = pixmap.get_height()
        self.orig_x = self.x_old = self.x = 20
        self.y_old = self.y = self.orig_y

        self.anim = goocanvas.Image(
            parent=self.rootitem,
            pixbuf=pixmap,
            x=self.x,
            y=self.y,
        )

        # 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) - 30,
            item.get_bounds().y1 * -1 + 65)

        item.connect("button_press_event", self.ok_event, text_item)
        gcompris.utils.item_focus_init(item, None)
Esempio n. 20
0
    def start(self):
        self.gcomprisBoard.level = 1
        self.gcomprisBoard.maxlevel = 3

        # Just a tick counter
        self.tick = 0

        self.boat_is_arrived = False
        self.reset_state = True
        self.gamewon = False
        # The basic duration factor for object animations
        # Higher is longer animation (slower)
        self.timerinc = 20
        self.step_time = 100

        # Need to manage the timers to quit properly
        self.waterlevel_timer = 0

        gcompris.sound.play_ogg("sounds/Harbor1.wav", "sounds/Harbor3.wav")

        # 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.svghandle = gcompris.utils.load_svg(
            "hydroelectric/hydroelectric.svgz")
        goocanvas.Svg(parent=self.rootitem,
                      svg_handle=self.svghandle,
                      svg_id="#BACKGROUND",
                      pointer_events=goocanvas.EVENTS_NONE)

        # Take care, the items are stacked on each other in the order you add them.
        # If you need, you can reorder them later with raise and lower functions.

        # The River
        self.riveritem = goocanvas.Svg(parent=self.rootitem,
                                       svg_handle=self.svghandle,
                                       svg_id="#RIVERWATER",
                                       pointer_events=goocanvas.EVENTS_NONE,
                                       visibility=goocanvas.ITEM_INVISIBLE)

        # The Sun
        self.sunitem = goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = self.svghandle,
          svg_id = "#SUN",
          tooltip = "\n\n\n" + \
            _("The sun heats the water and creates water vapor. "
              "Water vapor combines into small water droplets which "
              "becomes clouds.")
          )
        self.sunitem.connect("button_press_event", self.sun_item_event)
        # This item is clickeable and it must be seen
        gcompris.utils.item_focus_init(self.sunitem, None)
        self.sun_on = 0
        self.sunitem_orig_y1 = self.sunitem.get_bounds().y1
        self.sunitem_bounds = self.sunitem.get_bounds()
        self.sunitem_target_y1 = 10
        self.sun_connect_handler = 0

        # The Snow
        self.snowitem = goocanvas.Svg(parent=self.rootitem,
                                      svg_handle=self.svghandle,
                                      svg_id="#SNOW",
                                      pointer_events=goocanvas.EVENTS_NONE,
                                      visibility=goocanvas.ITEM_INVISIBLE)

        # The rain
        self.rainitem = goocanvas.Svg(parent=self.rootitem,
                                      svg_handle=self.svghandle,
                                      svg_id="#RAIN",
                                      pointer_events=goocanvas.EVENTS_NONE,
                                      visibility=goocanvas.ITEM_INVISIBLE)

        # The cloud
        self.clouditem = goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = self.svghandle,
          svg_id = "#CLOUD",
          visibility = goocanvas.ITEM_INVISIBLE,
          tooltip = "\n\n\n" + \
            _("As a cloud matures, the dense water droplets may combine "
              "to produce larger droplets, which may combine to form "
              "droplets large enough to fall as rain")
          )
        self.clouditem.props.visibility = goocanvas.ITEM_INVISIBLE
        self.clouditem.connect("animation-finished", self.cloud_arrived)
        self.cloud_on = False
        self.cloud_is_arrived = False
        self.clouditem_bounds = self.clouditem.get_bounds()
        self.its_raining = False

        # The vapor
        self.vaporitem = goocanvas.Svg(parent=self.rootitem,
                                       svg_handle=self.svghandle,
                                       svg_id="#VAPOR",
                                       pointer_events=goocanvas.EVENTS_NONE,
                                       visibility=goocanvas.ITEM_INVISIBLE)
        self.vaporitem.connect("animation-finished", self.vapor_arrived)
        self.vaporitem_bounds = self.vaporitem.get_bounds()

        # The reservoir level
        self.reservoirlevel = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=self.svghandle,
            svg_id="#RESERVOIR1",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        # The Dam
        goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=self.svghandle,
            svg_id="#DAM",
            pointer_events=goocanvas.EVENTS_NONE,
        )

        # The DAM'S TURBINE
        self.dam_turbine = \
          Producer(self.rootitem, self.svghandle,
                   Counter( self.rootitem, self.svghandle,
                            "#DAM_PROD_COUNT",
                            #Translator : "meter" here means a measuring device
                            _("This is the meter for electricity produced by the turbine. ") + \
                            _("The electricity power is measured in watts (W)."),
                            303, 224 ),
                   self.update_prod_count,
                   None,
                   [ "#TURBINE" ],
                   _("Flowing water is directed on to the blades of a turbine runner, "
                     "creating a force on the blades. In this way, energy is transferred "
                     "from the water flow to the turbine"),
                   "#TURBINE_CABLE_ON",
                   "#TRANSFORMER_DAM",
                   "#TRANSFORMER_DAM_TO_USERS",
                   1000)

        # The Wind
        self.winditem_off = goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = self.svghandle,
          svg_id = "#WIND_OFF",
          tooltip = "\n\n\n" + \
            _("This cloud simulates the wind, click on it to have wind.")
          )
        self.winditem_off.connect("button_press_event", self.wind_item_event)
        # This item is clickable and it must be seen
        gcompris.utils.item_focus_init(self.winditem_off, None)

        self.winditem_on = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=self.svghandle,
            svg_id="#WIND_ON",
            visibility=goocanvas.ITEM_INVISIBLE,
            pointer_events=goocanvas.EVENTS_NONE,
        )
        self.wind = False

        # The Cable from transformer 2 to Town
        self.cable_to_town_on = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=self.svghandle,
            svg_id="#CABLE_TO_TOWN_ON",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)
        # The Cable from transformer 2 to Tux
        self.cable_to_tux_on = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=self.svghandle,
            svg_id="#CABLE_TO_TUX_ON",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        # TRANSFORMER2
        self.transformer2item = goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = self.svghandle,
          svg_id = "#TRANSFORMER2",
          tooltip = "\n\n\n" + \
            _("This is a step down transformer. Electricity is transformed "
              "in low voltage, ready to be used by the customers.")
          )
        self.transformer2item.connect("button_press_event",
                                      self.transformer2_item_event)
        # This item is clickeable and it must be seen
        gcompris.utils.item_focus_init(self.transformer2item, None)
        self.transformer2_on = 0

        # The tuxboat
        self.boatitem = goocanvas.Svg(parent=self.rootitem,
                                      svg_handle=self.svghandle,
                                      svg_id="#BOAT",
                                      pointer_events=goocanvas.EVENTS_NONE)
        self.boatitem.translate(-100, 0)
        self.boatitem_bounds = self.boatitem.get_bounds()
        self.boatitem.connect("animation-finished", self.boat_arrived)
        self.boatitem_parked = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=self.svghandle,
            svg_id="#BOAT_PARKED",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        # Tux in his saloon
        self.tuxsaloonitem = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=self.svghandle,
            svg_id="#SALOON",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        goocanvas.Svg(parent=self.rootitem,
                      svg_handle=self.svghandle,
                      svg_id="#FOREGROUND",
                      pointer_events=goocanvas.EVENTS_NONE)

        # The level of water in the reservoir
        self.waterlevel_max = 5
        self.waterlevel_min = 1
        self.waterlevel = 0
        self.waterlevel_timer = gobject.timeout_add(1000, self.update)

        # We have 2 counters, the production one and the consumption
        # The children have to make sure there is no more consumption
        # than production.
        self.prod_count = 0
        self.conso_count = 0

        self.production_counter = \
            Counter( self.rootitem, self.svghandle,
                     "#PROD_COUNT",
                     #Translator : "meter" here means a measuring device
                     _("This is the meter for all the electricity produced. ") + \
                     _("The electricity power is measured in watts (W)."),
                     525, 226 )

        self.consumers_counter = \
            Counter( self.rootitem, self.svghandle,
                     "#CONSO_COUNT",
                     #Translator : "meter" here means a measuring device
                     _("This is the meter for electricity consumed by the users. ") + \
                     _("The electricity power is measured in watts (W)."),
                     590, 203 )

        self.consumers = []
        self.conso_tux = Consumer(self.rootitem, self.svghandle,
                                  self.update_conso_count, "#LIGHT_BUTTON_ON",
                                  "#LIGHT_BUTTON_OFF", "#TUX_ON", "#TUX_OFF",
                                  100)
        self.conso_house = Consumer(self.rootitem, self.svghandle,
                                    self.update_conso_count, "#LIGHT_HOUSE_ON",
                                    "#LIGHT_HOUSE_OFF", "#HOUSE_LIGHTS_ON",
                                    None, 400)
        self.conso_building = Consumer(self.rootitem, self.svghandle,
                                       self.update_conso_count,
                                       "#LIGHT_BUILDING_ON",
                                       "#LIGHT_BUILDING_OFF",
                                       "#BUILDING_LIGHTS_ON", None, 800)

        # The solar panel
        self.solar_array = \
          Producer(self.rootitem, self.svghandle,
                   Counter( self.rootitem, self.svghandle,
                            "#SOLAR_PANEL_COUNT",
                            #Translator : "meter" here means a measuring device
                            _("This is the meter for electricity produced by the solar panels. ") + \
                            _("The electricity power is measured in watts (W)."),
                            697, 177 ),
                   self.update_prod_count,
                   "#SOLAR_PANEL_BG",
                   [ "#SOLAR_PANEL_OFF", "#SOLAR_PANEL_ON" ],
                   _("Solar panels use light energy (photons) from the sun to "
                     "generate electricity through the photovoltaic effect."),
                   "#SOLAR_PANEL_CABLE_ON",
                   "#TRANSFORMER_SOLAR_PANEL",
                   "#TRANSFORMER_SOLAR_PANEL_TO_USERS",
                   400)

        # The Wind farm
        self.windfarmitems = []
        for i in range(1, 4):
            self.windfarmitems.append("#WIND_FARM_" + str(i))

        self.wind_farm = \
          Producer(self.rootitem, self.svghandle,
                   Counter( self.rootitem, self.svghandle,
                            "#WIND_FARM_COUNT",
                            #Translator : "meter" here means a measuring device
                            _("This is the meter for electricity produced by the wind turbines. ") + \
                            _("The electricity power is measured in watts (W)."),
                            650, 137 ),
                   self.update_prod_count,
                   "#WIND_FARM_BG",
                   self.windfarmitems,
                   _("A wind turbine is a device that converts wind motion energy "
                     "into electricity generation. It is called a wind generator or "
                     "wind charger. "),
                   "#WINDFARM_CABLE_ON",
                   "#TRANSFORMER_WINDFARM",
                   "#TRANSFORMER_WINDFARM_TO_USERS",
                   600)

        # Some item ordering
        self.rainitem.raise_(None)
        self.clouditem.raise_(None)
        self.vaporitem.raise_(None)

        gcompris.bar_set(gcompris.BAR_LEVEL)
        gcompris.bar_location(5, -1, 0.6)
        gcompris.bar_set_level(self.gcomprisBoard)
        self.next_level()
Esempio n. 21
0
    def __init__(self, rootitem, svghandle, counter, update_prod_count,
                 background_id, prod_items, tooltip, prod_item_on, transformer,
                 transformer_on, power):
        self.power_count = power
        self.counter = counter
        self.production = 0
        self.update_prod_count = update_prod_count

        # Is there enough renewable energy to run this producer
        self.energy = False

        self.background_item = None
        if background_id:
            self.background_item = goocanvas.Svg(
                parent=rootitem,
                svg_handle=svghandle,
                svg_id=background_id,
                pointer_events=goocanvas.EVENTS_NONE)

        done = False
        self.current_prod_item = 0
        self.prod_items = []
        for svg_id in prod_items:
            item = goocanvas.Svg(
              parent = rootitem,
              svg_handle = svghandle,
              svg_id = svg_id,
              visibility = \
                goocanvas.ITEM_VISIBLE if not done else goocanvas.ITEM_INVISIBLE,
              tooltip = "\n\n\n" + tooltip
            )
            done = True
            item.connect("button_press_event", self.runbutton_item_event)
            gcompris.utils.item_focus_init(item, None)
            self.prod_items.append(item)

        self.prod_item_on = goocanvas.Svg(parent=rootitem,
                                          svg_handle=svghandle,
                                          svg_id=prod_item_on,
                                          pointer_events=goocanvas.EVENTS_NONE,
                                          visibility=goocanvas.ITEM_INVISIBLE)

        self.transformer = goocanvas.Svg(
          parent = rootitem,
          svg_handle = svghandle,
          svg_id = transformer,
          tooltip = "\n\n\n" + \
            _("This is a step up transformer. Electricity is transmitted "
              "at high voltages (110 kV or above) "
              "to reduce the energy lost in long distance transmission.")
          )
        self.transformer.connect("button_press_event",
                                 self.powerbutton_item_event)
        gcompris.utils.item_focus_init(self.transformer, None)

        self.transformer_on = goocanvas.Svg(
            parent=rootitem,
            svg_handle=svghandle,
            svg_id=transformer_on,
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        # Is the power on
        self.power = False
        # Is the run is switched on
        self.is_on = False
        # The animation timer
        self.timer = 0
        self.enabled = True
Esempio n. 22
0
    def display_level(self, level):

        if self.rootitem:
            self.rootitem.remove()

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

        if (level == 1):
            gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
                                    "braille_alphabets/braille_tux.svgz")
            goocanvas.Text(parent=self.rootitem,
                           x=385,
                           y=100,
                           fill_color="black",
                           font=gcompris.skin.get_font("gcompris/title"),
                           anchor=gtk.ANCHOR_CENTER,
                           text=_("Braille : Unlocking the Code"))
            # Braille Intro
            text = _(
                "The Braille system is a method that is used by blind people to read and write."
            )
            # Braille Description
            text += "\n" + \
                _("Each Braille character, or cell, is made up of six dot positions, arranged in "
                  "a rectangle containing two columns of three dots each. As seen on the left, each dot "
                  "is referenced by a number from 1 to 6.")
            goocanvas.Text(parent=self.rootitem,
                           x=490,
                           y=280,
                           fill_color="black",
                           font=gcompris.skin.get_font("gcompris/medium"),
                           width=395,
                           anchor=gtk.ANCHOR_CENTER,
                           text=text)

            # TUX svghandle
            svghandle = gcompris.utils.load_svg(
                "braille_alphabets/braille_tux.svgz")
            self.tuxitem = goocanvas.Svg(parent=self.rootitem,
                                         svg_handle=svghandle,
                                         svg_id="#TUX-5",
                                         tooltip=_("I am braille TUX"))
            self.tuxitem.connect("button_press_event", self.next_level)
            gcompris.utils.item_focus_init(self.tuxitem, None)

            goocanvas.Text(parent=self.rootitem,
                           x=445,
                           y=475,
                           fill_color="black",
                           font=gcompris.skin.get_font("gcompris/board/tiny"),
                           anchor=gtk.ANCHOR_CENTER,
                           width=355,
                           text=_(
                               "When you are ready, click on "
                               "me and try reproducing Braille characters."))
        elif (level == 2):
            self.show_play_button()
            chars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
            self.gcomprisBoard.number_of_sublevel = len(chars)
            if self.gcomprisBoard.sublevel == 1:
                self.chars_shuffled = list(chars)
                random.shuffle(self.chars_shuffled)
            self.board_tile(chars)
            self.random_letter = self.chars_shuffled[
                self.gcomprisBoard.sublevel - 1]
            self.braille_cell(level)

        elif (level == 3):
            self.show_play_button()
            chars = ['K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T']
            self.gcomprisBoard.number_of_sublevel = len(chars)
            if self.gcomprisBoard.sublevel == 1:
                self.chars_shuffled = list(chars)
                random.shuffle(self.chars_shuffled)
            self.board_tile(chars)
            self.random_letter = self.chars_shuffled[
                self.gcomprisBoard.sublevel - 1]
            self.braille_cell(level)

        elif (level == 4):
            self.show_play_button()
            chars = ['U', 'V', 'X', 'Y', 'Z', 'W']
            self.gcomprisBoard.number_of_sublevel = len(chars)
            if self.gcomprisBoard.sublevel == 1:
                self.chars_shuffled = list(chars)
                random.shuffle(self.chars_shuffled)
            self.board_tile(chars)
            self.random_letter = self.chars_shuffled[
                self.gcomprisBoard.sublevel - 1]
            self.braille_cell(level)

        elif (level == 5):
            self.show_play_button()
            chars = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
            self.gcomprisBoard.number_of_sublevel = len(chars)
            if self.gcomprisBoard.sublevel == 1:
                self.chars_shuffled = list(chars)
                random.shuffle(self.chars_shuffled)
            self.board_number()
            self.random_letter = self.chars_shuffled[
                self.gcomprisBoard.sublevel - 1]
            self.braille_cell(level)
Esempio n. 23
0
  def __init__(self, game, rootitem, level, initial_color):
    self.game = game
    self.rootitem = rootitem
    self.initial_color = initial_color

    if initial_color == 0:
      self.color_1 = [ _("Not enough red"), _("Too much red")]
      self.color_2 = [ _("Not enough green"), _("Too much green")]
      self.color_3 = [ _("Not enough blue"), _("Too much blue")]
    else:
      self.color_1 = [ _("Not enough cyan"), _("Too much cyan")]
      self.color_2 = [ _("Not enough magenta"), _("Too much magenta")]
      self.color_3 = [ _("Not enough yellow"), _("Too much yellow")]

    self.color_rgb = [initial_color, initial_color, initial_color]
    self.color1 = self.color2 = self.color3 = self.initial_color
    self.color_cmy = [255 - self.color_rgb[0], 255 - self.color_rgb[1],
                 255 - self.color_rgb[2]]

    init_color = self.hex_code(initial_color, initial_color, initial_color)
    self.color_image = goocanvas.Ellipse(
      parent = rootitem,
      center_x = 395,
      center_y = 230,
      radius_y = 60,
      radius_x = 75,
      stroke_color = "black",
      fill_color_rgba = long(init_color,16),
      line_width = 1)

    # Random color to be matched
    self.increment = int(255/ (level * 2 + 1))
    rand_r = random.randrange(0, 2 * level + 1)
    rand_g = random.randrange(0, 2 * level + 1)
    rand_b = random.randrange(0, 2 * level + 1)

    self.r_random = rand_r * self.increment
    self.g_random = rand_g * self.increment
    self.b_random = rand_b * self.increment
    self.required_color_cmy = [255 - self.r_random, 255 - self.g_random,
                 255 - self.b_random]
    code = self.hex_code(self.r_random, self.g_random, self.b_random)

    random_color = goocanvas.Rect(
      parent = rootitem,
      radius_x = 6,
      radius_y = 6,
      x = 350,
      y = 50,
      width = 100,
      height = 70,
      stroke_color = "black",
      line_width = 1,
      fill_color_rgba = long(code, 16))

    # OK Button
    ok = goocanvas.Svg(parent = rootitem,
                       svg_handle = gcompris.skin.svg_get(),
                       svg_id = "#OK"
                       )
    ok.translate(0, -130)

    ok.connect("button_press_event", self.ok_event)
    gcompris.utils.item_focus_init(ok, None)
    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='SANS 50')
            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='SANS 50')
            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)
Esempio n. 25
0
    def braille_cell(self, level):
        self.play_letter(self.random_letter)

        # Translators : Do not translate the token {letter}
        message = _("Click on the dots in braille cell area to produce the "
                    "letter {letter}.").format(letter=self.random_letter)

        self.letter = "alphabet"
        if (level == 3):
            message += "\n" + _(
                "Look at the Braille character map and observe how "
                "similar the first and second line are.")
        elif (level == 4):
            message += "\n" + _(
                "Again, similar as the first line but take care, "
                "the 'W' letter was added afterwards.")
        elif (level == 5):
            message += "\n" + _(
                "This is easy, numbers are the same as letters "
                "from A to J.")
            self.letter = "number"

        gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
                                "braille_alphabets/mosaic.svgz")

        goocanvas.Text(parent=self.rootitem,
                       x=400,
                       y=200,
                       text=message,
                       fill_color="black",
                       font=gcompris.skin.get_font("gcompris/board/medium"),
                       width=780,
                       anchor=gtk.ANCHOR_CENTER,
                       alignment=pango.ALIGN_CENTER)

        goocanvas.Text(
            parent=self.rootitem,
            x=160.0,
            y=250.0,
            text=_("Braille Cell"),
            fill_color="black",
            font=gcompris.skin.get_font("gcompris/board/medium bold"))

        BrailleChar(self.rootitem,
                    150,
                    270,
                    120,
                    '',
                    COLOR_ON,
                    COLOR_OFF,
                    CIRCLE_FILL,
                    CIRCLE_STROKE,
                    False,
                    True,
                    False,
                    callback=self.letter_change,
                    braille_letter=self.letter)

        for i in range(2):
            for j in range(3):
                goocanvas.Text(
                    parent=self.rootitem,
                    text=(str(j + 1 + i * 3)),
                    font=gcompris.skin.get_font("gcompris/board/big"),
                    fill_color="black",
                    x=i * 120 + 140,
                    y=j * 45 + 290)

        # OK Button
        ok = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=gcompris.skin.svg_get(),
            svg_id="#OK",
            tooltip=_("Click to confirm your selection of dots"))
        ok.translate(-165, -155)

        ok.connect("button_press_event", self.ok_event)
        gcompris.utils.item_focus_init(ok, None)
Esempio n. 26
0
  def __init__(self, rootitem, svghandle, x, y):
    """
    Constructor
        rootitem    : The goocanvas item to add the mouse to
        svghandle   : Handle of the svg file, containing the graphics
        x, y        : Position of the center of the mouse in screen coordinates (800 x 520)
    """

    self.timer_scroll = None
    """ timer for scroll animation """

    self.timer_click = None
    """ timer for click animation """

    self.scroll_direction = None
    """
    defines the scroll direction:
       +1: zoom in
       -1: zoom out
    """

    self.wheel_imgs = []
    """ list of mouse wheel images """

    self.x = x
    """ x position of the center of the mouse in screen coordinates (800 x 520) """

    self.y = y
    """ y position of the center of the mouse in screen coordinates (800 x 520) """

    self.mouse_img = goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#MOUSE",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      )

    self.button_img = goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#MOUSE_BUTTON",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      )


    # GooCanvas does not support to add SVG-items to other SVG-items, so we have to add
    # the wheels to the rootitem.

    self.wheel_imgs.append(goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#MOUSEWHEEL01",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      ))

    self.wheel_imgs.append(goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#MOUSEWHEEL02",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      ))

    self.wheel_imgs.append(goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#MOUSEWHEEL03",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      ))

    self.current_wheel = 0
    """ the current wheel displayed """

    self.__update_transformation()
Esempio n. 27
0
    def displayLesson(self, lesson):

        # Keep the triplet shown to the user to know when
        # we can move to the exercices
        self.tripletSeen = set()

        try:
            self.lessonroot.remove()
        except:
            pass

        self.currentTripletId = 0
        self.lessonroot = goocanvas.Group(parent=self.rootitem)

        goocanvas.Rect(parent=self.lessonroot,
                       x=20,
                       y=10,
                       width=gcompris.BOARD_WIDTH - 40,
                       height=65,
                       fill_color_rgba=0xAAAAAA99L,
                       stroke_color_rgba=0x111111AAL,
                       line_width=2.0,
                       radius_x=3,
                       radius_y=3)

        goocanvas.Text(parent=self.lessonroot,
                       x=gcompris.BOARD_WIDTH / 2,
                       y=40.0,
                       text=gcompris.gcompris_gettext(lesson.name),
                       fill_color="black",
                       font=gcompris.skin.get_font("gcompris/title"),
                       anchor=gtk.ANCHOR_CENTER,
                       alignment=pango.ALIGN_CENTER,
                       width=300)

        # Previous Button
        item = goocanvas.Svg(
            parent=self.lessonroot,
            svg_handle=gcompris.skin.svg_get(),
            svg_id="#PREVIOUS",
        )
        gcompris.utils.item_absolute_move(item, 100, gcompris.BOARD_HEIGHT / 2)
        item.connect("button_press_event", self.previous_event, None)
        gcompris.utils.item_focus_init(item, None)

        # Next Button
        item = goocanvas.Svg(
            parent=self.lessonroot,
            svg_handle=gcompris.skin.svg_get(),
            svg_id="#NEXT",
        )
        gcompris.utils.item_absolute_move(item, gcompris.BOARD_WIDTH - 130,
                                          gcompris.BOARD_HEIGHT / 2)
        item.connect("button_press_event", self.next_event, None)
        gcompris.utils.item_focus_init(item, None)

        self.counteritem = goocanvas.Text(
            parent=self.lessonroot,
            x=gcompris.BOARD_WIDTH - 40,
            y=gcompris.BOARD_HEIGHT - 40,
            fill_color="black",
            font=gcompris.skin.get_font("gcompris/board/tiny"),
            anchor=gtk.ANCHOR_CENTER,
            alignment=pango.ALIGN_CENTER)

        # The triplet area
        w = 400
        h = 300
        goocanvas.Rect(parent=self.lessonroot,
                       x=(gcompris.BOARD_WIDTH - w) / 2,
                       y=(gcompris.BOARD_HEIGHT - h) / 2,
                       width=w,
                       height=h + 50,
                       fill_color_rgba=0xCECECECCL,
                       stroke_color_rgba=0x111111CCL,
                       line_width=2.0,
                       radius_x=3,
                       radius_y=3)
        self.imageitem = goocanvas.Image(parent=self.lessonroot)
        self.imageitem.connect("button_press_event", self.next_event, None)
        self.descriptionitem = goocanvas.Text(
            parent=self.lessonroot,
            x=gcompris.BOARD_WIDTH / 2,
            y=gcompris.BOARD_HEIGHT - 80,
            fill_color="black",
            font=gcompris.skin.get_font("gcompris/subtitle"),
            anchor=gtk.ANCHOR_CENTER,
            alignment=pango.ALIGN_CENTER,
            width=500)
        self.displayImage(lesson.getTriplets()[self.currentTripletId])
Esempio n. 28
0
    def start(self):
        self.gcomprisBoard.level = 1
        self.gcomprisBoard.maxlevel = 9
        self.gcomprisBoard.sublevel = 1
        self.gcomprisBoard.number_of_sublevel = 1
        gcompris.bar_set(gcompris.BAR_LEVEL)
        gcompris.bar_location(5, -1, 0.8)

        gcompris.bar_set_level(self.gcomprisBoard)

        self.ballinc = 20  # Event loop timer for the ball move

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

        svghandle = gcompris.utils.load_svg("penalty/penalty_bg.svgz")
        goocanvas.Svg(parent=self.rootitem,
                      svg_handle=svghandle,
                      svg_id="#BACKGROUND",
                      pointer_events=goocanvas.EVENTS_NONE)

        # Help
        self.help_item = goocanvas.Text(
            parent=self.rootitem,
            font=gcompris.skin.get_font("gcompris/board/medium"),
            x=gcompris.BOARD_WIDTH / 2,
            y=gcompris.BOARD_HEIGHT - 170,
            anchor=gtk.ANCHOR_CENTER,
            fill_color="white")
        self.help_item.props.visibility = goocanvas.ITEM_INVISIBLE

        # Tux
        item = goocanvas.Svg(parent=self.rootitem,
                             svg_handle=svghandle,
                             svg_id="#TUX")
        item.connect("button_press_event", self.help)

        # The activity help
        item = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=svghandle,
            svg_id="#HELP",
        )
        item.connect("button_press_event", self.help)
        # This item is clickeable and it must be seen
        gcompris.utils.item_focus_init(item, None)

        # The click indicator
        indicator_h = 30
        indicator_w = 10
        y_ref = 107

        self.indicator = []
        self.indicator.append(
            Indicator(self.rootitem, gcompris.BOARD_WIDTH / 2 - 350, y_ref,
                      indicator_w, indicator_h, 0, 200))
        self.indicator.append(
            Indicator(self.rootitem, gcompris.BOARD_WIDTH / 2, y_ref - 80,
                      indicator_h, indicator_w, 1, 100))
        self.indicator.append(
            Indicator(self.rootitem, gcompris.BOARD_WIDTH / 2 + 350, y_ref,
                      indicator_w, indicator_h, 2, 200))

        self.balloon = Balloon(self, svghandle, 10, 10)
        self.balloon.item.connect("button_press_event", self.shoot_item_event)

        self.next_level()
Esempio n. 29
0
    def start(self):
        self.gcomprisBoard.level = 1
        self.gcomprisBoard.maxlevel = 1
        self.gcomprisBoard.sublevel = 1
        self.gcomprisBoard.number_of_sublevel = 1

        # The basic duration factor for object animations
        # Higher is longer animation (slower)
        self.timerinc = 20
        self.step_time = 100

        # Need to manage the timers to quit properly
        self.waterlevel_timer = 0

        # Used to display the bonus a single time
        self.you_won = False

        gcompris.sound.play_ogg("sounds/Harbor1.wav", "sounds/Harbor3.wav")

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

        svghandle = gcompris.utils.load_svg("watercycle/watercycle.svgz")
        goocanvas.Svg(parent=self.rootitem,
                      svg_handle=svghandle,
                      svg_id="#BACKGROUND",
                      pointer_events=goocanvas.EVENTS_NONE)

        # Take care, the items are stacked on each other in the order you add them.
        # If you need, you can reorder them later with raise and lower functions.

        # The River
        self.riveritem = goocanvas.Svg(parent=self.rootitem,
                                       svg_handle=svghandle,
                                       svg_id="#RIVERWATER",
                                       pointer_events=goocanvas.EVENTS_NONE,
                                       visibility=goocanvas.ITEM_INVISIBLE)
        self.riverfull = False

        # The dirty water
        self.dirtywater = goocanvas.Svg(parent=self.rootitem,
                                        svg_handle=svghandle,
                                        svg_id="#DIRTYWATER",
                                        pointer_events=goocanvas.EVENTS_NONE,
                                        visibility=goocanvas.ITEM_INVISIBLE)

        # The clean water
        self.cleanwateritem = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=svghandle,
            svg_id="#CLEANWATER",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        # The Sun
        self.sunitem = goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = svghandle,
          svg_id = "#SUN",
          tooltip = "\n\n\n" + \
            _("The sun heats the water and creates water vapor. "
              "Water vapor combines into small water droplets which "
              "becomes clouds.")
          )
        self.sunitem.connect("button_press_event", self.sun_item_event)
        # This item is clickeable and it must be seen
        gcompris.utils.item_focus_init(self.sunitem, None)
        self.sun_on = 0
        self.sunitem_orig_y1 = self.sunitem.get_bounds().y1
        self.sunitem_target_y1 = 10
        self.sun_connect_handler = 0

        # The Snow
        self.snowitem = goocanvas.Svg(parent=self.rootitem,
                                      svg_handle=svghandle,
                                      svg_id="#SNOW",
                                      pointer_events=goocanvas.EVENTS_NONE,
                                      visibility=goocanvas.ITEM_INVISIBLE)

        # The rain
        self.rainitem = goocanvas.Svg(parent=self.rootitem,
                                      svg_handle=svghandle,
                                      svg_id="#RAIN",
                                      pointer_events=goocanvas.EVENTS_NONE,
                                      visibility=goocanvas.ITEM_INVISIBLE)

        # The cloud
        self.clouditem = goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = svghandle,
          svg_id = "#CLOUD",
          visibility = goocanvas.ITEM_INVISIBLE,
          tooltip = "\n\n\n" + \
            _("As a cloud matures, the dense water droplets may combine "
              "to produce larger droplets, which may combine to form "
              "droplets large enough to fall as rain")
          )
        self.clouditem.props.visibility = goocanvas.ITEM_INVISIBLE
        self.clouditem.connect("animation-finished", self.cloud_arrived)
        self.cloud_on = False
        self.cloud_is_arrived = False
        self.clouditem_bounds = self.clouditem.get_bounds()

        # The vapor
        self.vaporitem = goocanvas.Svg(parent=self.rootitem,
                                       svg_handle=svghandle,
                                       svg_id="#VAPOR",
                                       pointer_events=goocanvas.EVENTS_NONE,
                                       visibility=goocanvas.ITEM_INVISIBLE)
        self.vaporitem.connect("animation-finished", self.vapor_arrived)

        # The Waterpump
        self.waterpumpitem = goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = svghandle,
          svg_id = "#PUMPSTATION",
          tooltip = "\n\n\n" + \
            _("This is a water pump station.")
          )
        self.waterpumpitem.connect("button_press_event",
                                   self.waterpump_item_event)
        # This item is clickeable and it must be seen
        gcompris.utils.item_focus_init(self.waterpumpitem, None)
        self.waterpump_on = 0

        # The WaterCleaning
        self.watercleaningitem = goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = svghandle,
          svg_id = "#CLEANSTATION",
          tooltip = "\n\n\n" + \
            _("This is a water cleanup station.")
          )
        self.watercleaningitem.connect("button_press_event",
                                       self.watercleaning_item_event)
        # This item is clickeable and it must be seen
        gcompris.utils.item_focus_init(self.watercleaningitem, None)
        self.watercleaning_on = 0

        # The tuxboat
        self.boatitem = goocanvas.Svg(parent=self.rootitem,
                                      svg_handle=svghandle,
                                      svg_id="#BOAT",
                                      pointer_events=goocanvas.EVENTS_NONE)
        self.boatitem.translate(-100, 0)
        self.boatitem_parked = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=svghandle,
            svg_id="#BOAT_PARKED",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        # Tux in the shower (without water)
        self.tuxshoweritem = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=svghandle,
            svg_id="#SHOWER",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        self.shower_tux = goocanvas.Svg(parent=self.rootitem,
                                        svg_handle=svghandle,
                                        svg_id="#SHOWER_TUX",
                                        pointer_events=goocanvas.EVENTS_NONE,
                                        visibility=goocanvas.ITEM_INVISIBLE)

        # Tux in the shower with the water
        self.tuxshowerwateritem = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=svghandle,
            svg_id="#SHOWER_ON",
            pointer_events=goocanvas.EVENTS_NONE,
            visibility=goocanvas.ITEM_INVISIBLE)

        # The shower on/off button (I need to get the 2 buttons to manage the focus)
        self.showerbuttonitem_on = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=svghandle,
            svg_id="#SHOWER_BUTTON_ON",
            visibility=goocanvas.ITEM_INVISIBLE)
        self.showerbuttonitem_on.connect("button_press_event",
                                         self.showerbutton_item_event, True)
        # This item is clickeable and it must be seen
        gcompris.utils.item_focus_init(self.showerbuttonitem_on, None)
        self.showerbutton = False

        self.showerbuttonitem_off = goocanvas.Svg(
            parent=self.rootitem,
            svg_handle=svghandle,
            svg_id="#SHOWER_BUTTON_OFF",
            visibility=goocanvas.ITEM_INVISIBLE)
        self.showerbuttonitem_off.connect("button_press_event",
                                          self.showerbutton_item_event, False)
        # This item is clickeable and it must be seen
        gcompris.utils.item_focus_init(self.showerbuttonitem_off, None)

        goocanvas.Svg(parent=self.rootitem,
                      svg_handle=svghandle,
                      svg_id="#FOREGROUND",
                      pointer_events=goocanvas.EVENTS_NONE)

        goocanvas.Svg(
          parent = self.rootitem,
          svg_handle = svghandle,
          svg_id = "#WATER_TOWER",
          tooltip = "\n\n\n" + \
            _("A water tower or elevated water tower is a large elevated water storage container constructed to hold a water supply at a height sufficient to pressurize a water distribution system.")
          )

        # The level of water in the tower
        self.waterlevel_max = 12
        self.waterlevel_min = 1
        self.waterlevel_x_ratio = 1.3
        self.waterlevel = 1
        self.waterlevel_item = goocanvas.Ellipse(parent=self.rootitem,
                                                 center_x=635,
                                                 center_y=142,
                                                 radius_x=1,
                                                 radius_y=1,
                                                 fill_color_rgba=0x0033FFC0L,
                                                 line_width=0)
        self.waterlevel_timer = gobject.timeout_add(1000,
                                                    self.update_waterlevel)

        # Some item ordering
        self.rainitem.raise_(None)
        self.clouditem.raise_(None)
        self.vaporitem.raise_(None)

        # Ready GO
        target_x = 700
        trip_x = int(target_x - self.boatitem.get_bounds().x1)
        self.boatitem.connect("animation-finished", self.boat_arrived)
        self.boatitem.animate(target_x, 0, 1, 1, True, self.timerinc * trip_x,
                              self.step_time, goocanvas.ANIMATE_FREEZE)

        gcompris.bar_set(0)
        gcompris.bar_location(5, -1, 0.6)
        gcompris.bar_set_level(self.gcomprisBoard)
Esempio n. 30
0
  def __init__(self, rootitem, svghandle, x, y):
    """
    Constructor
        rootitem    : The goocanvas item to add the mouse to
        svghandle   : Handle of the svg file, containing the graphics
        x, y        : Position of the center of the touchpad in screen coordinates (800 x 520)
    """

    self.touchpad_x = x
    """ x position of the center of the touchpad in screen coordinates (800 x 520) """

    self.touchpad_y = y
    """ y position of the center of the touchpad in screen coordinates (800 x 520) """

    self.zoom_number_of_fingers = None
    """
    1: show "1"-finger animation
    2: show "2"-finger animation
    """

    self.zoom_direction = None
    """ zoom "in" or "out" """

    self.zoom_animation_start_timer = None
    """ one time timer to start the zoom animation again """

    self.zoom_animation_finished_handler_id = None
    """ we remember the handler id to be able to disconnect it again """

    self.click_animation_show_effect_timer = None
    """ one time timer to restart the click animation, after showing the touch effect """

    self.click_animation_finished_handler_id = None
    """ we remember the handler id to be able to disconnect it again """


    self.touchpad_img = goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#TOUCHPAD",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      )

    self.finger01_img = goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#FINGER",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      )

    self.finger02_img = goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#FINGER",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      )

    self.touch_effect_img = goocanvas.Svg(
      parent = rootitem,
      svg_handle = svghandle,
      svg_id = "#TOUCHPAD_PRESS_EFFECT",
      visibility = goocanvas.ITEM_INVISIBLE,
      pointer_events = goocanvas.EVENTS_NONE
      )

    self.__update_touchpad_transformation()