示例#1
0
	def __init__(self):
		super(ClutterScope, self).__init__()
		self.graticule = Graticule()
		self.add_actor(self.graticule)
		#self.set_reactive(True)

		self.traces = []

		layout = Clutter.BoxLayout()
		layout.set_vertical(False)
		layout.set_use_animations(True)
		layout.set_easing_duration(100)
		layout.set_spacing(4)
		label_box = Clutter.Box()
		label_box.set_layout_manager(layout)
		self.add_actor(label_box)
		label_box.set_position(0, 0)
		constraint = Clutter.BindConstraint()
		constraint.set_coordinate(Clutter.BindCoordinate.WIDTH)
		label_box.add_constraint(constraint)

		# Add some traces (just for looks)
		tr = Trace()
		tr.set_position(0, -50)
		self.graticule.add_actor(tr)
		self.traces += [tr]
		label_box.add_actor(TraceLabel(tr))
		tr.set_name('H1:DMT-STRAIN')

		tr = Trace()
		tr.set_color(color_from_string('magenta'))
		self.graticule.add_actor(tr)
		self.traces += [tr]
		label_box.add_actor(TraceLabel(tr))
		tr.set_name('L1:DMT-STRAIN')

		tr = Trace()
		tr.set_color(color_from_string('yellow'))
		tr.set_position(0, 50)
		self.graticule.add_actor(tr)
		self.traces += [tr]
		label_box.add_actor(TraceLabel(tr))
		tr.set_name('A1:DMT-STRAIN')

		# State for event signal handlers
		self.selected_trace = self.traces[0]
		self.__last_scroll_time = 0
		self.__drag_origin = None
示例#2
0
def create_scroll_actor(stage):
    scroll = Clutter.ScrollActor(name='scroll')
    scroll.set_position(0, 18)
    scroll.add_constraint(
        Clutter.AlignConstraint(source=stage,
                                align_axis=Clutter.AlignAxis.X_AXIS,
                                factor=0.5))
    scroll.add_constraint(
        Clutter.BindConstraint(source=stage,
                               coordinate=Clutter.BindCoordinate.HEIGHT,
                               offset=-36))
    scroll.set_scroll_mode(Clutter.ScrollMode.VERTICALLY)
    scroll.set_easing_duration(250)
    scroll.add_child(create_menu_actor())

    stage.add_child(scroll)
    def __init__(self, **kw):
        kw.setdefault("layout-manager", Clutter.BinLayout())
        super(PhotosImageWidget, self).__init__(**kw)
        self._ratio = 1.0

        self._base_image = Clutter.Texture()
        self.add_child(self._base_image)
        self._border_image = Clutter.Texture()
        self.add_child(self._border_image)

        self._crop_overlay = CropOverlay()
        self.add_child(self._crop_overlay)
        self._crop_overlay.hide_crop_overlay()
        self.crop_overlay_visible = False

        bind_overlay_size = Clutter.BindConstraint(
            coordinate=Clutter.BindCoordinate.SIZE, source=self._base_image)
        self._crop_overlay.add_constraint(bind_overlay_size)

        self.connect('allocation-changed', self.alloc_changed)
示例#4
0
	def __init__(self):
		super(Graticule, self).__init__()
		self.__constraints = []

		constraint = Clutter.AlignConstraint()
		constraint.set_factor(0.5)
		constraint.set_align_axis(Clutter.AlignAxis.X_AXIS)
		self.__constraints += [constraint]

		constraint = Clutter.AlignConstraint()
		constraint.set_align_axis(Clutter.AlignAxis.Y_AXIS)
		constraint.set_factor(0.5)
		self.__constraints += [constraint]

		constraint = Clutter.BindConstraint()
		constraint.set_coordinate(Clutter.BindCoordinate.SIZE)
		self.__constraints += [constraint]

		for constraint in self.__constraints:
			self.add_constraint(constraint)

		self.connect('paint', self.paint)
示例#5
0
    return False


