Exemplo n.º 1
0
    def setup_polygons(self, root):
        points = goocanvas.Points([(210.0, 320.0), (210.0, 380.0),
                                   (260.0, 350.0)])
        pattern = self.create_stipple("blue")
        polyline1 = goocanvas.Polyline(parent=root,
                                       close_path=True,
                                       line_width=1.0,
                                       points=points,
                                       fill_pattern=pattern,
                                       stroke_color="black")
        self.setup_item_signals(polyline1)

        points = goocanvas.Points([(270.0, 330.0), (270.0, 430.0),
                                   (390.0, 430.0), (390.0, 330.0),
                                   (310.0, 330.0), (310.0, 390.0),
                                   (350.0, 390.0), (350.0, 370.0),
                                   (330.0, 370.0), (330.0, 350.0),
                                   (370.0, 350.0), (370.0, 410.0),
                                   (290.0, 410.0), (290.0, 330.0)])
        polyline2 = goocanvas.Polyline(parent=root,
                                       close_path=True,
                                       line_width=1.0,
                                       points=points,
                                       fill_color="tan",
                                       stroke_color="black")
        self.setup_item_signals(polyline2)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
    def setup_lines(self, root):
        self.polish_diamond(root)
        self.make_hilbert(root)
        ''' Arrow tests '''
        p = goocanvas.Points([(340.0, 170.0), (340.0, 230.0), (390.0, 230.0),
                              (390.0, 170.0)])
        polyline1 = goocanvas.Polyline(parent=root,
                                       points=p,
                                       close_path=False,
                                       stroke_color="midnightblue",
                                       line_width=3.0,
                                       start_arrow=True,
                                       end_arrow=True,
                                       arrow_tip_length=3.0,
                                       arrow_length=4.0,
                                       arrow_width=3.5)
        self.setup_item_signals(polyline1)

        p = goocanvas.Points([(356.0, 180.0), (374.0, 220.0)])
        polyline2 = goocanvas.Polyline(parent=root,
                                       points=p,
                                       close_path=False,
                                       stroke_color="blue",
                                       line_width=1.0,
                                       start_arrow=True,
                                       end_arrow=True,
                                       arrow_tip_length=5.0,
                                       arrow_length=6.0,
                                       arrow_width=6.5)
        self.setup_item_signals(polyline2)

        p = goocanvas.Points([(356.0, 220.0), (374.0, 180.0)])
        polyline3 = goocanvas.Polyline(parent=root,
                                       points=p,
                                       close_path=False,
                                       stroke_color="blue",
                                       line_width=1.0,
                                       start_arrow=True,
                                       end_arrow=True,
                                       arrow_tip_length=5.0,
                                       arrow_length=6.0,
                                       arrow_width=6.5)
        self.setup_item_signals(polyline3)
        ''' Test polyline without any coords. '''
        polyline4 = goocanvas.Polyline(parent=root)
        self.setup_item_signals(polyline4)
        ''' Test polyline with 1 coord and arrows. '''
        p = goocanvas.Points([
            (356.0, 220.0),
        ])
        polyline5 = goocanvas.Polyline(parent=root,
                                       points=p,
                                       start_arrow=True,
                                       end_arrow=True)
        self.setup_item_signals(polyline5)
Exemplo n.º 4
0
    def winner(self, player):
        self.gamewon = True
        self.cur_player = 0

        # It's a draw, no line to draw
        if player == 0:
            gcompris.bonus.display(gcompris.bonus.DRAW, gcompris.bonus.FLOWER)
            return

        # Display the winner line
        self.scores[player - 1] += 1
        self.update_scores()

        points = goocanvas.Points([
            (self.winLine[0][0] * (self.boardSize / self.nbColumns) +
             self.stoneSize / 2, (self.boardSize / self.nbColumns) *
             (self.nbLines - 1 - self.winLine[0][1]) + self.stoneSize / 2),
            (self.winLine[1][0] * (self.boardSize / self.nbColumns) +
             self.stoneSize / 2, (self.boardSize / self.nbColumns) *
             (self.nbLines - 1 - self.winLine[1][1]) + self.stoneSize / 2)
        ])

        self.redLine = \
            goocanvas.Polyline(
            parent = self.boardItem,
            stroke_color_rgba=0xFF0000FFL,
            points = points,
            line_width = 8,
            line_cap = cairo.LINE_CAP_ROUND
            )
        if player == 1 or self.mode == 2:
            gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.FLOWER)
        elif player == 2:
            gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.FLOWER)
