Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        self._stage = clutter.Stage()
        self._stage.set_color(clutter.Color(0, 0, 0, 255))
        self._stage.set_size(300, 300)
        self._stage.connect('key-press-event', clutter.main_quit)

        rect = clutter.Rectangle()
        rect.set_color(clutter.Color(255, 255, 255, 0x99))
        rect.set_size(100, 100)
        rect.set_position(100, 100)
        self._stage.add(rect)

        rect = clutter.Rectangle()
        rect.set_color(clutter.Color(255, 255, 255, 255))
        rect.move_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
        rect.set_size(100, 100)
        rect.set_position(100, 100)
        self._stage.add(rect)
        self._gravity = clutter.GRAVITY_NORTH_WEST
        self._rect = rect

        self._timeline = clutter.Timeline(duration=500)
        self._timeline.set_loop(True)
        self._timeline.connect('completed', self.on_timeline_completed, self)

        alpha = clutter.Alpha(self._timeline, clutter.LINEAR)

        self._behave = clutter.BehaviourScale(0.0, 0.0, 1.0, 1.0, alpha=alpha)
        self._behave.apply(rect)

        self._stage.show_all()
Ejemplo n.º 2
0
    def __init__(self, message):
        self.stage = clutter.Stage()
        self.stage.set_color(clutter.color_from_string('DarkSlateGrey'))
        self.stage.set_size(800, 600)
        self.stage.set_title('My First Clutter Application')
        self.stage.connect('key-press-event', clutter.main_quit)
        self.stage.connect('button-press-event', self.on_button_press_event)

        color = clutter.Color(0xff, 0xcc, 0xcc, 0xdd)

        self.label = clutter.Text()
        self.label.set_font_name('Mono 32')
        self.label.set_text(message)
        self.label.set_color(color)
        (label_width, label_height) = self.label.get_size()
        label_x = self.stage.get_width() - label_width - 50
        label_y = self.stage.get_height() - label_height
        self.label.set_position(label_x, label_y)
        self.stage.add(self.label)

        self.cursor = clutter.Rectangle()
        self.cursor.set_color(color)
        self.cursor.set_size(20, label_height)
        cursor_x = self.stage.get_width() - 50
        cursor_y = self.stage.get_height() - label_height
        self.cursor.set_position(cursor_x, cursor_y)
        self.stage.add(self.cursor)

        self.timeline = clutter.Timeline(500)
        self.timeline.set_loop(True)
        alpha = clutter.Alpha(self.timeline, clutter.LINEAR)
        self.behaviour = clutter.BehaviourOpacity(0xdd, 0, alpha)
        self.behaviour.apply(self.cursor)
Ejemplo n.º 3
0
    def __init__(self, current_photo_index, images):
        Screen.__init__(self, 'Photo')

        self.animate = self.config.show_effects
        self.slideshow_step = self.config.slideshow_step

        self.zoom_level = 1
        self.index = current_photo_index
        self.images = images
        self.slideshow = False
        # Slideshow gobject timeout tag
        self.slideshow_timeout_tag = None

        # Create black background
        self.background = clutter.Rectangle()
        self.background.set_size(self.config.stage_width,
                                 self.config.stage_height)
        self.background.set_color((0, 0, 0, 255))
        self.add(self.background)

        # Screen Title (Displayed at the bottom left corner)
        self.screen_title = Label(0.13, "screentitle", 0, 0.87,
                                  _("Information"))
        self.add(self.screen_title)

        self.texture = None
        self._change_image(self.index)
Ejemplo n.º 4
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    rect_color = clutter.Color(255, 255, 255, 153)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Add a rectangle to the stage
    rect = clutter.Rectangle(rect_color)
    rect.set_size(70, 70)
    rect.set_position(50, 100)
    stage.add(rect)
    rect.show()

    # Show the stage
    stage.connect('destroy', clutter.main_quit)
    stage.show()

    timeline = clutter.Timeline(5000)  # milliseconds
    timeline.add_marker_at_time("clutter-tutorial", 2000)  # milliseconds
    timeline.connect('new-frame', on_timeline_new_frame, rect)
    timeline.connect('marker-reached', on_timeline_marker_reached)

    timeline.set_loop(True)

    timeline.start()

    # Start the main loop, so we can respond to events
    clutter.main()

    return 0