if __name__ == '__main__':
    Clutter.init(None)

    stage = Clutter.Stage(title='Actor Model', user_resizable=True)
    stage.connect('destroy', Clutter.main_quit)
    stage.connect('key-press-event', on_key_press_event)
    stage.show()

    scroll = Clutter.ScrollActor(name='scroll')
    scroll.set_position(0, 18)
    scroll.add_constraint(
        Clutter.AlignConstraint(source=stage,
                                align_axis=Clutter.AlignAxis.X_AXIS,
                                factor=0.5))
    scroll.add_constraint(
        Clutter.BindConstraint(source=stage,
                               coordinate=Clutter.BindCoordinate.HEIGHT,
                               offset=-36))
    scroll.set_scroll_mode(Clutter.ScrollMode.VERTICALLY)
    scroll.set_easing_duration(250)
    stage.add_child(scroll)

    menu = Menu()
    scroll.add_child(menu)
    menu.populate()

    Clutter.main()
示例#6
0
    # First actor, with a fixed (100, 25) size
    layer_a = Clutter.Actor()
    layer_a.props.background_color = Clutter.Color.get_static(Clutter.StaticColor.SCARLET_RED)
    layer_a.set_size(100, 25)
    stage.add_child(layer_a)

    # The first actor is anchored to the center of the stage
    layer_a.add_constraint(Clutter.AlignConstraint(source=stage, align_axis=Clutter.AlignAxis.BOTH, factor=0.5))

    # Second actor, with no explicit size
    layer_b = Clutter.Actor()
    layer_b.props.background_color = Clutter.Color.get_static(Clutter.StaticColor.BUTTER_DARK)
    stage.add_child(layer_b)

    # The second actor tracks the X coordinate and the width of the first actor
    layer_b.add_constraint(Clutter.BindConstraint(source=layer_a, coordinate=Clutter.BindCoordinate.X))
    layer_b.add_constraint(Clutter.BindConstraint(source=layer_a, coordinate=Clutter.BindCoordinate.WIDTH))

    # The second actor is snapped between the bottom edge of the first actor
    # and the bottom edge of the stage; vertical spacing of 10px is added for
    # padding
    layer_b.add_constraint(Clutter.SnapConstraint(source=layer_a,
                                                  from_edge=Clutter.SnapEdge.TOP,
                                                  to_edge=Clutter.SnapEdge.BOTTOM,
                                                  offset=10))
    layer_b.add_constraint(Clutter.SnapConstraint(source=stage,
                                                  from_edge=Clutter.SnapEdge.BOTTOM,
                                                  to_edge=Clutter.SnapEdge.BOTTOM,
                                                  offset=-10))

    # The third actor, again with no explicit size
示例#7
0
    if resize_id == 0:
        resize_id = GLib.timeout_add(500, idle_resize, actor)

if __name__ == '__main__':
    Clutter.init(None)

    # Our stage
    stage = Clutter.Stage(title='2D Clock', user_resizable=True)
    stage.props.background_color = Clutter.Color.get_static(Clutter.StaticColor.SKY_BLUE_LIGHT)
    stage.set_size(300, 300)
    stage.connect('destroy', Clutter.main_quit)
    stage.show()

    # The canvas, courtesy of Cairo
    canvas = Clutter.Canvas(width=300, height=300)
    canvas.connect('draw', draw_clock)
    canvas.invalidate()

    # The actor that displays the canvas
    actor = Clutter.Actor(content=canvas)
    actor.set_content_scaling_filters(Clutter.ScalingFilter.TRILINEAR,
                                      Clutter.ScalingFilter.LINEAR)
    actor.add_constraint(Clutter.BindConstraint(source=stage, coordinate=Clutter.BindCoordinate.SIZE))
    actor.connect('allocation-changed', on_actor_resize)
    stage.add_child(actor)

    # Set up a timeout that invalidates the contents of the canvas every second
    GLib.timeout_add(1000, invalidate_clock, canvas)

    Clutter.main()
示例#8
0
		Cogl.set_source_color(cogl_color_from_clutter_color(color))
		Cogl.path_round_rectangle(3, 3, w - 3, h - 3, 3, 10)
		Cogl.path_fill()


# Initialize Clutter
Clutter.init(sys.argv)

# Disable font mipmapping (see <http://bugzilla.clutter-project.org/show_bug.cgi?id=2584>)
Clutter.set_font_flags(0)

