示例#1
0
    def displayTicketBox(self, x, y):
        goocanvas.Rect(parent=self.root,
                       x=x + 5,
                       y=y + 5,
                       width=350,
                       height=230,
                       stroke_color_rgba=0x223344FFL,
                       fill_color_rgba=0x00000000L,
                       radius_x=5.0,
                       radius_y=5.0,
                       line_width=7)

        for i in range(4):
            for j in range(3):
                box = goocanvas.Rect(parent=self.root,
                                     x=x + 7 + 88 * i,
                                     y=y + 7 + 77 * j,
                                     width=82,
                                     height=73,
                                     stroke_color_rgba=0x223344FFL,
                                     fill_color_rgba=0x66666666L,
                                     line_width=2)
                self.rect.append(box)
                self.rect_x.append(x + 7 + 88 * i)
                self.rect_y.append(y + 7 + 77 * j)
示例#2
0
 def _createUI(self):
     self._cursor = ARROW
     root = self.get_root_item()
     self.tracks = goocanvas.Group()
     self.tracks.set_simple_transform(0, KW_LABEL_Y_OVERFLOW, 1.0, 0)
     root.add_child(self.tracks)
     self._marquee = goocanvas.Rect(
         parent=root,
         stroke_pattern=unpack_cairo_pattern(0x33CCFF66),
         fill_pattern=unpack_cairo_pattern(0x33CCFF66),
         visibility=goocanvas.ITEM_INVISIBLE)
     self._playhead = goocanvas.Rect(y=-10,
                                     parent=root,
                                     line_width=1,
                                     fill_color_rgba=0x000000FF,
                                     stroke_color_rgba=0xFFFFFFFF,
                                     width=3)
     self._playhead_controller = PlayheadController(self._playhead)
     self.connect("size-allocate", self._size_allocate_cb)
     root.connect("motion-notify-event", self._selectionDrag)
     root.connect("button-press-event", self._selectionStart)
     root.connect("button-release-event", self._selectionEnd)
     self.height = (LAYER_HEIGHT_EXPANDED + TRACK_SPACING +
                    LAYER_SPACING) * 2
     # add some padding for the horizontal scrollbar
     self.height += 21
     self.set_size_request(-1, self.height)
示例#3
0
def make_element_widget(canvas, element):
    def add_pad_widget(pad_widget):
        d = pad_widget.get_data("direction")
        if d == gst.PAD_SRC:
            source_pads.add_child(pad_widget)
        else:
            sink_pads.add_child(pad_widget)

    def show_pad(pad):
        w = make_pad_widget(canvas, pad, element)
        block_pad(pad)
        add_pad_widget(w)
        return False

    def pad_added(element, pad):
        print pad.get_name(), pad.get_caps()
        gobject.idle_add(show_pad, pad)

    def hide_pad(pad):
        if pad.get_direction() == gst.PAD_SRC:
            source_pads.remove_child(pad.get_data("widget"))
        else:
            sink_pads.remove_child(pad.get_data("widget"))
        return False

    def pad_removed(element, pad):
        print pad.get_name(), pad.get_direction(), pad
        gobject.idle_add(hide_pad, pad)

    background = make_item(element_box)
    text = make_item(element_text)
    text.props.text = element.get_name()
    source_pads = vlist(goocanvas.Rect(width=55))
    sink_pads = vlist(goocanvas.Rect(width=55))
    content = vlist(text, hlist(sink_pads, source_pads))
    size_change(content, lambda size_: set_size(background, size_))
    ret = group(background, content)
    ret.set_data("element", element)
    ret.set_data("box", background)
    background.set_data("element", element)
    make_selectable(canvas, ret)
    make_dragable(canvas, ret, lambda pos_: (max(0, pos_[0]), max(0, pos_[1])))

    for pad in element.get_pad_template_list():
        if pad.presence == gst.PAD_REQUEST:
            add_pad_widget(make_request_template_widget(canvas, pad, element))

    for pad in element.pads():
        show_pad(pad)

    element.connect("pad-added", pad_added)
    element.connect("pad-removed", pad_removed)
    element.set_data("widget", ret)
    return ret