Ejemplo n.º 5
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    actor_color = clutter.Color(255, 255, 255, 153)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Add a rectangle to the stage
    rect = clutter.Rectangle(actor_color)
    rect.set_size(100, 100)
    rect.set_position(20, 20)
    stage.add(rect)
    rect.show()

    # Add a label to the stage
    label = clutter.Text("Sans 12", "Some Text", actor_color)
    label.set_size(500, 500)
    label.set_position(20, 150)
    stage.add(label)
    label.show()

    # Show the stage
    stage.connect("destroy", clutter.main_quit)
    stage.show_all()

    # Start the main loop, so we can respond to events:
    clutter.main()

    return 0
Ejemplo n.º 6
0
def main(args):
    stage = clutter.Stage()
    stage.set_size(800, 600)
    stage.set_color(clutter.color_from_string('DarkSlateGray'))
    stage.connect('actor-added', on_stage_add)
    stage.connect('button-press-event', on_button_press_event)

    print "stage color: %s" % (stage.get_color())

    color = clutter.Color(0x35, 0x99, 0x2a, 0x66)
    border_color = color.lighten()
    rect = None
    for i in range(1, 10):
        rect = clutter.Rectangle()
        rect.set_position((800 - (80 * i)) / 2, (600 - (60 * i)) / 2)
        rect.set_size(80 * i, 60 * i)

        # colors are either clutter.Color or 4-tuples
        if i % 2 == 0:
            rect.set_color(color)
        else:
            rect.set_color((0x35, 0x99, 0x2a, 0x33))

        rect.set_border_width(10)
        rect.set_border_color(border_color)

        stage.add(rect)
        rect.show()

    stage.show()
    clutter.main()

    return 0
Ejemplo n.º 7
0
    def __init__(self, ease=clutter.EASE_IN_QUAD):
        if self.__class__ == AnimatedWindowBase:
            raise TypeError, \
                "AnimatedWindowBase is an abstract class, " \
                "must be subclassed with a gtk.Window"

        self._actor = clutter.Rectangle()
        self.ease = ease
Ejemplo n.º 8
0
def main():
    stage_color = clutter.Color(176, 176, 176, 255) # light gray

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(800, 600)
    stage.set_color(stage_color)

    # Create and add a label actor, hidden at first
    global label_filename
    label_filename = clutter.Text()
    label_color = clutter.Color(96, 96, 144, 255) # blueish
    label_filename.set_color(label_color)
    label_filename.set_font_name("Sans 24")
    label_filename.set_position(10, 10)
    label_filename.set_opacity(0)
    stage.add(label_filename)
    label_filename.show()

    # Add a plane under the ellipse of images
    rect_color = clutter.Color(255, 255, 255, 255) # white
    rect = clutter.Rectangle(rect_color)
    rect.set_height(ELLIPSE_HEIGHT + 20)
    rect.set_width(stage.get_width() + 100)
    # Position it so that its center is under the images
    rect.set_position(-(rect.get_width() - stage.get_width()) / 2,
                      ELLIPSE_Y + IMAGE_HEIGHT - (rect.get_height() / 2))
    # Rotate it around its center
    rect.set_rotation(clutter.X_AXIS, -90, 0, rect.get_height() / 2, 0)
    stage.add(rect)
    rect.show()

    # show the stage
    stage.connect("destroy", clutter.main_quit)
    stage.show_all()

    global timeline_rotation
    timeline_rotation = clutter.Timeline(2000) # milliseconds
    timeline_rotation.connect('completed', on_timeline_rotation_completed)

    # Add an actor for each image
    load_images("images")
    add_image_actors(stage)

    # timeline_rotation.set_loop(True)

    # Move them a bit to start with
    global list_items
    if list_items:
        rotate_all_until_item_is_at_front(list_items[0])

    # Start the main loop, so we can respond to events
    clutter.main()

    return 0
Ejemplo n.º 9
0
 def __init__(self):
     clutter.Group.__init__(self)
     self._is_enabled = False
     self._background = clutter.Rectangle()
     self._background.set_color((204, 204, 0, 255))
     self._background.set_size(200, 200)
     self.set_opacity(128)
     self.add(self._background)
     self.connect('over-in', self.on_over_in)
     self.connect('over-out', self.on_over_out)
     self.connect('drop', self.on_drop)