Exemplo n.º 5
0
    def action(self, objet, target, truc, idpt):
        """Action to do at each step during normal execution of the game"""
        if truc.type == gtk.gdk.BUTTON_PRESS:
            if idpt == (
                    self.actu + 1
            ):  #Action to execute if the selected point is the following of previous one
                xd, yd, xa, ya = self.POINT[(idpt - 1)].x, self.POINT[(
                    idpt - 1)].y, self.POINT[idpt].x, self.POINT[idpt].y
                item = goocanvas.Polyline(parent=self.ROOT,
                                          points=goocanvas.Points([(xd, yd),
                                                                   (xa, ya)]),
                                          stroke_color='black',
                                          line_cap=cairo.LINE_CAP_ROUND,
                                          line_width=1.5)

                if idpt == 2:  # Always raise the first point
                    self.POINT[self.MAX].raise_(None)
                    self.TEXT[self.MAX].raise_(None)

                self.POINT[idpt].props.visibility = goocanvas.ITEM_INVISIBLE
                self.TEXT[idpt].props.visibility = goocanvas.ITEM_INVISIBLE
                if idpt == self.MAX:  #Action to execute if all points have been selected in good way
                    gcompris.set_background(
                        self.ROOT,
                        self.data[self.gcomprisBoard.sublevel - 1].img2)
                    self.gamewon = 1
                    gcompris.bar_hide(True)
                    self.timeout = gobject.timeout_add(
                        1500, self.lauch_bonus
                    )  # The level is complete -> Bonus display

                else:  #Action to execute if the selected point isn''t the last one of this level
                    #Set color in blue to next point. Too easy ???
                    #self.POINT[(idpt+1)].set_properties(fill_color_rgba=0x003DF5F0)
                    self.actu = self.actu + 1  #self.actu update to set it at actual value of selected point
    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)
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
  def circle_item_event(self, widget, target, event=None):
    if eval(self.config_dict['disable_line']):
      return False

    if event.type == gtk.gdk.BUTTON_PRESS:
      if event.button == 1:
        bounds = widget.get_bounds()
        self.pos_x = (bounds.x1+bounds.x2)/2
        self.pos_y = (bounds.y1+bounds.y2)/2
        if 'line 1' in self.canvasitems:
          self.canvasitems['line 1'].remove()
        self.canvasitems['line 1'] =goocanvas.Polyline(
          parent = self.rootitem,
          points = goocanvas.Points([(self.pos_x, self.pos_y),
                                     (event.x, event.y)]),
          fill_color_rgba = self.colors['line'],
          line_cap = cairo.LINE_CAP_ROUND,
          line_width = 6.0
          )
        self.movingline='line 1'
        print "Button press"
        return True
    if event.type == gtk.gdk.MOTION_NOTIFY:
      if event.state & gtk.gdk.BUTTON1_MASK:
        self.canvasitems[self.movingline].set_properties(
          points = goocanvas.Points([(self.pos_x, self.pos_y),
                                     (event.x, event.y)])
          )
    if event.type == gtk.gdk.BUTTON_RELEASE:
      if event.button == 1:
        self.movingline='line 1'
        print "Button release"
        return True
    return False
Exemplo n.º 9
0
  def __init__(self,satellite_instance, rootitem):
    self.rootitem = rootitem
    self.satellite_instance = satellite_instance

    self.length = 130
    self.button_width = 20
    line = goocanvas.Polyline(
      parent = self.rootitem,
      points = goocanvas.Points( [(650, 500), (780, 500)] ),
      stroke_color = "grey",
      width = 2.0)

    text_speed = goocanvas.Text(
      parent = rootitem,
      x = (650 + 780)/2,
      y = 470,
      font = gcompris.skin.get_font("gcompris/board/small"),
      anchor = gtk.ANCHOR_CENTER,
      alignment = pango.ALIGN_CENTER,
      fill_color = "white",
      text = _("Speed"))

    back = goocanvas.Rect(
      parent = self.rootitem,
      radius_x = 6,
      radius_y = 6,
      x = 630,
      y = 460,
      width = 169,
      height = 59,
      stroke_color_rgba = 0xFFFFFFFFL,
      fill_color_rgba = 0x0000FF44L)

    slider_x = 650 + self.length / 2.0
    self.bar = goocanvas.Polyline(
      parent = self.rootitem,
      points = goocanvas.Points([(slider_x, 495),
                                 (slider_x, 505)]),
      stroke_color = "grey",
      line_width = 5.0)

    # This is the relative position of the scale from 0 to 1
    # 0 is the bottom
    self.scale_value = 0.5
    self.speed_button(650, 500, self.button_width, '-', -0.01)
    self.speed_button(780, 500, self.button_width, '+', 0.01)
Exemplo n.º 10
0
 def restore(self, anim_):
     AnimItem.restore(self, anim_)
     self.item = \
         goocanvas.Polyline(
             parent = self.rootitem,
             line_cap = cairo.LINE_CAP_ROUND,
             points = self.points
             )
     AnimItem.init_item(self)
Exemplo n.º 11
0
    def draw(self, cr):
        p_points = goocanvas.Points(self.points)

        line = goocanvas.Polyline(
            parent=cr.get_root_item(),
            points=p_points,
            close_path=True,
            line_width=self.pen.linewidth,
            stroke_color=self.pen.color.to_rgb_hex(),
        )
Exemplo n.º 12
0
    def draw(self, cr):
        p_points = goocanvas.Points(self.points)
        polyline = goocanvas.Polyline(
            parent=cr.get_root_item(),
            points=p_points,
            close_path=True,
            stroke_color=self.pen.color.to_rgb_hex(),
        )

        if self.filled:
            polyline.props.fill_color = self.pen.fill_color.to_rgb_hex()

        self.polyline = polyline
Exemplo n.º 13
0
 def draw_line(self, x, y, destx, desty, color):
   line =goocanvas.Polyline(parent = self.rootitem,
                            points = goocanvas.Points([(x, y),
                                                       (destx, desty)]),
                            stroke_color = color,
                            line_cap = cairo.LINE_CAP_ROUND,
                            line_width = 4.0)
   self.drawitems.append(line)
   #to be able to draw by clicking on the new line
   line.connect("button_press_event", self.draw_item_event)
   line.connect("button_release_event", self.draw_item_event)
   line.connect("motion_notify_event", self.draw_item_event)
   return line
Exemplo n.º 14
0
    def __init__(self, anim, x, y, color_fill, color_stroke, line_width):
        AnimItem.__init__(self, anim)
        x, y = self.snap_to_grid(x, y)

        self.item = \
            goocanvas.Polyline(
                parent = self.rootitem,
                stroke_color_rgba = color_stroke,
                points = goocanvas.Points([(x , y), (x , y)]),
                line_width = line_width,
                line_cap = cairo.LINE_CAP_ROUND)

        AnimItem.init_item(self)