def setup_canvas(canvas):
    global ellipse1, ellipse2, rect1, rect2, rect3, rect4

    root = canvas.get_root_item()

    # Absolute.
    ellipse1 = goocanvas.Ellipse(parent=root,
                                 center_x=0,
                                 center_y=0,
                                 radius_x=25,
                                 radius_y=15,
                                 fill_color="blue")
    ellipse1.translate(100, 100)

    rect1 = goocanvas.Rect(parent=root,
                           x=-10,
                           y=-10,
                           width=20,
                           height=20,
                           fill_color="blue")
    rect1.translate(100, 200)

    rect3 = goocanvas.Rect(parent=root,
                           x=-10,
                           y=-10,
                           width=20,
                           height=20,
                           fill_color="blue")
    rect3.translate(200, 200)

    # Relative.
    ellipse2 = goocanvas.Ellipse(parent=root,
                                 center_x=0,
                                 center_y=0,
                                 radius_x=25,
                                 radius_y=15,
                                 fill_color="red")
    ellipse2.translate(100, 400)

    rect2 = goocanvas.Rect(parent=root,
                           x=-10,
                           y=-10,
                           width=20,
                           height=20,
                           fill_color="red")
    rect2.translate(100, 500)

    rect4 = goocanvas.Rect(parent=root,
                           x=-10,
                           y=-10,
                           width=20,
                           height=20,
                           fill_color="red")
    rect4.translate(200, 500)
示例#5
0
    def __createFrame(self):
        line = goocanvas.Rect(fill_color=self.IMAGE_FRAME_COLOR, line_width=0)
        line.props.x = self.image.props.x + self.image.props.width
        line.props.y = self.image.props.y
        line.props.width = self.IMAGE_FRAME_THICKNESS
        line.props.height = self.image.props.height + self.IMAGE_FRAME_THICKNESS
        self.frame.append(line)

        line = goocanvas.Rect(fill_color=self.IMAGE_FRAME_COLOR, line_width=0)
        line.props.x = self.image.props.x
        line.props.y = self.image.props.y + self.image.props.height
        line.props.width = self.image.props.width + 1
        line.props.height = self.IMAGE_FRAME_THICKNESS
        self.frame.append(line)
示例#6
0
    def __init__(self, instance, element, track, timeline):
        goocanvas.Group.__init__(self)
        View.__init__(self)
        Zoomable.__init__(self)
        self.app = instance
        self.track = track
        self.timeline = timeline
        self.namewidth = 0
        self.nameheight = 0

        self.bg = goocanvas.Rect(height=self.height, line_width=0)

        self.content = Preview(element)

        self.name = goocanvas.Text(x=NAME_HOFFSET + NAME_PADDING,
                                   y=NAME_VOFFSET + NAME_PADDING,
                                   operator=cairo.OPERATOR_ADD,
                                   alignment=pango.ALIGN_LEFT)
        self.namebg = goocanvas.Rect(radius_x=2,
                                     radius_y=2,
                                     x=NAME_HOFFSET,
                                     y=NAME_VOFFSET,
                                     line_width=0)

        self.start_handle = StartHandle(self.app,
                                        element,
                                        timeline,
                                        height=self.height)
        self.end_handle = EndHandle(self.app,
                                    element,
                                    timeline,
                                    height=self.height)

        self.selection_indicator = goocanvas.Rect(
            visibility=goocanvas.ITEM_INVISIBLE,
            line_width=0.0,
            height=self.height)

        for thing in (self.bg, self.content, self.selection_indicator,
                      self.start_handle, self.end_handle, self.namebg,
                      self.name):
            self.add_child(thing)

        for prop, interpolator in element.getInterpolators().itervalues():
            self.add_child(Curve(instance, element, interpolator, 50))

        self.element = element
        self.settings = instance.settings
        self.normal()