Ejemplo n.º 10
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    actor_color = clutter.Color(255, 255, 255, 153)
    actor_color2 = clutter.Color(16, 64, 144, 255)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Add our custom container to the stage
    box = ExampleBox()

    # Set the size to the preferred size of the container
    box.set_size(-1, -1)
    box.set_position(20, 20)
    stage.add(box)
    box.show()

    # Add some actors to our container
    actor = clutter.Rectangle(color=actor_color)
    actor.set_size(75, 75)
    box.add(actor)
    actor.show()

    actor2 = clutter.Rectangle(color=actor_color2)
    actor2.set_size(75, 75)
    box.add(actor2)
    actor2.show()

    # Show the stage
    stage.show()
    stage.connect('destroy', clutter.main_quit)

    box.do_remove_all()

    # Start the main loop, so we can respond to events
    clutter.main()

    return 0
Ejemplo n.º 11
0
    def _create_playing_preview(self):
        '''Create the Now Playing preview sidebar.'''
        preview = clutter.Group()

        # Video preview of current media
        video_texture = self.media_player.get_texture()
        if video_texture == None:
            video_texture = Texture(self.theme.getImage("default_album_art"))
        width, height = video_texture.get_size()
        x_ratio = (self.PREVIEW_WIDTH - 50) / float(width)
        y_ratio = (self.PREVIEW_HEIGHT - 50) / float(height)

        if x_ratio > y_ratio:
            video_texture.set_scale((self.PREVIEW_HEIGHT - 50) / float(height),
                                    (self.PREVIEW_HEIGHT - 50) / float(height))
            new_width = int(width * \
                ((self.PREVIEW_HEIGHT - 50) / float(height)))
            new_x = int(((self.PREVIEW_WIDTH - 50) - new_width) / 2.0)
            video_texture.set_position(int(new_x), 0)
            # Below are size and position calculations for border rectangle
            rect_x = new_x -3
            rect_y = -3
            new_width = (self.PREVIEW_HEIGHT - 50) / float(height) * width
            new_height = (self.PREVIEW_HEIGHT - 50) / float(height) * height
        else:
            video_texture.set_scale((self.PREVIEW_WIDTH - 50) / float(width),
                                    (self.PREVIEW_WIDTH - 50) / float(width))
            new_height = int(height * \
                ((self.PREVIEW_WIDTH - 50) / float(width)))
            new_y = int(((self.PREVIEW_HEIGHT - 50) - new_height) / 2.0)
            video_texture.set_position(0, int(new_y))
            rect_x = -3
            rect_y = new_y -3
            # Below are size and position calculations for border rectangle
            new_width = (self.PREVIEW_WIDTH - 50) / float(width) * width
            new_height = (self.PREVIEW_WIDTH - 50) / float(width) * height

        # Video frame
        rect = clutter.Rectangle()
        rect.set_size(int(new_width + 6), int(new_height + 6))
        rect.set_position(rect_x, rect_y)
        rect.set_color((128, 128, 128, 192))
        preview.add(rect)

        preview.add(video_texture)

        self._preview_title = Label(0.03, "text", 0.03, 0.74, "")
        preview.add(self._preview_title)

        return preview
Ejemplo n.º 12
0
def main(args):
    stage = clutter.Stage()
    stage.set_size(800, 600)
    stage.set_color(clutter.Color(0xcc, 0xcc, 0xcc, 0xff))
    stage.connect('key-press-event', clutter.main_quit)
    stage.connect('destroy', clutter.main_quit)

    rect = clutter.Rectangle()
    rect.set_position(0, 0)
    rect.set_size(150, 150)
    rect.set_color(clutter.Color(0x33, 0x22, 0x22, 0xff))
    rect.set_border_color(clutter.color_from_string('white'))
    rect.set_border_width(15)
    rect.show()

    knots = ( \
            (   0,   0 ),   \
            ( 300,   0 ),   \
            ( 300, 300 ),   \
            (   0, 300 ),   \
    )

    path = clutter.Path('M 0 0 L 300 0 L 300 300 L 0 300')

    timeline = clutter.Timeline(3000)
    timeline.set_loop(True)
    alpha = clutter.Alpha(timeline, clutter.EASE_OUT_SINE)

    o_behaviour = clutter.BehaviourOpacity(alpha=alpha,
                                           opacity_start=0x33,
                                           opacity_end=255)
    o_behaviour.apply(rect)

    p_behaviour = clutter.BehaviourPath(alpha, path)
    path.add_move_to(0, 0)
    p_behaviour.apply(rect)

    r_behaviour = BehaviourRotate(alpha)
    r_behaviour.apply(rect)

    stage.add(rect)
    stage.show()

    timeline.start()

    clutter.main()

    return 0