Exemplo n.º 15
0
  def __init__(self, rootitem, color_instance, image, primary_color,
               x, y, points, incr_x, incr_y, decr_x, decr_y, level, color_incr):
    self.rootitem = rootitem
    self.primary_color = primary_color
    self.color_instance = color_instance
    self.color_incr = color_incr

    # Load the tube image
    image = 'color_mix/' + image
    pixbuf = gcompris.utils.load_pixmap(image)
    tube = goocanvas.Image(
      parent = self.rootitem,
      pixbuf = pixbuf,
      x = x,
      y = y
      )

    button_width = 20
    line = goocanvas.Polyline(
      parent = self.rootitem,
      points = points,
      stroke_color = "white",
      width = 2.0)

    self.difference_x = (incr_x - decr_x) / 7
    self.difference_y = (incr_y - decr_y) / 8
    slider_x = decr_x + self.difference_x
    slider_y = decr_y + self.difference_y
    self.bar = goocanvas.Polyline(
      parent = self.rootitem,
      points = goocanvas.Points([(slider_x, slider_y - 4),
                                 (slider_x, slider_y + 6)]),
      stroke_color = "white",
      line_width = 10.0)

    self.scale_value = 1
    move = int(255/ (level * 2 + 1))
    self.color_button(decr_x, decr_y, button_width, '-', -move)
    self.color_button(incr_x, incr_y, button_width, '+', move)
    def create_item(self, x, y):
        self.item_id = str(uuid.uuid4())

        self.item_orig_x = x
        self.item_orig_y = y

        self.item_width = DEFAULT_WIDTH
        self.item_height = DEFAULT_HEIGHT

        if self.tool == 'circle':
            self.item = goocanvas.Ellipse(parent=self._root, center_x=x, \
                    center_y=y, radius_x = DEFAULT_WIDTH/2, \
                    radius_y = DEFAULT_HEIGHT/2, title=self.item_id, \
                    fill_color_rgba = self._fill_color, \
                    stroke_color_rgba = self._stroke_color)
        elif self.tool == 'rect':
            self.item = goocanvas.Rect(parent=self._root, x=x, y=y, \
                    width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, \
                    fill_color_rgba = self._fill_color, \
                    stroke_color_rgba = self._stroke_color, title=self.item_id)
        elif self.tool == 'pencil':
            self.line_points = []  #Reset
            self.line_points.append((x, y))
            self.item = goocanvas.Polyline(parent=self._root, \
                    points=goocanvas.Points(self.line_points), \
                    stroke_color_rgba = self._stroke_color, title=self.item_id)
        elif self.tool == 'poly':
            self.line_points = []  #Reset
            self.line_points.append((x, y))
            self.item = goocanvas.Polyline(parent=self._root, \
                    points=goocanvas.Points(self.line_points), \
                    stroke_color_rgba = self._stroke_color, \
                    fill_color_rgba = self._fill_color, title=self.item_id)
        elif self.tool == 'eraser':
            self.item = self.get_item_at(x, y, True)
        else:
            pass
Exemplo n.º 17
0
  def paint_hex(self, x, y, color=0x0099FFCCL):
    ax = 30+self.sqrt3*self.r*x
    ay = 30+1.5*self.r*y

    if y&1 :
     ax+=self.sqrt3/2*self.r
    pts = []
    for i in range (len(self.cx)):
     pts.append ((ax+self.cx [i], ay+self.cy [i]))

    s = goocanvas.Polyline (parent =  self.rootitem,
                            points = goocanvas.Points(pts),
                            close_path = True,
                            stroke_color = "black",
                            fill_color_rgba = color,
                            line_width = 2.5)
    return s
Exemplo n.º 18
0
def create_demo_table(root, x, y, width, height):
    table = goocanvas.Table(parent=root,
                            row_spacing=4.0,
                            column_spacing=4.0,
                            width=width,
                            height=height)

    table.translate(x, y)

    square = goocanvas.Rect(parent=table,
                            x=0.0,
                            y=0.0,
                            width=50.0,
                            height=50.0,
                            fill_color="red")

    table.set_child_properties(square, row=0, column=0, x_shrink=True)

    square.set_data("id", "Red square")
    square.connect("button_press_event", on_button_press)

    circle = goocanvas.Ellipse(parent=table,
                               center_x=0,
                               center_y=0,
                               radius_x=25,
                               radius_y=25,
                               fill_color="blue")

    table.set_child_properties(circle, row=0, column=1, x_shrink=True)

    circle.set_data("id", "Blue circle")
    circle.connect("button_press_event", on_button_press)

    p = goocanvas.Points([(25, 0), (0, 50), (50, 50)])
    triangle = goocanvas.Polyline(parent=table,
                                  close_path=True,
                                  points=p,
                                  fill_color="yellow")

    table.set_child_properties(triangle, row=0, column=2, x_shrink=True)

    triangle.set_data("id", "Yellow triangle")
    triangle.connect("button_press_event", on_button_press)