示例#7
0
    def __init__(self, timeline, **kwargs):
        kwargs["parent"] = timeline.get_root_item()

        if "width" in kwargs:
            width = kwargs["width"]
            del kwargs["width"]
        else:
            width = 50

        goocanvas.Group.__init__(self, **kwargs)

        self.timeline = timeline

        self.rect = goocanvas.Rect(parent=self,
                                   width=width,
                                   height=timeline.get_pts(
                                       timeline.project.pipeline.duration),
                                   fill_color="blue")
        self.rect.connect("button_press_event", self.button_press)
        self.motion_handler_id = None
        self.release_handler_id = None

        # labelling
        for i in xrange(int(timeline.project.pipeline.duration)):
            goocanvas.Text(parent=self,
                           text=str(1.0 * i),
                           y=timeline.get_pts(i),
                           pointer_events=0)

        # playback marker
        self.playback_marker = goocanvas.Rect(
            parent=self,
            width=width,
            height=0,
            visibility=goocanvas.ITEM_INVISIBLE,
            fill_color_rgba=0x00000044)
        self.playback_marker.props.pointer_events = 0  # let self.rect receive pointer events

        # playback marker adjustments
        self.marker_start = gtk.Adjustment(0, 0,
                                           timeline.project.pipeline.duration,
                                           0.01)
        self.marker_duration = gtk.Adjustment(
            0, 0, timeline.project.pipeline.duration, 0.01)
        self.start_handler = self.marker_start.connect("value-changed",
                                                       self.start_changed)
        self.duration_handler = self.marker_duration.connect(
            "value-changed", self.duration_changed)
示例#8
0
def setup_canvas(canvas, units, units_name):
    data = [[100, 100, 200, 20, 10, 200, 310, 24],
            [100, 100, 200, 20, 10, 200, 310, 24],
            [1, 1, 3, 0.5, 0.16, 3, 4, 0.3], [30, 30, 100, 10, 5, 80, 60, 10]]

    d = data[units]

    root = canvas.get_root_item()

    item = goocanvas.Rect(parent=root, x=d[0], y=d[1], width=d[2], height=d[3])

    item.connect("motion_notify_event", on_motion_notify)

    buffer = "This box is %gx%g %s" % (d[2], d[3], units_name)
    font_desc = "Sans %gpx" % d[4]

    item = goocanvas.Text(parent=root,
                          text=buffer,
                          x=d[0] + d[2] / 2,
                          y=d[1] + d[3] / 2,
                          width=-1,
                          anchor=gtk.ANCHOR_CENTER,
                          font=font_desc)

    buffer = "This font is %g %s high" % (d[7], units_name)
    font_desc = "Sans %gpx" % d[7]

    item = goocanvas.Text(parent=root,
                          text=buffer,
                          x=d[5],
                          y=d[6],
                          width=-1,
                          anchor=gtk.ANCHOR_CENTER,
                          font=font_desc)
示例#9
0
    def __init__(self, element, selection):
        goocanvas.Group.__init__(self)
        selectable.Selectable.__init__(self, selection)
        self.register_instance(self)
        self.element = element
        self.bg = goocanvas.Rect(
            parent = self,
            fill_color = "grey",
            radius_x = 5,
            radius_y = 5)

        self.text = goocanvas.Text(
            parent = self,
            font = "Sans 8 Bold",
            text = element.get_name())

        self.__sourcePads = {}
        self.__sinkPads = {}
        self.__links = {}

        for pad in element.get_pad_template_list():
            if pad.presence != gst.PAD_ALWAYS:
                self.__addPad(pad)

        for pad in element.pads():
            self.__addPad(pad)
    def play_sound_on_click(self, widget, target, event, numID):
        '''
        plays the note sound when the mouse clicks on the note name
        '''
        self.selectedNoteObject = widget

        if self.pitchSoundEnabled:
            # change the sound to be played to the c" sound, if we asked for a c"
            # and the user clicked the c-button
            if self.currentNote.numID == 8 and numID == 1:
                numID = 8
            HalfNote(numID, self.staff.staffName, self.staff.rootitem).play()
        if hasattr(self, 'focusRect'):
            self.focusRect.remove()

        self.focusRect = goocanvas.Rect(parent=self.rootitem,
                                        x=self.selectedNoteObject.props.x + 6,
                                        y=self.selectedNoteObject.props.y +
                                        8.5,
                                        width=28,
                                        height=23,
                                        radius_x=5,
                                        radius_y=5,
                                        stroke_color="black",
                                        line_width=1.0)
        self.focusRect.translate(-515, -320)
        self.focusRect.scale(2.0, 2.0)
        def drawNoteButton(x, y, numID, play_sound_on_click):
            '''
            local method to draw one button
            '''
            if self.colorButtons:
                color = NOTE_COLOR_SCHEME[numID]
            else:
                color = 'white'
            text = getKeyNameFromID(numID, self.sharpNotation)
            vars(self)[str(numID)] = goocanvas.Text(
                parent=self.rootitem,
                x=x,
                y=y,
                text=text,
                fill_color='black',
                anchor=gtk.ANCHOR_CENTER,
                alignment=pango.ALIGN_CENTER,
                pointer_events="GOO_CANVAS_EVENTS_NONE")

            rect = goocanvas.Rect(parent=self.rootitem,
                                  x=x - 12.5,
                                  y=y - 10,
                                  width=25,
                                  height=20,
                                  line_width=.5,
                                  fill_color=color)
            vars(self)[str(numID)].raise_(None)
            vars(self)[str(numID)].scale(2.0, 2.0)
            vars(self)[str(numID)].translate(-250, -150)
            rect.scale(2, 2)
            rect.translate(-250, -150)
            rect.connect("button_press_event", play_sound_on_click, numID)
            rect.set_data('numID', numID)
            gcompris.utils.item_focus_init(rect, None)
            gcompris.utils.item_focus_init(vars(self)[str(numID)], None)