Ejemplo n.º 13
0
def main(args):
    stage = clutter.Stage()
    stage.connect('destroy', clutter.main_quit)
    stage.set_color(clutter.Color(0x66, 0x66, 0xdd, 0xff))

    rect = clutter.Rectangle(clutter.Color(0x44, 0xdd, 0x44, 0xff))
    rect.set_size(50, 50)
    rect.set_anchor_point(25, 25)
    rect.set_position(stage.get_width() / 2, stage.get_height() / 2)
    rect.set_opacity(0x88)
    rect.set_reactive(True)
    rect.connect('button-press-event', on_button_press)
    stage.add(rect)

    stage.show()
    clutter.main()
Ejemplo n.º 14
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    actor_color = clutter.Color(255, 255, 255, 153)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Add a rectangle to the stage
    rect = clutter.Rectangle(actor_color)
    rect.set_size(100, 100)
    rect.set_position(20, 20)
    stage.add(rect)
    rect.show()

    # Rotate it 20 degrees away from us around the x axis
    # (around its top edge)
    rect.set_rotation(clutter.X_AXIS, -20, 0, 0, 0)

    # Add a label to the stage
    label = clutter.Text("Sans 12", "Some Text", actor_color)
    label.set_size(500, 500)
    label.set_position(20, 150)
    stage.add(label)
    label.show()

    # Scale it 300% along the x axis
    label.set_scale(3., 1.)

    # Move it up and to the right
    label.move_by(10, -10)

    # Move it along the z axis, further from the viewer
    label.set_depth(-20)

    # Show the stage
    stage.connect("destroy", clutter.main_quit)
    stage.show_all()

    # Start the main loop, so we can respond to events
    clutter.main()

    return 0
Ejemplo n.º 15
0
    def __init__(self, name='', callback=None, has_tabs=False, kind=None):
        """
        You should never create a Screen object directly! This init is supposed
        to be called from child classes that inherit this class.
        """
        Base.__init__(self)
        clutter.Group.__init__(self)

        self.name = name
        self.callback = callback

        self.has_tabs = has_tabs
        if has_tabs:
            self.tab_group = TabGroup(0.95, 0.13, 'title')
            self.tab_group.set_y(self.get_abs_y(0.1))
            self.tab_group.set_anchor_point_from_gravity(
                clutter.GRAVITY_CENTER)
            self.tab_group.set_x(self.get_abs_x(0.5))
            self.tab_group.active = True

            self.add(self.tab_group)

        if kind is None:
            self.kind = self.NORMAL
        else:
            self.kind = kind

        def handle_default():
            '''Return the default handler method.'''
            return self._handle_default

        self.event_handlers = defaultdict(
            handle_default, {
                UserEvent.NAVIGATE_UP: self._handle_up,
                UserEvent.NAVIGATE_DOWN: self._handle_down,
                UserEvent.NAVIGATE_LEFT: self._handle_left,
                UserEvent.NAVIGATE_RIGHT: self._handle_right,
                UserEvent.NAVIGATE_SELECT: self._handle_select
            })

        rect = clutter.Rectangle()
        rect.set_size(self.config.stage_width, self.config.stage_height)
        rect.hide()
        self.add(rect)
Ejemplo n.º 16
0
    def __init__(self, stage):
        # Now, the stage
        #self.stage = clutter.Stage()
        self.stage = stage
        self.stage.set_color(clutter.color_from_string('black'))
        self.stage.set_size(WIDTH, HEIGHT)

        label = clutter.Text()
        label.set_text("Hello Clutter")
        label.set_color(clutter.color_from_string('white'))
        self.stage.add(label)
        # If no position is given it defaults to the upper most left corner.

        rect = clutter.Rectangle()
        rect.set_size(100, 100)
        rect.set_color(clutter.color_from_string('white'))
        self.stage.add(rect)

        self.stage.show_all()
Ejemplo n.º 17
0
    def __init__(self):
        """
        """
        super(CategoryOverlay, self).__init__(clutter.BoxLayout())
        layout = self.get_layout_manager()
        layout.set_vertical(False)
        self.set_color(config.background_color)

        self.boxes = []
        for category_name in game.get_category_names():
            box = clutter.Box(
                clutter.BinLayout(clutter.BIN_ALIGNMENT_CENTER,
                                  clutter.BIN_ALIGNMENT_CENTER))
            rect = clutter.Rectangle()
            rect.set_color(config.square_background_color)
            box.add(rect)
            text = Text(config.category_overlay_font, category_name)
            box.add(text)
            self.add(box)