Exemplo n.º 19
0
    def make_hilbert(self, root):
        SCALE = 7
        hilbert = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd"

        points = [
            (340, 290),
        ]
        count = 0

        for letter in hilbert:
            if letter == 'u':
                p = points[count][0]
                p1 = points[count][1] - SCALE
                points.append(tuple([p, p1]))
            if letter == 'd':
                p = points[count][0]
                p1 = points[count][1] + SCALE
                points.append(tuple([p, p1]))
            if letter == 'l':
                p = points[count][0] - SCALE
                p1 = points[count][1]
                points.append(tuple([p, p1]))
            if letter == 'r':
                p = points[count][0] + SCALE
                p1 = points[count][1]
                points.append(tuple([p, p1]))
            count += 1

        points = goocanvas.Points(points)

        pattern = self.create_stipple("red")

        item = goocanvas.Polyline(parent=root,
                                  close_path=False,
                                  points=points,
                                  line_width=4.0,
                                  stroke_pattern=pattern,
                                  line_cap=cairo.LINE_CAP_SQUARE,
                                  line_join=cairo.LINE_JOIN_MITER)

        self.setup_item_signals(item)
Exemplo n.º 20
0
 def line(p1, p2):
     goocanvas.Polyline(parent=self.blobCanvasGroup,
                        points=goocanvas.Points([p1, p2]),
                        line_width=2,
                        stroke_color='black',
                        end_arrow=True)
     p1 = Vec2(*p1)
     p2 = Vec2(*p2)
     v = p1 - p2
     ang = positiveAngle(-1 * atan2(v.getX(), v.getY()), pi)
     where = (p1 + p2).__div__(2.0)  # truediv bug
     direction = where - center
     direction.normalize()
     where = where + direction * 10
     goocanvas.Text(parent=self.blobCanvasGroup,
                    x=where.getX(),
                    y=where.getY(),
                    anchor=gtk.ANCHOR_CENTER,
                    fill_color="#cc4400",
                    font="Sans 6",
                    text="%d" % degrees(ang)).raise_(None)
Exemplo n.º 21
0
    def __init__(self,
                 diagram,
                 a_nConnectorCountId=1,
                 a_nFrom=-1,
                 a_nFromOut=-1):  #a_nInputs, a_nOutputs, a_nBlockType ):

        self.ParentDiagram = diagram

        self.m_nCountId = a_nConnectorCountId

        self.fromBlock = a_nFrom
        self.fromBlockOut = a_nFromOut

        self.fromPoint = self.ParentDiagram.m_oBlocks[
            self.fromBlock].GetOutputPos(
                self.fromBlockOut
            )  #pegando o ponto verdadeiro de onde sai o conector

        self.ConnBoundary = 16.0

        self.toPoint = (0, 0)

        self.toBlock = -1  #a_nTo
        self.toBlockIn = -1  #a_nToIn

        self.m_bFocus = False
        self.m_bHasFlow = False

        self.wGroup = goocanvas.Group(can_focus=True)
        # append connector to canvas root at a low level
        # so that blocks catch events before connectors
        self.ParentDiagram.root_add(self.wGroup, 1)

        w1 = goocanvas.Polyline(end_arrow=True, line_width=3)
        self.wGroup.add_child(w1)

        self.widgets = {}
        self.widgets["Line"] = w1

        self.turnOnEvents()
Exemplo n.º 22
0
    def __init__(self, game, rootitem, x, y, level, planet_left, planet_right):
        self.game = game
        self.rootitem = rootitem
        self.level = level
        # This counts how much space travel the children did
        # Let us determine a success case
        self.trip_distance = 0

        # load spaceship
        self.tux_spaceship = goocanvas.Image(
            parent=self.rootitem,
            pixbuf=gcompris.utils.load_pixmap(
                "intro_gravity/tux_spaceship.png"),
            x=x,
            y=y)

        # Center it
        bounds = self.tux_spaceship.get_bounds()
        self.tux_spaceship.translate((bounds.x2 - bounds.x1) / 2.0 * -1,
                                     (bounds.y2 - bounds.y1) / 2.0 * -1)

        self.planet_right = planet_right
        self.planet_left = planet_left

        # load arrows for force applied on spacehip
        point = goocanvas.Points([(x - 50, y), (x - 90, y)])
        self.force_line = goocanvas.Polyline(parent=self.rootitem,
                                             points=point,
                                             stroke_color_rgba=0xFFFFFFFFL,
                                             end_arrow=True,
                                             line_width=0.5)

        # Set to true to stop the calculation
        self.done = False
        self.move = 0

        gobject.timeout_add(30, self.calculate)
Exemplo n.º 23
0
    class Controller(controller.Controller):

        __ARROW_COLOR__ = "black"

        arrow = goocanvas.Polyline(stroke_color=__ARROW_COLOR__)

        __center = None
        __prev_pads = []

        def enter(self, item, target):
            self._view.focus()

        def leave(self, item, target):
            self._view.unfocus()

        def drag_start(self):
            self._canvas.get_root_item().add_child(self.arrow)
            self.__center = self.center(self._view.socket)
            points = [self.__center, self.__center]
            self._mousedown = Point(0, 0)
            self.arrow.props.points = goocanvas.Points(points)

        def drag_end(self):
            self.arrow.remove()
            for pad in self.__prev_pads:
                pad.unhilight()
                if pad.canLink(self._view):
                    pad.linkPads(self._view)

        def __pads_under_point(self, (x, y)):
            items = self._canvas.get_items_in_area(
                goocanvas.Bounds(x - 1, y - 1, x + 1, y + 1), True, True, True)
            if items:
                return [
                    item for item in items if isinstance(item, PadBaseView)
                ]
            return []