# Set up stage.
stage = Clutter.Stage.get_default()
stage.set_size(576, 576)
stage.set_user_resizable(True)
stage.connect('destroy', lambda *args: Clutter.main_quit())

scope = ClutterScope()
stage.add_actor(scope)
scope.set_reactive(True)
constraint = Clutter.BindConstraint()
constraint.set_coordinate(Clutter.BindCoordinate.SIZE | Clutter.BindCoordinate.POSITION)
constraint.set_source(stage)
scope.add_constraint(constraint)

# Show everything.
stage.show_all()

# Start main loop.
Clutter.main()
示例#9
0
    def init_draggable_handles(self):
        # Setup the four handles on the cropbox's corners. These are inset into the corners
        # of the cropbox, and don't actually spill over onto the image stage; the illusion
        # of their outward-facing corners overlapping the stage is made by offsetting the
        # opaque squares slightly onto the cropbox
        handles = []
        coordinates = [TOP | LEFT, TOP | RIGHT, BOT | LEFT, BOT | RIGHT]

        for coordinate in coordinates:
            handle = DraggableHandle(self, coordinate)

            # Each handle has four constraints:
            #   horiz_constraint: binds the handle to the cropbox's top/bottom sides
            #   vert_constraint: binds the handle to the cropbox's left/right sides
            #   width_constraint: binds the handle such that its width stays constant
            #   height_constraint: binds the handle such that its height stays constant
            #
            # The height/width constraints are set by binding the opposite side of the handle
            # that horiz/vert constraints bind (respectively) to the same edge of the cropbox,
            # and setting an offset equal to the desired height/width. The handle's hitbox is
            # constrainted by position to the handle image

            horiz_constraint = Clutter.SnapConstraint()
            horiz_constraint.set_source(self)
            vert_constraint = Clutter.SnapConstraint()
            vert_constraint.set_source(self)

            height_constraint = Clutter.SnapConstraint()
            height_constraint.set_source(self)
            width_constraint = Clutter.SnapConstraint()
            width_constraint.set_source(self)

            hitbox_pos_constraint = Clutter.BindConstraint()
            hitbox_pos_constraint.set_source(handle.current_knob)
            hitbox_pos_constraint.set_offset(4)
            hitbox_pos_constraint.set_coordinate(
                Clutter.BindCoordinate.POSITION)

            offset = handle.get_offset()
            if coordinate & TOP:
                horiz_constraint.set_edges(CLUTTER_EDGES[TOP],
                                           CLUTTER_EDGES[TOP])
                height_constraint.set_edges(CLUTTER_EDGES[BOT],
                                            CLUTTER_EDGES[TOP])
                horiz_constraint.set_offset(BORDER_THICKNESS / 2 - offset)
                height_constraint.set_offset(BORDER_THICKNESS / 2 - offset)
            else:
                horiz_constraint.set_edges(CLUTTER_EDGES[BOT],
                                           CLUTTER_EDGES[BOT])
                height_constraint.set_edges(CLUTTER_EDGES[TOP],
                                            CLUTTER_EDGES[BOT])
                horiz_constraint.set_offset(-(BORDER_THICKNESS / 2 + offset))
                height_constraint.set_offset(-(BORDER_THICKNESS / 2 + offset))

            if coordinate & LEFT:
                vert_constraint.set_edges(CLUTTER_EDGES[LEFT],
                                          CLUTTER_EDGES[LEFT])
                width_constraint.set_edges(CLUTTER_EDGES[RIGHT],
                                           CLUTTER_EDGES[LEFT])
                vert_constraint.set_offset(BORDER_THICKNESS / 2 - offset)
                width_constraint.set_offset(BORDER_THICKNESS / 2 - offset)
            else:
                vert_constraint.set_edges(CLUTTER_EDGES[RIGHT],
                                          CLUTTER_EDGES[RIGHT])
                width_constraint.set_edges(CLUTTER_EDGES[LEFT],
                                           CLUTTER_EDGES[RIGHT])
                vert_constraint.set_offset(-(BORDER_THICKNESS / 2 + offset))
                width_constraint.set_offset(-(BORDER_THICKNESS / 2 + offset))

            handle.add_constraint(height_constraint)
            handle.add_constraint(width_constraint)
            handle.add_constraint(horiz_constraint)
            handle.add_constraint(vert_constraint)
            handle.hitbox.add_constraint(hitbox_pos_constraint)

            handles.append(handle)

        return handles