Ejemplo n.º 18
0
    def __init__(self):
        self.current_mode = 0
        self.stage = clutter.Stage()
        self.stage.set_color(clutter.Color(0x88, 0x88, 0xdd, 0xff))

        self.rect = clutter.Rectangle()
        self.rect.set_color(clutter.Color(0xee, 0x33, 0, 0xff))
        self.rect.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
        self.rect.set_size(50, 50)
        self.rect.set_position(self.stage.get_width() / 2,
                               self.stage.get_height() / 2)
        self.stage.add(self.rect)

        self.easing_mode_label = clutter.Text()
        self.stage.add(self.easing_mode_label)

        self.stage.connect('destroy', clutter.main_quit)
        self.stage.connect('button-press-event', self.on_button_press)
        self.stage.show()
        self.update_label()
Ejemplo n.º 19
0
    def setUp(self):
        '''Set up the test.'''
        EntertainerTest.setUp(self)

        self.menu = GridMenu(0, 0)

        self.cursor = clutter.Rectangle()

        self.item = MenuItem()
        self.item.userdata = "foo"

        self.menu.raw_add_item(MenuItem())
        self.menu.raw_add_item(MenuItem())
        self.menu.raw_add_item(self.item)
        self.menu.raw_add_item(MenuItem())

        self.menu.items_per_row = 2
        self.menu.items_per_col = 2
        self.menu.visible_rows = 2
        self.menu.visible_cols = 2
Ejemplo n.º 20
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    rect_color = clutter.Color(255, 255, 255, 153)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Add a rectangle to the stage
    rect = clutter.Rectangle(rect_color)
    rect.set_size(40, 40)
    rect.set_position(10, 10)
    stage.add(rect)
    rect.show()

    # Show the stage
    stage.connect('destroy', clutter.main_quit)
    stage.show()

    timeline = clutter.Timeline(5000)  # milliseconds
    timeline.set_loop(True)
    timeline.start()

    # Create a clutter alpha for the animation
    alpha = clutter.Alpha(timeline)
    alpha.set_func(on_alpha, None)

    # Create an animation to change the properties
    # XXX: There is a bug in pygobject that will refuse to convert between
    # ints and chars. This should be fixed when clutter 1.2 is out and
    # pyclutter targets it. The result is that the opacity won't be animated
    # the bug report is https://bugzilla.gnome.org/show_bug.cgi?id=591800
    # and shall be fixed in the next release, so perhaps by the time you read
    # this is already fixed.
    rect.animate_with_alpha(alpha, 'x', 150.0, 'y', 150.0, 'opacity', 0.0)

    # Start the main loop, so we can respond to events
    clutter.main()

    return 0
Ejemplo n.º 21
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    rect_color = clutter.Color(255, 255, 255, 153)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Add a rectangle to the stage
    global rect
    rect = clutter.Rectangle(rect_color)
    rect.set_size(70, 70)
    rect.set_position(50, 100)
    stage.add(rect)
    rect.show()

    # Show the stage
    stage.connect('destroy', clutter.main_quit)
    stage.show()

    # Create a score and add two timelines to it,
    # so the second timeline starts when the first one stops
    score = clutter.Score()
    score.set_loop(True)

    timeline_rotation = clutter.Timeline(5000)  # milliseconds
    timeline_rotation.connect('new-frame', on_timeline_rotation_new_frame)
    score.append(timeline=timeline_rotation)

    timeline_move = clutter.Timeline(5000)  # milliseconds
    timeline_move.connect('new-frame', on_timeline_move_new_frame)
    score.append(parent=timeline_rotation, timeline=timeline_move)

    score.start()

    # Start the main loop, so we can respond to events
    clutter.main()

    return 0