Exemplo n.º 24
0
    def ruler_item_event(self, widget, target, event=None):
        (x, y)= self.gcomprisBoard.canvas.\
            convert_from_item_space(widget, event.x, event.y)
        if event.type == gtk.gdk.BUTTON_PRESS:
            if event.button == 1:
                self.pos_x = x
                self.pos_y = y
                self.ruleritem = goocanvas.Polyline(
                    parent=self.rootitem,
                    points=goocanvas.Points([(self.pos_x, self.pos_y),
                                             (x, y)]),
                    stroke_color_rgba=0xFF0000FFL,
                    line_width=2.0)
                return True

        if event.type == gtk.gdk.MOTION_NOTIFY:
            if event.state & gtk.gdk.BUTTON1_MASK:
                # Calc the angle and distance and display them in the status bar
                distance = math.sqrt((self.pos_x - x) * (self.pos_x - x) +
                                     (self.pos_y - y) * (self.pos_y - y))
                distance = int(distance / self.sea_ratio)

                angle = math.atan2(abs(self.pos_x - x), abs(self.pos_y - y))
                angle = int(angle * 180 / math.pi)
                angle = abs(angle - 90)
                self.statusitem.props.text = \
                    _("Distance:") + " " + str(distance) + " " + _("Angle:") + " " + str(angle)
                self.ruleritem.props.points = \
                    goocanvas.Points([(self.pos_x, self.pos_y), (x, y)])

        if event.type == gtk.gdk.BUTTON_RELEASE:
            if event.button == 1:
                self.ruleritem.remove()
                self.statusitem.props.text = ""
                return True
        return False
Exemplo n.º 25
0
    def start(self):
        self.board.level = 1
        self.board.maxlevel = self.levelset.numlevels
        self.board.sublevel = 1
        self.board.number_of_sublevel = self.levelset.num_sublevels
        self.trog_wait = 1900

        gcompris.set_default_background(self.board.canvas.get_root_item())
        gcompris.bar_set_level(self.board)

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

        # create our rootitem. We put each canvas item here so at the end we only
        # need to remove the rootitem
        self.rootitem = goocanvas.Group(
            parent=self.board.canvas.get_root_item())

        # draw the board on top of the background
        for i in range(0, self.width + 1):
            goocanvas.Polyline(parent=self.rootitem,
                               points=goocanvas.Points([
                                   (i * self.sw + self.left, self.top),
                                   (i * self.sw + self.left, self.scrh)
                               ]),
                               fill_color_rgba=0x000000FFL,
                               line_width=3.0)
        for i in range(0, self.height + 1):
            goocanvas.Polyline(parent=self.rootitem,
                               points=goocanvas.Points([
                                   (self.left, self.top + i * self.sh),
                                   (self.scrw, self.top + i * self.sh)
                               ]),
                               fill_color_rgba=0x000000FFL,
                               line_width=3.0)

        # munchers and troggles
        self.players = []
        self.muncher = Muncher()
        self.troggles = [Troggle(), Troggle(), Troggle()]

        self.players[:] = self.troggles
        self.players.append(self.muncher)

        # create the squares
        self.squares = []
        for i in range(0, self.width):
            tmp = []
            for j in range(0, self.height):
                s = Square(self.left + self.sw * i + self.sw / 2,
                           self.top + self.sh * j + self.sh / 2)
                s.pic.raise_(None)
                tmp.append(s)
            self.squares.append(tmp)

        # so that the troggles get clipped to the board area
        goocanvas.Rect(parent=self.rootitem,
                       x=0,
                       y=0,
                       width=self.scrw,
                       height=self.top,
                       fill_color_rgba=0xFFFFFFFFL)
        goocanvas.Rect(parent=self.rootitem,
                       x=0,
                       y=0,
                       width=self.left,
                       height=self.scrh,
                       fill_color_rgba=0xFFFFFFFFL)

        # the board title
        self.title = goocanvas.Text(
            parent=self.rootitem,
            text="",
            font=gcompris.skin.get_font("gcompris/board/title bold"),
            x=self.sw + 10,
            y=self.top / 2)

        # the message
        self.message_back = goocanvas.Rect(parent=self.rootitem,
                                           x=0,
                                           y=0,
                                           width=1,
                                           height=1,
                                           fill_color_rgba=0x60F060F0L)
        self.message = goocanvas.Text(
            parent=self.rootitem,
            text="",
            anchor=gtk.ANCHOR_CENTER,
            font=gcompris.skin.get_font("gcompris/board/big bold"),
            x=self.scrw / 2,
            y=self.scrh / 2)
        self.hide_message()

        # the trogwarning
        self.trogwarning = goocanvas.Text(
            parent=self.rootitem,
            text=_("T\nR\nO\nG\nG\nL\nE"),
            anchor=gtk.ANCHOR_CENTER,
            font=gcompris.skin.get_font("gcompris/board/title bold"),
            x=self.left / 2,
            y=self.scrh / 2)
        self.trogwarning.props.visibility = goocanvas.ITEM_INVISIBLE
        self.trogwarning_num = 0

        # the spare life
        self.muncher.spare.goocanvas.raise_(None)

        gcompris.bar_set(0)
        gcompris.bar_location(10, -1, 0.6)

        self.startGame()