示例#10
0
    def init_draggable_borders(self):
        # Setup the borders which lay between the draggable handles
        borders = []
        coordinates = [TOP, BOT, LEFT, RIGHT]

        for coordinate in coordinates:
            border_wrapper = DraggableBorder(self, coordinate)
            border = border_wrapper.line
            border_hitbox = border_wrapper.hitbox

            # Each border has four constraints:
            #   cropbox_edge_constraint: binds the border's x/y position to the respective edge
            #       of the cropbox
            #   thickness_constraint: binds the height/width of the border to the same edge, in
            #       order to maintain a constant thickness
            #   length_constraint (1 & 2): these two bind the two loose ends of the border to the
            #       cropbox's corners
            # Its hitbox is constrained in the same fashion as its length_constraints, but also has
            # a positional constraint to the border
            cropbox_edge_constraint = Clutter.SnapConstraint()
            cropbox_edge_constraint.set_source(self)
            thickness_constraint = Clutter.SnapConstraint()
            thickness_constraint.set_source(self)

            wrapper_constraint_1 = Clutter.SnapConstraint()
            wrapper_constraint_1.set_source(self)
            wrapper_constraint_2 = Clutter.SnapConstraint()
            wrapper_constraint_2.set_source(self)
            wrapper_pos_constraint = Clutter.BindConstraint()
            wrapper_pos_constraint.set_source(border)
            length_constraint_1 = Clutter.SnapConstraint()
            length_constraint_1.set_source(self)
            length_constraint_2 = Clutter.SnapConstraint()
            length_constraint_2.set_source(self)

            if coordinate & TOP or coordinate & LEFT:
                thickness_offset = border_wrapper.get_offset()
            else:
                thickness_offset = -border_wrapper.get_offset()

            cropbox_edge_constraint.set_edges(CLUTTER_EDGES[coordinate],
                                              CLUTTER_EDGES[coordinate])

            thickness_constraint.set_edges(
                CLUTTER_EDGES[self.opposing_side(coordinate)],
                CLUTTER_EDGES[coordinate])
            thickness_constraint.set_offset(thickness_offset)

            wrapper_pos_constraint.set_coordinate(
                Clutter.BindCoordinate.POSITION)
            wrapper_pos_constraint.set_offset(-MARGIN / 2)

            if coordinate & TOP or coordinate & BOT:
                length_constraint_1.set_edges(CLUTTER_EDGES[LEFT],
                                              CLUTTER_EDGES[LEFT])
                length_constraint_2.set_edges(CLUTTER_EDGES[RIGHT],
                                              CLUTTER_EDGES[RIGHT])
                wrapper_constraint_1.set_edges(CLUTTER_EDGES[LEFT],
                                               CLUTTER_EDGES[LEFT])
                wrapper_constraint_2.set_edges(CLUTTER_EDGES[RIGHT],
                                               CLUTTER_EDGES[RIGHT])
                border_hitbox.set_height(MARGIN)
            else:
                length_constraint_1.set_edges(CLUTTER_EDGES[TOP],
                                              CLUTTER_EDGES[TOP])
                length_constraint_2.set_edges(CLUTTER_EDGES[BOT],
                                              CLUTTER_EDGES[BOT])
                wrapper_constraint_1.set_edges(CLUTTER_EDGES[TOP],
                                               CLUTTER_EDGES[TOP])
                wrapper_constraint_2.set_edges(CLUTTER_EDGES[BOT],
                                               CLUTTER_EDGES[BOT])
                border_hitbox.set_width(MARGIN)

            border.add_constraint(cropbox_edge_constraint)
            border.add_constraint(thickness_constraint)
            border.add_constraint(length_constraint_1)
            border.add_constraint(length_constraint_2)
            border_hitbox.add_constraint(wrapper_constraint_1)
            border_hitbox.add_constraint(wrapper_constraint_2)
            border_hitbox.add_constraint(wrapper_pos_constraint)

            borders.append(border_wrapper)

        return borders