Ejemplo n.º 22
0
    def showPreview(self, thumbnail, type, pressedAction=None):
        if self.previewBox:  # replace previous preview
            self.hidePreview()

        (pBoxY, pBoxX, pBoxShownX, pBoxSide, pBoxInSide,
         border) = self._getPBoxCoords(type)
        # 50% transparent yellow TODO: take this from current OS theme ?
        backgroundColor = clutter.color_from_string("yellow")
        backgroundColor.alpha = 128
        background = clutter.Rectangle(color=backgroundColor)
        background.set_size(pBoxSide, pBoxSide)
        background.set_reactive(True)
        background.connect('button-release-event', self._previewPressedCB,
                           pressedAction)

        # resize and fit in the thumbnail
        thumbnail.set_keep_aspect_ratio(True)
        (tw, th) = thumbnail.get_size()
        wf = float(pBoxInSide) / tw
        hf = float(pBoxInSide) / th
        if tw >= th:
            thumbnail.set_size(tw * wf, th * wf)
        else:
            thumbnail.set_size(tw * hf, th * hf)
        (tw, th) = thumbnail.get_size()
        print(tw, th)
        thumbnail.move_by(border + (pBoxInSide - tw) / 2.0,
                          border + (pBoxInSide - th) / 2.0)

        # create a container for the thumbnail and background
        box = clutter.Group()
        box.add(background)
        box.add(thumbnail)
        # TODO: preview layer above the buttons layer ?
        self.buttons.getLayer().add(box)
        box.show()
        box.set_position(pBoxX, pBoxY)
        self.previewBoxStartingPoint = (pBoxX, pBoxY)
        box.animate(clutter.LINEAR, 300, "x", pBoxShownX)
        self.previewBox = box
Ejemplo n.º 23
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    actor_color = clutter.Color(255, 255, 255, 153)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Add a group to the stage
    group = clutter.Group()
    group.set_position(40, 40)
    stage.add(group)
    group.show()

    # Add a rectangle to the group
    rect = clutter.Rectangle(actor_color)
    rect.set_size(50, 50)
    rect.set_position(0, 0)
    group.add(rect)
    rect.show()

    # Add a label to the group
    label = clutter.Text("Sans 9", "Some Text", actor_color)
    label.set_position(0, 60)
    group.add(label)
    label.show()

    # Scale the group 120% along the x axis
    group.set_scale(3.0, 1.0)

    # Rotate it around the z axis
    group.set_rotation(clutter.Z_AXIS, 10, 0, 0, 0)

    # Show the stage
    stage.connect("destroy", clutter.main_quit)
    stage.show_all()

    # Start the main loop, so we can respond to events
    clutter.main()
Ejemplo n.º 24
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    label_color = clutter.Color(255, 255, 255, 153)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Connect signal handlers to handle mouse clicks on the stage
    stage.connect('button-press-event', on_stage_button_press)

    # Add a rectangle to the stage
    rect = clutter.Rectangle(label_color)
    rect.set_size(100, 100)
    rect.set_position(50, 50)
    rect.show()
    stage.add(rect)

    # Allow the actor to emit events.
    # By default only the stage does this.
    rect.set_reactive(True)

    # Connect signal handlers for events
    rect.connect('button-press-event', on_rect_button_press)
    rect.connect('button-release-event', on_rect_button_release)
    rect.connect('motion-event', on_rect_motion)
    rect.connect('enter-event', on_rect_enter)
    rect.connect('leave-event', on_rect_leave)

    # Show the stage
    stage.connect('destroy', clutter.main_quit)
    stage.show()

    # Start the main loop, so we can respond to events
    clutter.main()

    return 0
Ejemplo n.º 25
0
    def __init__(self, x=0, y=0, item_width=0.2, item_height=0.1):
        GridMenu.__init__(self, x, y, item_width, item_height)

        self.cursor_below = False
        self.horizontal = True
        self.items_per_col = 4
        self.visible_rows = 3
        self.visible_cols = 5

        c = clutter.Rectangle()
        c.set_size(100, 100)
        c.set_color((255, 255, 255, 128))
        self.cursor = c

        pix_buffer = gtk.gdk.pixbuf_new_from_file(
            self.config.theme.getImage("default_movie_art"))
        self.movie_default = RoundedTexture(0.0, 0.0, 0.1, 0.25, pix_buffer)
        self.movie_default.hide()
        self.add(self.movie_default)

        self.album_default = Texture(
            self.config.theme.getImage("default_album_art"))
        self.album_default.hide()
        self.add(self.album_default)
Ejemplo n.º 26
0
def main():
    stage_color = clutter.Color(0, 0, 0, 255)
    rect_color = clutter.Color(255, 255, 255, 153)

    # Get the stage and set its size and color
    stage = clutter.Stage()
    stage.set_size(200, 200)
    stage.set_color(stage_color)

    # Add a rectangle to the stage
    rect = clutter.Rectangle(rect_color)
    rect.set_size(40, 40)
    rect.set_position(10, 10)
    stage.add(rect)
    rect.show()

    # Show the stage
    stage.connect('destroy', clutter.main_quit)
    stage.show()

    timeline = clutter.Timeline(5000) # milliseconds
    timeline.set_loop(True)
    timeline.start()

    # Instead of our custom callback,
    # we could use a standard callback. For instance, CLUTTER_ALPHA_SINE_INC.
    alpha = clutter.Alpha(timeline)
    alpha.set_func(on_alpha, None)

    behaviour = clutter.BehaviourPath(alpha, knots=((10, 10), (150, 150)))
    behaviour.apply(rect)

    # Start the main loop, so we can respond to events
    clutter.main()

    return 0