示例#12
0
    def __init__(self, rootitem, x, y, width, height, number_of_sections):
        '''
        display an empty progress bar
        '''
        self.rootitem = rootitem
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.number_of_sections = number_of_sections

        txt2 = _('Explore Status:')
        item = goocanvas.Text(
            parent=self.rootitem,
            x=self.x,
            y=self.y,
            text=txt2,
            font=gcompris.skin.get_font("gcompris/board/medium"),
            use_markup=True)

        bounds = item.get_bounds()
        # This is the start of the bar
        self.x += bounds.x2 - bounds.x1 + 20
        self.progressBar = goocanvas.Rect(parent=self.rootitem,
                                          x=self.x,
                                          y=self.y,
                                          width=self.width,
                                          height=self.height,
                                          stroke_color="black",
                                          fill_color_rgba=0x666666AAL,
                                          line_width=2.0,
                                          radius_x=3,
                                          radius_y=3)
示例#13
0
    def draw(self):

        self.selected_color = 0x3030AAFFL
        self.default_color = 0xFFFFFFFFL
        self.default_stroke = 0x101080FFL
        self.marked_stroke = 0xC01010FFL

        # Timeline coord
        x1 = self.drawing_area[0]
        x2 = self.drawing_area[2]
        y = self.drawing_area[3] + 5

        # Our timeline repesentation respects the drawing area ratio
        # If we could display a thumbnail of the current frame in each
        # time zone, and we could scroll the time zone.
        #self.zoom = (( self.drawing_area[2] - self.drawing_area[0] ) /
        #             ( self.drawing_area[3] - self.drawing_area[1] ))
        # w = h * self.zoom
        w = 14
        h = 27

        i = x1
        t = 0
        while i + w < x2:

            item = goocanvas.Rect(parent=self.rootitem,
                                  x=i,
                                  y=y,
                                  width=w,
                                  height=h,
                                  fill_color_rgba=self.default_color,
                                  stroke_color_rgba=self.default_stroke,
                                  line_width=1.0,
                                  radius_x=3.0,
                                  radius_y=3.0)
            item.set_data("time", t)

            if not self.selected:
                self.selected = item

            self.timelinelist.append(item)
            item.connect("button_press_event", self.timeline_item_event)

            i += w + 1
            t += 1

        # Frame Number
        self.frame_counter = \
            goocanvas.Text(
            parent = self.anim.rootitem,
            text = 0,
            x = 43,
            y = 460,
            font = gcompris.skin.get_font("gcompris/board/medium"),
            fill_color = "black")

        # Select the first item in the timeline
        self.current_time = 0
        self.select_it(self.selected)
        self.lastmark_it(self.timelinelist[t - 1])