Exemplo n.º 26
0
  def start_event(self, widget, target, event=None):
    if event.type == gtk.gdk.BUTTON_PRESS:
      if event.button == 1:
        bounds = widget.get_bounds()
        self.pos_x = (bounds.x1+bounds.x2)/2
        self.pos_y = (bounds.y1+bounds.y2)/2
        self.line =goocanvas.Polyline(
          parent = self.rootitem,
          points = goocanvas.Points([(self.pos_x, self.pos_y),
                                     (event.x, event.y)]),
          stroke_color = 'white',
          line_cap = cairo.LINE_CAP_ROUND,
          line_width = 2.0
          )
        return True

    if event.type == gtk.gdk.MOTION_NOTIFY:
      if event.state & gtk.gdk.BUTTON1_MASK:
        self.line.set_properties(
          points = goocanvas.Points([(self.pos_x, self.pos_y),
                                     (event.x, event.y)])
          )

    if event.type == gtk.gdk.BUTTON_RELEASE:
      if event.button == 1:

        # Get the planet center
        planet_bounds = self.game.planet.get_bounds()
        self.planet_x = (planet_bounds.x1 + planet_bounds.x2)/2
        self.planet_y = (planet_bounds.y1 + planet_bounds.y2)/2

        # Get the satellite center
        sat_bounds = self.satellite.get_bounds()
        sat_x = (sat_bounds.x1 + sat_bounds.x2)/2
        sat_y = (sat_bounds.y1 + sat_bounds.y2)/2

        # Calc the distances from planet center to sat and to click
        self.distance = math.sqrt(((self.planet_x - sat_x)**2) +
                                  ((self.planet_y - sat_y)**2))
        click_dist = math.sqrt(((self.planet_x - event.x)**2) +
                               ((self.planet_y - event.y)**2))

        # Make the angle be linear in the range 0 -> 2*PI
        sat_add = 0 if sat_y > self.planet_y else math.pi
        if sat_y > self.planet_y:
          sat_angle = math.acos((sat_x - self.planet_x) / self.distance)
        else:
          sat_angle = math.pi * 2 - math.acos((sat_x - self.planet_x) /
                                               self.distance)

        # Make the angle be linear in the range 0 -> 2*PI
        if event.y > self.planet_y:
          click_angle = math.acos((event.x - self.planet_x) / click_dist)
        else:
          click_angle = math.pi * 2 - math.acos((event.x - self.planet_x) /
                                                 click_dist)

        # Fix the 0 angle case
        if sat_angle > click_angle + math.pi:
          click_angle += math.pi * 2
        elif click_angle > sat_angle + math.pi:
          click_angle -= math.pi * 2

        revolution_direction = 1 if click_angle < sat_angle else -1

        # Set the step to make the satellite start where it is now
        self.step = sat_angle / (math.pi/180)

        # Pass the line lengh * direction
        self.initiate_movement(math.sqrt((((self.pos_x - event.x)**2)) +
                                         ((self.pos_y - event.y)**2)) *
                               revolution_direction)
        self.line.remove()
        return True
    return False
 def make_polyline_item(self, **kwargs):
     item = goocanvas.Polyline(**kwargs)
     return item
Exemplo n.º 28
0
    def tux_move(self):

        # The sea area is defined in the global self.sea_area
        step_x = (self.sea_area[2] - self.sea_area[0]) / 20 * 2
        step_y = (self.sea_area[3] - self.sea_area[1]) / 10

        # Original boat position
        bx = self.right_boat.x
        by = self.right_boat.y
        ba = 0
        one_path = []

        # X loop
        while (bx <= self.sea_area[2] and bx >= self.sea_area[0]):
            score = 10000
            # By default, go straight
            coord = (bx, by, ba, int(step_x))

            # angle loop
            for boat_angle in [-45, 0, 45]:
                a_pi = boat_angle * math.pi / 180
                # Find the point from current boat position with angle a and distance step_x
                x = bx + math.cos(a_pi) * step_x
                y = by + math.sin(a_pi) * step_x

                # Manage the wrapping
                line_style = goocanvas.LineDash([1.0])
                if (y < self.sea_area[1]):
                    y = self.sea_area[3] - (self.sea_area[1] - y)
                    line_style = goocanvas.LineDash([5.0, 1.0, 5.0])
                elif (y > self.sea_area[3]):
                    y = self.sea_area[1] + (y - self.sea_area[3])
                    line_style = goocanvas.LineDash([5.0, 1.0, 5.0])

                # Find shortest path to previous calculated point
                condition = self.get_absolute_weather_condition(x, y)
                wind = self.get_wind_score(boat_angle, condition)
                if (wind < score):
                    score = wind
                    coord = (x, y, boat_angle, step_x, line_style
                             )  # x y angle distance line_style

            # ----------
            goocanvas.Polyline(parent=self.root_weather_item,
                               points=goocanvas.Points([(bx, by),
                                                        (coord[0], coord[1])]),
                               stroke_color_rgba=0x00CC00FFL,
                               line_width=2.0,
                               line_dash=coord[4])
            bx = coord[0]
            by = coord[1]
            ba = coord[2]
            one_path.append(coord)

        # --------------------------------------------------------------
        # Translate the previous calculation in a string for Tux program
        # --------------------------------------------------------------

        ba = 0  # Boat angle
        cumulative_distance = 0
        tux_move = ""
        for c in one_path:
            #print "X,Y,A,D=" + str(c)
            x = c[0]
            y = c[1]
            a = c[2]  # angle
            d = c[3]  # distance

            if (ba - a < 0):
                if (cumulative_distance):
                    tux_move += _("forward") + " " + str(
                        cumulative_distance) + "\n"
                    cumulative_distance = 0
                tux_move += _("right") + " " + str(abs(int(ba - a))) + "\n"
                ba += abs(int(ba - a))
            elif (ba - a > 0):
                if (cumulative_distance):
                    tux_move += _("forward") + " " + str(
                        cumulative_distance) + "\n"
                    cumulative_distance = 0
                tux_move += _("left") + " " + str(abs(int(ba - a))) + "\n"
                ba -= abs(int(ba - a))

            cumulative_distance += int(d / self.sea_ratio)

        # Final move, add an ofset because we loose space in abs()
        tux_move += _("forward") + " " + str(cumulative_distance + 2) + "\n"

        self.right_boat.tb.set_text(tux_move)
        self.right_boat.tv.set_editable(False)