Ejemplo n.º 27
0
    def on_key_press(stage, event, box):
        from clutter import keysyms
        if event.keyval == keysyms.h:
            for child in box:
                do_allocate = box.child_get_property(child, 'allocate-hidden')
                box.child_set_property(child, 'allocate-hidden',
                                       not do_allocate)
            box.queue_relayout()

    import random
    stage = clutter.Stage()
    stage.connect('destroy', clutter.main_quit)

    box = SampleBox()
    for i in range(10):
        rect = clutter.Rectangle()
        color = clutter.Color(random.randint(0, 255), random.randint(0, 255),
                              random.randint(0, 255), 255)
        rect.set_color(color)
        rect.set_size(50, 50)
        rect.set_reactive(True)
        rect.connect('button-press-event', on_child_button_pressed)
        box.add(rect)
        box.child_set_property(rect, 'allocate-hidden', False)
        if i % 2:
            rect.hide()

    stage.add(box)
    box.set_reactive(True)

    info = clutter.Text()
Ejemplo n.º 28
0
    def __init__(self):
        if len(sys.argv) != 2:  #TODO: move to ... or remove
            raise SystemExit("Usage: python main.py <image file>")

        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        self.window.connect("delete-event", self.delete_event)
        self.window.connect("destroy", self.destroy)

        # Sets the border width of the window.
        self.window.set_title('BNF Viewer')
        self.window.set_border_width(10)
        #self.window.set_size_request(200,100)
        self.window.set_default_size(640, 400)

        self.vbox = gtk.VBox()  #False, 0
        #self.box1.pack_start(self.button1, True, True, 0)

        self.toolbar = gtk.Toolbar()
        self.toolbar.set_style(gtk.TOOLBAR_TEXT)

        self.toolbar.append_item('Rules', 'Show Rules', 'private text', None,
                                 self.on_button_clicked)
        self.toolbar.append_space()

        self.vbox.add(self.toolbar)

        self.table = gtk.Table(2, 2, False)

        self.clutter_widget = cluttergtk.Embed()
        self.clutter_widget.set_size_request(200, 200)

        self.table.attach(self.clutter_widget, 0, 1, 0, 1,
                          gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0)

        self.vbox.add(
            self.table)  # pack_end(self.clutter_widget, True, True, 0)

        self.stage_color = clutter.Color(0, 0, 0, 255)  # Black
        self.actor_color = clutter.Color(255, 255, 255, 153)

        self.stage = self.clutter_widget.get_stage()
        self.stage.set_color(self.stage_color)
        self.stage.set_size(640, 480)

        # Create a viewport actor to be able to scroll actor. By passing NULL it
        # will create new GtkAdjustments
        self.viewport = cluttergtk.Viewport()
        self.stage.add(self.viewport)
        self.viewport.set_size(640, 480)

        # Load image from first command line argument and add it to viewport
        self.texture = clutter.Texture(sys.argv[1])
        self.viewport_group = clutter.Group()

        self.viewport_group.add(self.texture)
        self.viewport.add(self.viewport_group)

        self.texture.set_position(0, 0)

        # Create scrollbars and connect them to viewport
        self.h_adjustment, self.v_adjustment = self.viewport.get_adjustments()
        self.scrollbar = gtk.VScrollbar(self.v_adjustment)
        self.table.attach(self.scrollbar, 1, 2, 0, 1, 0, gtk.EXPAND | gtk.FILL,
                          0, 0)

        self.scrollbar = gtk.HScrollbar(self.h_adjustment)
        self.table.attach(self.scrollbar, 0, 1, 1, 2, gtk.EXPAND | gtk.FILL, 0,
                          0, 0)

        # Connect a signal handler to handle mouse clicks and key presses on the stage
        self.stage.connect("button-press-event", self.on_stage_button_pressed)

        # Add a group to the stage
        self.group = clutter.Group()
        self.group.set_position(40, 40)
        self.viewport_group.add(self.group)

        # Add a rectangle to the stage
        self.rect = clutter.Rectangle(self.actor_color)
        self.rect.set_size(100, 400)
        self.rect.set_position(20, 20)
        self.group.add(self.rect)
        #self.rect.show()

        # Add a label to the stage
        self.label = clutter.Text("Sans 12", "Some Text", self.actor_color)
        self.label.set_size(500, 500)
        self.label.set_position(20, 15)
        self.group.add(self.label)
        #label.show()

        # This packs the button into the window (which is a container).
        self.window.add(self.vbox)

        # Show the window and the button
        self.window.show_all()
