Пример #1
0
    def __init__(self, x, y, width, height, color="title"):
        Base.__init__(self)
        clutter.Group.__init__(self)

        self.width = self.get_abs_x(width)
        self.height = self.get_abs_y(height)
        self.bar_width = int(self.width * self.BAR_LENGTH)
        self.bar_x = int(self.width * self.INFO_LENGTH)
        self.media_length_x = (1 - self.INFO_LENGTH + 0.05) * width

        self.set_position(self.get_abs_x(x), self.get_abs_y(y))

        self._color = self._color_to_cairo_color(
            self.config.theme.get_color(color))

        self._background = clutter.CairoTexture(self.bar_width, self.height)
        self._draw_background()
        self._background.set_position(self.bar_x, 0)
        self.add(self._background)

        self._foreground = clutter.CairoTexture(self.height, self.height)
        self._foreground.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
        self._draw_foreground()
        self._foreground.set_position(self.bar_x, 0)
        self.add(self._foreground)

        self.media_position = Label(0.037, "title", 0, 0, "")
        self.add(self.media_position)

        self.media_length = Label(0.037, "title", self.media_length_x, 0, "")
        self.add(self.media_length)

        self._media_player = None
        self._progress_bar_moving = False

        self._hide_timeout_key = None
        self.auto_display = False
        self._visible = None
        self._timeline = clutter.Timeline(500)
        self._alpha = clutter.Alpha(self._timeline, clutter.EASE_IN_OUT_SINE)
        self._behaviour = clutter.BehaviourOpacity(0, 255, self._alpha)
        self._behaviour.apply(self)

        self._progress = None
        # Call the property setter to initialize the displayed position.
        self.progress = 0

        # Preparation to pointer events handling.
        self._motion_handler = 0
        self.set_reactive(True)
        self.connect('scroll-event', self._on_scroll_event)
        self.connect('button-press-event', self._on_button_press_event)
        self.connect('button-release-event', self._on_button_release_event)
        self.connect('enter-event', self._on_enter_event)
        self.connect('leave-event', self._on_leave_event)
Пример #2
0
def main():
    stage = clutter.Stage()
    stage.set_color(clutter.Color(red=0xff, green=0xcc, blue=0xcc, alpha=0xff))
    stage.set_size(width=400, height=300)
    stage.connect('button-press-event', on_button_press_event)
    stage.connect('destroy', clutter.main_quit)

    cairo_tex = clutter.CairoTexture(width=200, height=200)
    cairo_tex.set_position(x=(stage.get_width() - 200) / 2,
                           y=(stage.get_height() - 200) / 2)

    # we obtain a cairo context from the clutter.CairoTexture
    # and then we can use it with the cairo primitives to draw
    # on it.
    context = cairo_tex.cairo_create()

    # we scale the context to the size of the surface
    context.scale(200, 200)
    context.set_line_width(0.1)
    context.set_source_color(clutter.Color(255, 0, 0, 0x88))
    context.translate(0.5, 0.5)
    context.arc(0, 0, 0.4, 0, pi * 2)
    context.stroke()

    del (context)  # we need to destroy the context so that the
    # texture gets properly updated with the result
    # of our operations; you can either move all the
    # drawing operations into their own function and
    # let the context go out of scope or you can
    # explicitly destroy it

    # clutter.CairoTexture is a clutter.Actor, so we can
    # manipulate it as any other actor
    center_x = cairo_tex.get_width() / 2
    center_z = cairo_tex.get_height() / 2
    cairo_tex.set_rotation(clutter.Y_AXIS, 45.0, center_x, 0, center_z)
    stage.add(cairo_tex)
    cairo_tex.show()

    # clutter.CairoTexture is also a clutter.Texture, so we can save
    # memory when dealing with multiple copies by simply cloning it
    # and manipulating the clones
    clone_tex = clutter.Clone(cairo_tex)
    clone_tex.set_position((stage.get_width() - 200) / 2,
                           (stage.get_height() - 200) / 2)
    clone_tex.set_rotation(clutter.Y_AXIS, -45.0, center_x, 0, center_z)
    stage.add(clone_tex)
    clone_tex.show()

    stage.show()

    clutter.main()

    return 0
Пример #3
0
    def __init__(self, width=DEFAULT_SYMBOL_SIZE):
        super(RightArrow, self).__init__(width=width, color='green')

        self.arrow = clutter.CairoTexture(width, width)
        cr = self.arrow.cairo_create()
        cr.set_source_rgba(1, 1, 1, 0.4)
        cr.move_to(width / 2, width / 2 - width / 3)
        cr.line_to(width - width / 9, width / 2)
        cr.line_to(width / 2, width / 2 + width / 3)
        cr.close_path()
        cr.rectangle(width / 6, width / 3, width / 3, width / 3)
        cr.fill()
        del cr
        self.add(self.arrow)