示例#14
0
    def __init__(self, element, composition, timeline):
        goocanvas.Group.__init__(self)
        View.__init__(self)
        Zoomable.__init__(self)

        self.element = element
        self.comp = composition
        self.timeline = timeline

        self.bg = goocanvas.Rect(height=self.__HEIGHT__,
                                 fill_color_rgba=self.__NORMAL__,
                                 line_width=0)

        self.content = Preview(self.element)
        self.name = goocanvas.Text(x=10,
                                   text=os.path.basename(
                                       unquote(element.factory.name)),
                                   font="Sans 9",
                                   fill_color_rgba=0x000000FF,
                                   alignment=pango.ALIGN_LEFT)

        self.start_handle = StartHandle(element,
                                        timeline,
                                        height=self.__HEIGHT__)
        self.end_handle = EndHandle(element, timeline, height=self.__HEIGHT__)

        for thing in (self.bg, self.content, self.start_handle,
                      self.end_handle, self.name):
            self.add_child(thing)

        if element:
            self.zoomChanged()
        self.normal()
示例#15
0
    def __init__(self, hangman, parent, x, y,
                 letter, letters, fill_color, stroke_color):
      self.hangman = hangman
      self.letter = letter
      self.letters = letters
      self.disabled = False

      w = 30
      h = 30

      self.rect = goocanvas.Rect(
        parent = parent,
        x = x,
        y = y,
        width = w,
        height = h,
        fill_color_rgba = fill_color,
        stroke_color_rgba = stroke_color,
        line_width = 1.0)

      self.letterItem = goocanvas.Text(
        parent = parent,
        x = x + w/2,
        y = y + h/2,
        text = letter,
        fill_color = "black",
        anchor = gtk.ANCHOR_CENTER,
        alignment = pango.ALIGN_CENTER
        )

      self.letterItem.connect("button_press_event",
                              self.letter_event, letter)
      self.rect.connect("button_press_event",
                        self.letter_event, letter)
示例#16
0
    def __init__(self, hangman, x, y,
                 letter, letters):
      self.found = False
      parent = hangman.rootitem

      fill_color = 0xFF3366AAL
      stroke_color = 0xFF33CCAAL
      w = 30
      h = 30

      self.letters = letters

      self.rect = goocanvas.Rect(
        parent = parent,
        x = x,
        y = y,
        width = w,
        height = h,
        fill_color_rgba = fill_color,
        stroke_color_rgba = stroke_color,
        line_width = 1.0)

      self.letterItem = goocanvas.Text(
        parent = parent,
        x = x + w/2,
        y = y + h/2,
        text = letter,
        fill_color = "black",
        anchor = gtk.ANCHOR_CENTER,
        alignment = pango.ALIGN_CENTER
        )

      self.hide(True)
示例#17
0
def main():
    window = gtk.Window()
    window.set_default_size(640, 600)
    window.show()
    window.connect("destroy", lambda w: gtk.main_quit())

    scrolled_win = gtk.ScrolledWindow()
    scrolled_win.set_shadow_type(gtk.SHADOW_IN)
    scrolled_win.show()

    window.add(scrolled_win)

    canvas = goocanvas.Canvas()
    canvas.set_size_request(600, 450)
    canvas.set_bounds(0, 0, 1000, 1000)

    root = canvas.get_root_item()

    handle = rsvg.Handle("../images/circle1.svg")

    svgitem = CustomSvgItem(x=100, y=100, handle=handle, parent=root)
    svgitem.connect("button_press_event", on_press, root)

    r = goocanvas.Rect(parent=root, x=10, y=10, width=20, height=20)
    r.connect("button_press_event", on_r_press)
    r.props.fill_color = 'yellow'

    canvas.show()
    scrolled_win.add(canvas)

    gtk.main()
示例#18
0
    def __init__(self, rootitem, x, y, width, height, number_of_sections):
        '''
        display an empty progress bar
        '''
        self.rootitem = rootitem
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.number_of_sections = number_of_sections

        txt2 = _('Explore Status:')
        item = goocanvas.Text(
            parent=self.rootitem,
            x=self.x,
            y=self.y,
            text='<span font_family="URW Gothic L" size="medium" \
          weight="bold" style="italic">' + txt2 + '</span>',
            use_markup=True)

        bounds = item.get_bounds()
        # This is the start of the bar
        self.x += bounds.x2 - bounds.x1 + 20
        self.progressBar = goocanvas.Rect(parent=self.rootitem,
                                          x=self.x,
                                          y=self.y,
                                          width=self.width,
                                          height=self.height,
                                          stroke_color="black",
                                          fill_color_rgba=0x666666AAL,
                                          line_width=2.0,
                                          radius_x=3,
                                          radius_y=3)