Ejemplo n.º 29
0
                cogl.rectangle(box.x1, box.y1, box.x2, box.y2)
            child.paint()


def on_key_group_activate(key_group, child):
    print "Child %s activated!" % child


if __name__ == '__main__':
    stage = clutter.Stage()
    stage.connect('destroy', clutter.main_quit)

    key_group = KeyGroup()
    stage.add(key_group)

    rect = clutter.Rectangle(clutter.color_from_string('red'))
    rect.set_size(50, 50)
    rect.set_position(0, 0)
    key_group.add(rect)

    rect = clutter.Rectangle(clutter.color_from_string('green'))
    rect.set_size(50, 50)
    rect.set_position(75, 0)
    key_group.add(rect)

    rect = clutter.Rectangle(clutter.color_from_string('blue'))
    rect.set_size(50, 50)
    rect.set_position(150, 0)
    key_group.add(rect)

    key_group.set_position(stage.get_width() / 2 - key_group.get_width() / 2,
Ejemplo n.º 30
0
    def __init__(self, x=0, y=0, item_width=0.2, item_height=0.1):
        Base.__init__(self)
        clutter.Group.__init__(self)

        self.motion_duration = 100  # Default duration of animations ms.
        self.cursor_below = True  # Is the cursor below items?
        self._active = None
        self._is_vertical = True
        self.items = []

        # Items dimensions variable: relative, absolute, center
        self._item_width = item_width
        self._item_height = item_height
        self._item_width_abs = self.get_abs_x(item_width)
        self._item_height_abs = self.get_abs_y(item_height)
        self._dx = int(self._item_width_abs / 2)
        self._dy = int(self._item_height_abs / 2)

        # Default cursor's index.
        self._selected_index = 0

        # Grid dimensions: real, visible.
        self.items_per_row = 10
        self.items_per_col = 10
        self._visible_rows = 3
        self._visible_cols = 5

        # The moving_group is a Clutter group containing all the items.
        self._moving_group_x = 0
        self._moving_group_y = 0
        self._moving_group = clutter.Group()
        self.add(self._moving_group)

        # The moving_group is translated using a `BehaviourPath`.
        self._moving_group_timeline = clutter.Timeline(200)
        moving_group_alpha = clutter.Alpha(self._moving_group_timeline,
                                           clutter.EASE_IN_OUT_SINE)
        moving_group_path = clutter.Path()
        self._moving_group_behaviour = clutter.BehaviourPath(
            moving_group_alpha, moving_group_path)
        self._moving_group_behaviour.apply(self._moving_group)

        # The cursor is an Actor that can be added and moved on the menu.
        # The cusor is always located in the visible (clipped) area of the menu.
        self._cursor_x = 0
        self._cursor_y = 0
        self._cursor = None
        self._cursor_timeline = clutter.Timeline(200)
        cursor_alpha = clutter.Alpha(self._cursor_timeline,
                                     clutter.EASE_IN_SINE)
        cursor_path = clutter.Path()
        self._cursor_behaviour = clutter.BehaviourPath(cursor_alpha,
                                                       cursor_path)

        # A MotionBuffer is used to compute useful information about the
        # cursor's motion. It's used when moving the cursor with a pointer.
        self._motion_buffer = MotionBuffer()
        self._event_mode = self.MODE_NONE
        self._motion_handler = 0
        self._seek_step_x = 0
        self._seek_step_y = 0
        gobject.timeout_add(200, self._internal_timer_callback)

        #XXX: Samuel Buffet
        # This rectangle is used to grab events as it turns out that their
        # might be a bug in clutter 0.8 or python-clutter 0.8.
        # It may be avoided with next release of clutter.
        self._event_rect = clutter.Rectangle()
        self._event_rect.set_opacity(0)
        self.add(self._event_rect)
        self._event_rect.set_reactive(True)
        self._event_rect.connect('button-press-event',
                                 self._on_button_press_event)
        self._event_rect.connect('button-release-event',
                                 self._on_button_release_event)
        self._event_rect.connect('scroll-event', self._on_scroll_event)

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