Exemplo n.º 29
0
    def display_sea_area(self):
        # Some constant to define the sea area
        # The sea area is defined in the global self.sea_area
        step_x = (self.sea_area[2] - self.sea_area[0]) / 20
        step_y = (self.sea_area[3] - self.sea_area[1]) / 10
        self.sea_ratio = step_x

        text_x = self.sea_area[0] - 15
        text_y = self.sea_area[1] - 15

        # We manage a 2 colors grid
        ci = 0
        ca = 0xc6afffFFL
        cb = 0x1D0DFFFFL

        # The background
        item = goocanvas.Rect(parent=self.rootitem,
                              x=self.sea_area[0],
                              y=self.sea_area[1],
                              width=self.sea_area[2] - self.sea_area[0],
                              height=self.sea_area[3] - self.sea_area[1],
                              fill_color_rgba=0xafe0ffFFL,
                              line_width=0)
        item.connect("button_press_event", self.ruler_item_event)
        item.connect("button_release_event", self.ruler_item_event)
        item.connect("motion_notify_event", self.ruler_item_event)

        for y in range(self.sea_area[1], self.sea_area[3] + 1, int(step_y)):
            if (ci % 2):
                color = ca
            else:
                color = cb
            ci += 1

            # Text number
            item = goocanvas.Text(
                parent=self.rootitem,
                text=int(ci),
                font=gcompris.skin.get_font("gcompris/content"),
                x=text_x,
                y=y,
                fill_color_rgba=cb,
                anchor=gtk.ANCHOR_CENTER)
            item.connect("button_press_event", self.ruler_item_event)
            item.connect("button_release_event", self.ruler_item_event)
            item.connect("motion_notify_event", self.ruler_item_event)

            item = goocanvas.Polyline(parent=self.rootitem,
                                      points=goocanvas.Points([
                                          (self.sea_area[0], y),
                                          (self.sea_area[2], y)
                                      ]),
                                      stroke_color_rgba=color,
                                      line_width=1.0)
            item.connect("button_press_event", self.ruler_item_event)
            item.connect("button_release_event", self.ruler_item_event)
            item.connect("motion_notify_event", self.ruler_item_event)

        ci = 0
        for x in range(self.sea_area[0], self.sea_area[2] + 1, int(step_x)):
            if (ci % 2):
                color = ca
            else:
                color = cb
            ci += 1

            # Text number
            item = goocanvas.Text(
                parent=self.rootitem,
                text=int(ci),
                font=gcompris.skin.get_font("gcompris/content"),
                x=x,
                y=text_y,
                fill_color_rgba=cb,
                anchor=gtk.ANCHOR_CENTER)
            item.connect("button_press_event", self.ruler_item_event)

            item = goocanvas.Polyline(parent=self.rootitem,
                                      points=goocanvas.Points([
                                          (x, self.sea_area[1]),
                                          (x, self.sea_area[3])
                                      ]),
                                      stroke_color_rgba=color,
                                      line_width=1.0)
            item.connect("button_press_event", self.ruler_item_event)

        # The ARRIVAL LINE
        item = goocanvas.Polyline(parent=self.rootitem,
                                  points=goocanvas.Points([
                                      (self.sea_area[2], self.sea_area[1] - 5),
                                      (self.sea_area[2], self.sea_area[3] + 5)
                                  ]),
                                  stroke_color_rgba=0xFF0000FFL,
                                  line_width=5.0)
        item.connect("button_press_event", self.ruler_item_event)

        # The grid is done
        # ----------------

        # The Programming input area LEFT
        self.left_boat.sw = gtk.ScrolledWindow()
        self.left_boat.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
        self.left_boat.sw.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        w = 200.0
        h = 160.0
        y = 355.0  # The upper limit of the text boxes
        x_left = gcompris.BOARD_WIDTH / 4 - 30
        x_right = (gcompris.BOARD_WIDTH / 4) * 3 + 30

        self.left_boat.tb = gtk.TextBuffer()
        self.left_boat.tv = gtk.TextView(self.left_boat.tb)
        self.left_boat.sw.add(self.left_boat.tv)

        command_example = _("right") + " 45\n" + _("forward") + " 5\n" + _(
            "left") + " 45"
        self.left_boat.tb.set_text(command_example)

        self.left_boat.tv.set_wrap_mode(gtk.WRAP_CHAR)
        goocanvas.Widget(parent=self.rootitem,
                         widget=self.left_boat.sw,
                         x=x_left,
                         y=y,
                         width=w,
                         height=h,
                         anchor=gtk.ANCHOR_N)
        self.left_boat.tv.show()
        self.left_boat.sw.show()

        # The Programming input area RIGHT
        self.right_boat.sw = gtk.ScrolledWindow()
        self.right_boat.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
        self.right_boat.sw.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        self.right_boat.tb = gtk.TextBuffer()
        self.right_boat.tv = gtk.TextView(self.right_boat.tb)
        self.right_boat.sw.add(self.right_boat.tv)

        command_example = _("left") + " 45\n" + _("forward") + " 5\n" + _(
            "right") + " 45"
        self.right_boat.tb.set_text(command_example)

        self.right_boat.tv.set_wrap_mode(gtk.WRAP_CHAR)
        goocanvas.Widget(parent=self.rootitem,
                         widget=self.right_boat.sw,
                         x=x_right,
                         y=y,
                         width=w,
                         height=h,
                         anchor=gtk.ANCHOR_N)
        self.right_boat.tv.show()
        self.right_boat.sw.show()

        # Text Labels
        self.left_boat.speeditem = goocanvas.Text(
            parent=self.rootitem,
            text="",
            font=gcompris.skin.get_font("gcompris/content"),
            x=x_left,
            y=y - 20,
            fill_color_rgba=0xFF0000FFL,
            anchor=gtk.ANCHOR_CENTER)

        self.right_boat.speeditem = goocanvas.Text(
            parent=self.rootitem,
            text="",
            font=gcompris.skin.get_font("gcompris/content"),
            x=x_right,
            y=y - 20,
            fill_color_rgba=0X027308FFL,
            anchor=gtk.ANCHOR_CENTER)

        # The status area
        self.statusitem = goocanvas.Text(
            parent=self.rootitem,
            text="",
            font=gcompris.skin.get_font("gcompris/content"),
            x=gcompris.BOARD_WIDTH / 2,
            y=y - 12,
            fill_color_rgba=0X000a89FFL,
            anchor=gtk.ANCHOR_CENTER)

        # The decoration boats
        pixmap = gcompris.utils.load_pixmap("searace/top_boat_red.png")
        item = goocanvas.Image(
            parent=self.rootitem,
            pixbuf=pixmap,
        )
        gcompris.utils.item_rotate(item, -90)
        item.translate(-y - 40, -10)

        pixmap = gcompris.utils.load_pixmap("searace/top_boat_green.png")
        item = goocanvas.Image(
            parent=self.rootitem,
            pixbuf=pixmap,
        )
        gcompris.utils.item_rotate(item, -90)
        item.translate(-y - 40, gcompris.BOARD_WIDTH - 60)

        # The commands
        hl = 18
        y += 7
        text_color = 0x0000FFFFL
        goocanvas.Text(parent=self.rootitem,
                       text=_("COMMANDS ARE"),
                       font=gcompris.skin.get_font("gcompris/small"),
                       x=gcompris.BOARD_WIDTH / 2,
                       y=y,
                       fill_color_rgba=text_color,
                       anchor=gtk.ANCHOR_CENTER)

        goocanvas.Text(parent=self.rootitem,
                       text=_("forward"),
                       font=gcompris.skin.get_font("gcompris/tiny"),
                       x=gcompris.BOARD_WIDTH / 2,
                       y=y + hl,
                       fill_color_rgba=text_color,
                       anchor=gtk.ANCHOR_CENTER)

        goocanvas.Text(parent=self.rootitem,
                       text=_("left"),
                       font=gcompris.skin.get_font("gcompris/tiny"),
                       x=gcompris.BOARD_WIDTH / 2,
                       y=y + hl * 2,
                       fill_color_rgba=text_color,
                       anchor=gtk.ANCHOR_CENTER)

        goocanvas.Text(parent=self.rootitem,
                       text=_("right"),
                       font=gcompris.skin.get_font("gcompris/tiny"),
                       x=gcompris.BOARD_WIDTH / 2,
                       y=y + hl * 3,
                       fill_color_rgba=text_color,
                       anchor=gtk.ANCHOR_CENTER)