示例#19
0
    def __init__(self, animitem):
        self.animitem = animitem

        self.anchorgroup = None

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

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

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

        self.up = \
            goocanvas.Image(
            parent = self.anchorgroup,
            pixbuf = gcompris.utils.load_pixmap("anim/up.png"),
            )
        self.up.connect("button_press_event",
                    self.animitem.up_size, False)
示例#20
0
    def writeText(self, txt, x=100, y=250, width=150):
        '''
        write text box with background rectangle to game
        the text is returned and must be removed by the caller
        '''

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

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

        TG = 10
        bounds = t.get_bounds()

        rect = goocanvas.Rect(parent=textrootitem,
                              x=bounds.x1 - TG,
                              y=bounds.y1 - TG,
                              width=bounds.x2 - bounds.x1 + TG * 2,
                              height=bounds.y2 - bounds.y1 + TG * 2,
                              line_width=2.0,
                              radius_x=3.0,
                              radius_y=3.0,
                              fill_color_rgba=TEXT_BG_COLOR,
                              stroke_color="black")
        t.raise_(rect)
        return textrootitem
示例#21
0
 def restore(self, anim_):
     AnimItem.restore(self, anim_)
     self.item = \
         goocanvas.Rect(
             parent = self.rootitem
             )
     AnimItem.init_item(self)
示例#22
0
  def speed_button(self, x, y, size, text, move):
    button = goocanvas.Rect(
      parent = self.rootitem,
      x = x - size / 2.0,
      y = y - size / 2.0,
      width = size,
      height =  size,
      line_width = 1.0,
      stroke_color_rgba= 0xCECECEFFL,
      fill_color_rgba = 0x333333FFL,
      radius_x = 15.0,
      radius_y = 5.0,
      )
    gcompris.utils.item_focus_init(button, None)

    text = goocanvas.Text(
      parent = self.rootitem,
      x = x,
      y = y,
      text = text,
      font = gcompris.skin.get_font("gcompris/subtitle"),
      fill_color = "white",
      anchor = gtk.ANCHOR_CENTER,
      alignment = pango.ALIGN_CENTER
      )
    gcompris.utils.item_focus_init(text, button)

    button.connect("button_press_event", self.move_bar, move)
    text.connect("button_press_event", self.move_bar, move)
示例#23
0
  def instructions(self, message):
    # Instructions button to begin activity
    self.text = goocanvas.Text(
      parent = self.rootitem,
      x = 400,
      y = 103,
      fill_color = "white",
      anchor = gtk.ANCHOR_CENTER,
      alignment = pango.ALIGN_LEFT,
      width = 500,
      font = gcompris.skin.get_font("gcompris/board/small"),
      text = message )
    self.text.connect('button_press_event', self.ready_event)
    bounds = self.text.get_bounds()
    gap = 20

    self.text_back = goocanvas.Rect(
      parent = self.rootitem,
      radius_x = 6,
      radius_y = 6,
      x = bounds.x1 - gap,
      y = bounds.y1 - gap,
      width = bounds.x2 - bounds.x1 + gap * 2,
      height = bounds.y2 - bounds.y1 + gap * 2,
      stroke_color_rgba = 0xFFFFFFFFL,
      fill_color_rgba = 0xCCCCCC44L)
    gcompris.utils.item_focus_init(self.text_back, None)
    gcompris.utils.item_focus_init(self.text, self.text_back)
    self.text_back.connect('button_press_event', self.ready_event)