Пример #4
0
    def __init__(self, width=DEFAULT_SYMBOL_SIZE, color='solid'):
        super(Symbol, self).__init__(clutter.BinLayout(True, True))

        self.set_width(width)

        self.circle = clutter.CairoTexture(width, width)
        cr = self.circle.cairo_create()
        cr.set_operator(cairo.OPERATOR_CLEAR)
        cr.paint()
        cr.set_operator(cairo.OPERATOR_OVER)
        cr.arc(width / 2, width / 2, width / 2, 0.0, 2 * math.pi)

        if color == 'solid':
            pattern = cairo.SolidPattern(0.20, 0.20, 0.20, 0.9)
            cr.set_source(pattern)
            cr.fill_preserve()
            del pattern

        elif color == 'bubble':
            pattern = cairo.RadialGradient(width / 2, width / 2, 0, width / 2,
                                           width / 2, width / 2)
            pattern.add_color_stop_rgba(0, 0.88, 0.95, 0.99, 0.1)
            pattern.add_color_stop_rgba(0.6, 0.88, 0.95, 0.99, 0.1)
            pattern.add_color_stop_rgba(0.8, 0.67, 0.83, 0.91, 0.2)
            pattern.add_color_stop_rgba(0.9, 0.5, 0.67, 0.88, 0.7)
            pattern.add_color_stop_rgba(1.0, 0.3, 0.43, 0.69, 0.8)
            cr.set_source(pattern)
            cr.fill_preserve()
            del pattern

            pattern = cairo.LinearGradient(0, 0, width, width)
            pattern.add_color_stop_rgba(0.0, 1.0, 1.0, 1.0, 0.0)
            pattern.add_color_stop_rgba(0.15, 1.0, 1.0, 1.0, 0.95)
            pattern.add_color_stop_rgba(0.3, 1.0, 1.0, 1.0, 0.0)
            pattern.add_color_stop_rgba(0.7, 1.0, 1.0, 1.0, 0.95)
            pattern.add_color_stop_rgba(1.0, 1.0, 1.0, 1.0, 0.0)
            cr.set_source(pattern)
            cr.fill()
            del pattern

        elif color == 'blue':
            pattern = cairo.RadialGradient(width / 2, width / 2, 0, width / 2,
                                           width / 2, width / 2)
            pattern.add_color_stop_rgba(0, 0.22, 0.22, 0.99, 0.1)
            pattern.add_color_stop_rgba(0.6, 0.22, 0.22, 0.88, 0.1)
            pattern.add_color_stop_rgba(0.8, 0.22, 0.22, 0.67, 0.2)
            pattern.add_color_stop_rgba(0.9, 0.22, 0.22, 0.55, 0.7)
            pattern.add_color_stop_rgba(1.0, 0.22, 0.22, 0.44, 0.8)
            cr.set_source(pattern)
            cr.fill_preserve()
            del pattern

            pattern = cairo.RadialGradient(width / 2, width / 2, 0, width / 2,
                                           width / 2, width / 2)
            pattern.add_color_stop_rgba(0.9, 0.22, 0.22, 0.99, 0.1)
            pattern.add_color_stop_rgba(0.8, 0.22, 0.22, 0.88, 0.1)
            pattern.add_color_stop_rgba(0.75, 0.22, 0.22, 0.67, 0.2)
            pattern.add_color_stop_rgba(0.7, 0.22, 0.22, 0.55, 0.7)
            pattern.add_color_stop_rgba(0.1, 0.22, 0.22, 0.44, 0.8)
            cr.set_source(pattern)
            cr.fill_preserve()
            del pattern

            pattern = cairo.LinearGradient(0, 0, width, width)
            pattern.add_color_stop_rgba(0.0, 0.0, 0.0, 1.0, 0.0)
            pattern.add_color_stop_rgba(0.15, 0.0, 0.0, 1.0, 0.95)
            pattern.add_color_stop_rgba(0.3, 0.0, 0.0, 1.0, 0.0)
            pattern.add_color_stop_rgba(0.7, 0.0, 0.0, 1.0, 0.95)
            pattern.add_color_stop_rgba(1.0, 0.0, 0.0, 1.0, 0.0)
            cr.set_source(pattern)
            cr.fill()
            del pattern

        elif color == 'green':
            pattern = cairo.RadialGradient(width / 2, width / 2, 0, width / 2,
                                           width / 2, width / 2)
            pattern.add_color_stop_rgba(0, 0.22, 0.99, 0.22, 0.1)
            pattern.add_color_stop_rgba(0.6, 0.22, 0.88, 0.22, 0.1)
            pattern.add_color_stop_rgba(0.8, 0.22, 0.67, 0.22, 0.2)
            pattern.add_color_stop_rgba(0.9, 0.22, 0.55, 0.22, 0.7)
            pattern.add_color_stop_rgba(1.0, 0.22, 0.44, 0.22, 0.8)
            cr.set_source(pattern)
            cr.fill_preserve()
            del pattern

            pattern = cairo.RadialGradient(width / 2, width / 2, 0, width / 2,
                                           width / 2, width / 2)
            pattern.add_color_stop_rgba(0.9, 0.22, 0.99, 0.22, 0.1)
            pattern.add_color_stop_rgba(0.8, 0.22, 0.88, 0.22, 0.1)
            pattern.add_color_stop_rgba(0.75, 0.22, 0.67, 0.22, 0.2)
            pattern.add_color_stop_rgba(0.7, 0.22, 0.55, 0.22, 0.7)
            pattern.add_color_stop_rgba(0.1, 0.22, 0.44, 0.22, 0.8)
            cr.set_source(pattern)
            cr.fill_preserve()
            del pattern

            pattern = cairo.LinearGradient(0, 0, width, width)
            pattern.add_color_stop_rgba(0.0, 0.0, 1.0, 0.0, 0.0)
            pattern.add_color_stop_rgba(0.15, 0.0, 1.0, 0.0, 0.95)
            pattern.add_color_stop_rgba(0.3, 0.0, 1.0, 0.0, 0.0)
            pattern.add_color_stop_rgba(0.7, 0.0, 1.0, 0.0, 0.95)
            pattern.add_color_stop_rgba(1.0, 0.0, 1.0, 0.0, 0.0)
            cr.set_source(pattern)
            cr.fill()
            del pattern

        elif color == 'red':
            pattern = cairo.RadialGradient(width / 2, width / 2, 0, width / 2,
                                           width / 2, width / 2)
            pattern.add_color_stop_rgba(0, 0.99, 0.22, 0.22, 0.1)
            pattern.add_color_stop_rgba(0.6, 0.88, 0.22, 0.22, 0.1)
            pattern.add_color_stop_rgba(0.8, 0.67, 0.22, 0.22, 0.2)
            pattern.add_color_stop_rgba(0.9, 0.55, 0.22, 0.22, 0.7)
            pattern.add_color_stop_rgba(1.0, 0.44, 0.22, 0.22, 0.8)
            cr.set_source(pattern)
            cr.fill_preserve()
            del pattern

            pattern = cairo.RadialGradient(width / 2, width / 2, 0, width / 2,
                                           width / 2, width / 2)
            pattern.add_color_stop_rgba(0.9, 0.99, 0.22, 0.22, 0.1)
            pattern.add_color_stop_rgba(0.8, 0.88, 0.22, 0.22, 0.1)
            pattern.add_color_stop_rgba(0.75, 0.67, 0.22, 0.22, 0.2)
            pattern.add_color_stop_rgba(0.7, 0.55, 0.22, 0.22, 0.7)
            pattern.add_color_stop_rgba(0.1, 0.44, 0.22, 0.22, 0.8)
            cr.set_source(pattern)
            cr.fill_preserve()
            del pattern

            pattern = cairo.LinearGradient(0, 0, width, width)
            pattern.add_color_stop_rgba(0.0, 1.0, 0.0, 0.0, 0.0)
            pattern.add_color_stop_rgba(0.15, 1.0, 0.0, 0.0, 0.95)
            pattern.add_color_stop_rgba(0.3, 1.0, 0.0, 0.0, 0.0)
            pattern.add_color_stop_rgba(0.7, 1.0, 0.0, 0.0, 0.95)
            pattern.add_color_stop_rgba(1.0, 1.0, 0.0, 0.0, 0.0)
            cr.set_source(pattern)
            cr.fill()
            del pattern

        del cr

        self.add(self.circle)

        # glowing timeline
        self.timeline = clutter.Timeline(duration=settings.ARROW_BLINK_RATE)
        self.timeline.set_loop(True)
        self.alpha = clutter.Alpha(self.timeline, clutter.LINEAR)
        self.blink = clutter.BehaviourOpacity(alpha=self.alpha,
                                              opacity_start=BLINK_OFF_OPACITY,
                                              opacity_end=255)
        self.timeline.connect('completed', self.on_blink_completed)

        # By default we enable blinking for arrow.
        self.blink_on()