Exemplo n.º 30
0
    def init_board(self):

        self.state = "Ready"

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

        # Another group where we put each canvas line item in it
        self.lines_group = goocanvas.Group(
            parent=self.gcomprisBoard.canvas.get_root_item())

        start_x = 40
        start_y = gcompris.BOARD_HEIGHT / 2
        stop_x = gcompris.BOARD_WIDTH - 100

        # Line path (create several little line)
        min_boundary = 40
        y = start_y
        line_width = 45 - self.gcomprisBoard.level * 2
        step = (stop_x - start_x) / (30)

        frequency = 1 + int(self.gcomprisBoard.level / 4)

        xpi = math.pi / 2 * frequency
        y = start_y + math.cos(xpi) * (self.gcomprisBoard.level * 10)
        for x in range(start_x, stop_x, step):

            xpi += (math.pi / 2 * frequency) / step
            y2 = start_y + math.cos(xpi) * (self.gcomprisBoard.level * 10)

            # Check we stay within boundaries
            if (y2 >= gcompris.BOARD_HEIGHT - min_boundary):
                y2 = gcompris.BOARD_HEIGHT - min_boundary
            elif (y2 <= min_boundary):
                y2 = min_boundary

            item = goocanvas.Polyline(parent=self.lines_group,
                                      points=goocanvas.Points([(x, y),
                                                               (x + step, y2)
                                                               ]),
                                      stroke_color_rgba=self.color_empty,
                                      line_width=line_width,
                                      line_cap=cairo.LINE_CAP_ROUND)
            item.connect("enter_notify_event", self.line_item_event)
            item.connect("button_press_event", self.line_item_event)

            # Draw the black tube
            if x > start_x and x < stop_x - step:
                goocanvas.Polyline(parent=self.rootitem,
                                   points=goocanvas.Points([(x, y),
                                                            (x + step, y2)]),
                                   fill_color_rgba=self.color_border,
                                   line_width=line_width + 20,
                                   line_cap=cairo.LINE_CAP_ROUND)
            y = y2

        self.highlight_next_line()

        # Another group where we put each canvas line item in it
        self.water_spot_group = goocanvas.Group(
            parent=self.gcomprisBoard.canvas.get_root_item())

        # A water spot will be displayed when the user win
        self.water_spot = goocanvas.Image(
            parent=self.water_spot_group,
            pixbuf=gcompris.utils.load_pixmap("followline/water_spot.svg"),
            x=580,
            y=260,
        )
        self.water_spot.props.visibility = goocanvas.ITEM_INVISIBLE