示例#24
0
def create_width_for_height_table(root, x, y, width, height, rotation):

    text = "This is a long paragraph that will have to be split over a few \
           lines so we can see if its allocated height changes when its \
           allocated width is changed."

    table = goocanvas.Table(parent=root, width=width, height=height)

    table.translate(x, y)
    table.rotate(rotation, 0, 0)

    item = goocanvas.Rect(parent=table,
                          x=0.0,
                          y=0.0,
                          width=width - 2,
                          height=10.0,
                          fill_color="red")

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

    item = goocanvas.Text(parent=table,
                          text=text,
                          x=0,
                          y=0,
                          width=-1,
                          anchor=gtk.ANCHOR_NW)

    table.set_child_properties(item,
                               row=1,
                               column=0,
                               x_expand=True,
                               x_fill=True,
                               x_shrink=True,
                               y_expand=True,
                               y_fill=True)

    item.set_data("id", "Text Item")
    item.connect("button_press_event", on_button_press)

    item = goocanvas.Rect(parent=table,
                          x=0.0,
                          y=0.0,
                          width=width - 2,
                          height=10.0,
                          fill_color="red")

    table.set_child_properties(item, row=2, column=0, x_shrink=True)
示例#25
0
    def start(self):
        self.board_paused = False
        self.game_start = False
        # Create our rootitem. We put each canvas item in it so at the end we
        # only have to kill it. The canvas deletes all the items it contains
        # automaticaly.
        self.rootitem = goocanvas.Group(
            parent=self.gcomprisBoard.canvas.get_root_item())
        land_rootitem = goocanvas.Group(parent=self.rootitem)

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

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

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

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

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

        gcompris.bar_set_level(self.gcomprisBoard)

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

        self.ready_button(self.rootitem)
示例#26
0
  def __init__(self, rootitem, move_back_callback):

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

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

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

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

      # Move back item
      item = goocanvas.Image(parent = rootitem,
                             pixbuf = gcompris.utils.load_pixmap("braille_alphabets/back.svg"),
                             x = 430,
                             y = 400,
                             tooltip = _("Back to the activity")
                             )
      gcompris.utils.item_focus_init(item, None)
      item.connect("button_press_event", move_back_callback)
示例#27
0
  def display_user_list(self, users, start_filter):

    y_start = 80
    y = y_start
    x = gcompris.BOARD_WIDTH/4
    i = 0
    step_y = 90

    for user in users:
      if eval(self.config_dict['uppercase_only']):
        login = user.login.decode('utf8').upper().encode('utf8')
      else:
        login = user.login

      if not login.startswith(start_filter):
        continue

      # The text
      item = goocanvas.Text(
        parent = self.rootitem,
        x= x,
        y= y,
        text= login,
        fill_color="white",
        font=gcompris.skin.get_font("gcompris/board/huge"),
        anchor = gtk.ANCHOR_CENTER,
        )
      item.connect("button_press_event", self.name_click_event, user)

      gap = 10
      bounds = item.get_bounds()
      item_bg = \
          goocanvas.Rect(
          parent = self.rootitem,
          x = bounds.x1 - gap,
          y = bounds.y1 - gap,
          width = bounds.x2 - bounds.x1 + gap*2,
          height = bounds.y2 - bounds.y1 + gap*2,
          line_width=2.0,
          fill_color_rgba=0x555555CAL,
          stroke_color_rgba=0xFFFFFFFFL,
          radius_x=5.0,
          radius_y=5.0)
      item_bg.connect("button_press_event", self.name_click_event, user)
      item.raise_(item_bg)
      # This item is clickeable and it must be seen
      gcompris.utils.item_focus_init(item, item_bg)
      gcompris.utils.item_focus_init(item_bg, None)

      y += step_y
      i += 1

      # Perform the column switch
      if(i==5):
        y = y_start
        x = 3*gcompris.BOARD_WIDTH/4
示例#28
0
 def item_event (self, item, target, event):
   if event.type == gtk.gdk.BUTTON_PRESS:
       item = goocanvas.Rect(
       parent = self.backroot,
       x = 0,
       y = 0,
       width = gcompris.BOARD_WIDTH,
       height = 900,
       fill_color = "pink"
       )
示例#29
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)
示例#30
0
 def _BbRect(self):
     self.SetBackColor()
     #w1 = goocanvas.Polyline(points=goocanvas.Points(pf), fill_color_rgba=ColorFromList(self.m_oBackColor), line_width=1)
     w1 = goocanvas.Rect(width=self.width,
                         height=self.height,
                         fill_color_rgba=ColorFromList(self.m_oBackColor),
                         line_width=1,
                         radius_x=self.m_nRadius,
                         radius_y=self.m_nRadius)
     self.wGroup.add_child(w1)
     self.widgets["Rect"] = w1