Ejemplo n.º 1
0
    def __init__(self, ui, num_tabs):
        self.ui = ui
        self.num_tabs = num_tabs
        self.duration = 1000
        self.tgs = [None] * num_tabs
        self.current_side = 0
        self.sides = [None] * num_tabs
        self.selected_callbacks = [None] * num_tabs
        self.appear_callbacks = [None] * num_tabs

        self.box = self.ui.get_object("box")

        for i in range(self.num_tabs):
            self.sides[i] = self.ui.get_object("side" + str(i))
            btn_prev = self.ui.get_object("side" + str(i) + "-btn-prev")
            tap_prev = Clutter.TapAction()
            btn_prev.add_action(tap_prev)
            tap_prev.connect("tap", self.btn_prev)

            btn_next = self.ui.get_object("side" + str(i) + "-btn-next")
            tap_next = Clutter.TapAction()
            btn_next.add_action(tap_next)
            tap_next.connect("tap", self.btn_next)

            t = Clutter.PropertyTransition(property_name='rotation-angle-y')
            t.set_from(i * -90)
            t.set_to(i * -90 - 90)
            t.add_marker("appear", 0.5)
            t.connect("marker-reached::appear", self.appear)
            t.connect("completed", self.completed)
            t.set_duration(self.duration)
            t.set_animatable(self.box)
            t.set_progress_mode(Clutter.AnimationMode.EASE_IN_OUT_CUBIC)
            self.tgs[i] = t

        btn_next = self.ui.get_object("side5-btn-next")
        tap_next = Clutter.TapAction()
        btn_next.add_action(tap_next)
        tap_next.connect("tap", self.btn_next)

        btn_next = self.ui.get_object("side5-btn-prev")
        tap_next = Clutter.TapAction()
        btn_next.add_action(tap_next)
        tap_next.connect("tap", self.btn_prev)

        self.tg = self.tgs[0]

        # Set up page 0 to page 2 transition
        self.t2 = Clutter.PropertyTransition(property_name='rotation-angle-y')
        self.t2.set_from(0)
        self.t2.set_to(180)
        self.t2.add_marker("appear", 0.5)
        self.t2.connect("marker-reached::appear", self.appear)
        self.t2.connect("completed", self.intro_completed)
        self.t2.set_duration(self.duration)
        self.t2.set_animatable(self.box)
        self.t2.set_progress_mode(Clutter.AnimationMode.EASE_IN_OUT_CUBIC)

        self.preload = Clutter.Timeline.new(500)
        self.preload.connect("completed", self.preload_complete)
Ejemplo n.º 2
0
    def __init__(self):
        Clutter.Text.__init__(self)

        self._selected = False

        self.props.font_name = 'Sans Bold 24px'
        self.props.color = Clutter.Color.get_static(Clutter.StaticColor.WHITE)
        self.props.margin_left = 12
        self.props.margin_right = 12

        self.set_pivot_point(0.5, 0.5)

        group = Clutter.TransitionGroup(
            duration=250, progress_mode=Clutter.AnimationMode.EASE_OUT)

        trans = Clutter.PropertyTransition(property_name='scale-x')
        trans.set_from(1.0)
        trans.set_to(3.0)
        group.add_transition(trans)

        trans = Clutter.PropertyTransition(property_name='scale-y')
        trans.set_from(1.0)
        trans.set_to(3.0)
        group.add_transition(trans)

        trans = Clutter.PropertyTransition(property_name='opacity')
        trans.set_from(255)
        trans.set_to(0)
        group.add_transition(trans)

        self.add_transition('activateTransition', group)
        group.stop()

        self.connect('transition-stopped', self._on_transition_stopped)
Ejemplo n.º 3
0
    def __init__(self, image, target, size=BUTTONSIZE):
        """Initialize the class."""

        Clutter.Texture.__init__(self)

        width, height = getNewSize(size, size)
        self.set_size(width, height)

        icon = icontheme.lookup_icon(image, width,
                                     Gtk.IconLookupFlags.USE_BUILTIN)
        if icon:
            print icon.get_filename(), width
            self.set_from_file(icon.get_filename())

        self.set_reactive(True)
        self.connect("button-press-event", self.on_click, target)

        # Create transition
        self.transition = Clutter.PropertyTransition()
        self.transition.set_progress_mode(
            Clutter.AnimationMode.EASE_OUT_BOUNCE)
        self.transition.set_duration(5000)
        self.transition.set_from(100.0)
        self.transition.set_to(50.0)
        self.transition.set_animatable(self)

        self.transition.start()
    def __init__(self):
        self.stage = Clutter.Stage()
        self.stage.set_title('Clutter example')
        self.stage.set_background_color(Clutter.color_from_string('#BBB')[1])
        self.stage.set_size(300.0, 300.0)

        self.actor = Clutter.Actor()
        self.actor.set_background_color(
            Clutter.color_from_string('#DA0060')[1])
        self.actor.set_position(75.0, 75.0)
        self.actor.set_size(150.0, 150.0)
        self.actor.set_pivot_point(0.5, 0.5)

        self.rotation = Clutter.PropertyTransition(
            property_name='rotation-angle-z')
        self.rotation.set_animatable(self.actor)
        self.rotation.set_duration(5000)
        self.rotation.set_from(0.0)
        self.rotation.set_to(360.0)
        self.rotation.set_repeat_count(-1)
        self.rotation.start()

        text = Clutter.Text.new_full('Arial Black 12', 'Click me!',
                                     Clutter.color_from_string('black')[1])
        self.actor.add_child(text)

        self.stage.add_child(self.actor)
        self.stage.show()
        self.actor.set_reactive(True)

        self.stage.set_user_resizable(True)
        self.actor.connect('button-press-event', self.color_actor)
        self.stage.connect('key-press-event', self.on_key_press)
        self.stage.connect('destroy', lambda *_: Clutter.main_quit())
Ejemplo n.º 5
0
  def __init__(self, ui, num_tabs):
    self.ui = ui
    self.num_tabs = num_tabs
    self.duration = 1000
    self.tgs = [None] * 4
    self.current_side = 0
    self.sides = [None] * 4

    self.box = self.ui.get_object("box")

    for i in range(self.num_tabs):
      self.sides[i] = self.ui.get_object("side" + str(i))
      btn_prev = self.ui.get_object("side" + str(i) + "-btn-prev")
      btn_prev.connect("clicked", self.btn_prev)
      btn_next = self.ui.get_object("side" + str(i) + "-btn-next")
      btn_next.connect("clicked", self.btn_next)

      t = Clutter.PropertyTransition(property_name='rotation-angle-y')
      t.set_from(i * -90)
      t.set_to(i * -90 - 90)
      t.add_marker("appear", 0.5)
      t.connect("marker-reached::appear", self.appear)
      t.connect("completed", self.completed)
      t.set_duration(self.duration)
      t.set_animatable(self.ui.get_object("box"))
      t.set_progress_mode(Clutter.AnimationMode.EASE_IN_OUT_CUBIC)
      self.tgs[i] = t

    self.tg = self.tgs[0]
Ejemplo n.º 6
0
    def __init__(self):
        Clutter.init(None)
        ui = Clutter.Script()
        ui.load_from_file("ui-threads.json")
        stage = ui.get_object("stage")
        stage.connect("destroy", self.stop)
        stage.connect("destroy", lambda w: Clutter.main_quit())

        self.loader = ui.get_object("loader")
        self.loader.set_from_file("style/loading.png")
        self.t = Clutter.PropertyTransition(property_name='rotation-angle-z')
        self.t.set_from(0)
        self.t.set_to(360)
        self.t.set_duration(3000)
        self.t.set_animatable(self.loader)
        self.t.set_repeat_count(-1)
        self.t.start()

        button1 = ui.get_object("button1")
        button1.connect("button-press-event", self.execute_in_main)
        button1.set_reactive(True)

        button2 = ui.get_object("button2")
        button2.connect("button-press-event", self.idle_add_event)
        button2.set_reactive(True)

        button3 = ui.get_object("button3")
        button3.connect("button-press-event", self.threads_idle_add_event)
        button3.set_reactive(True)

        button4 = ui.get_object("button4")
        button4.connect("button-press-event", self.execute_in_thread)
        button4.set_reactive(True)

        stage = ui.get_object("stage")
        stage.set_title("Test threads")
        stage.connect("destroy", self.stop)
        stage.show_all()

        self.events = JoinableQueue(10)

        # UI events needs to happen from within the
        # main thread. This was the only way I found that would do that.
        # It looks weirdm, but it works.
        def execute(event):
            print("Execute " + event + " from " + str(current_thread()))
            for i in range(100):
                hashlib.md5(str(list(range(100000))))
            print("Done executing")

        self.execute = execute
        stage.show()
Ejemplo n.º 7
0
    def __init__(self, config):
        super(Model, self).__init__()

        self.config = config
        self.model = config.ui.get_object("model")
        color_str = config.get("System", "model-color")
        self.color = Clutter.Color.from_string(color_str)[1]
        self.loader = config.ui.get_object("loader")
        self.loader.set_from_file(config.get("System", "loader"))

        self.model_data = Mash.Data()
        self.model.set_data(self.model_data)
        self.v_min = Clutter.Vertex()
        self.v_max = Clutter.Vertex()
        self.depth = 0

        self.t = Clutter.PropertyTransition(property_name='rotation-angle-z')
        self.t.set_from(0)
        self.t.set_to(360)
        self.t.set_duration(3000)
        self.t.set_animatable(self.loader)
        self.t.set_repeat_count(-1)
        self.t.start()

        #Set up the light
        self.light_set = Mash.LightSet()
        vp = config.ui.get_object("volume-viewport")

        # Directional
        self.light_directional = Mash.DirectionalLight()
        self.light_set.add_light(self.light_directional)

        # Point light
        self.light_point = Mash.PointLight()
        self.light_set.add_light(self.light_point)
        
        # Add the model the lights to the volume viewport
        vp.add_child(self.light_directional);
        vp.add_child(self.light_point);

        cm = Cogl.Matrix()
        m = Clutter.matrix_init_from_array(cm, [
             1, 0, 0, 0,
             0, -1, 0, 0,
             0, 0, 1, 0,
             0, 0, 0, 1])
        config.ui.get_object("model-flipper").set_transform(m)

        self.model.connect("show", self.model_loaded)

        self.model.set_light_set(self.light_set)
        self.model.set_color(self.color)
Ejemplo n.º 8
0
    # The actor displaying the canvas content; the actor has the same
    # preferred size as the content, but if it gets allocated more
    # space, the content will be centered inside that allocation
    actor = Clutter.Actor(content=canvas,
                          content_gravity=Clutter.ContentGravity.CENTER,
                          request_mode=Clutter.RequestMode.CONTENT_SIZE)
    actor.set_content_scaling_filters(Clutter.ScalingFilter.TRILINEAR,
                                      Clutter.ScalingFilter.LINEAR)
    actor.set_pivot_point(0.5, 0.5)
    actor.add_constraint(
        Clutter.AlignConstraint(source=stage,
                                align_axis=Clutter.AlignAxis.BOTH,
                                factor=0.5))
    stage.add_child(actor)

    # We use an explicit transition because we want to make it loop
    transition = Clutter.PropertyTransition(property_name='rotation-angle-y',
                                            duration=2000,
                                            repeat_count=-1)
    transition.set_from(0)
    transition.set_to(360)
    actor.add_transition('rotateActor', transition)

    # Connect to the 'draw' signal before invalidating, so that the canvas
    # gets drawn once
    canvas.connect('draw', draw_content)
    canvas.invalidate()

    Clutter.main()
Ejemplo n.º 9
0
    for i in range(N_RECTS):
        color = Clutter.Color.from_hls(360 / N_RECTS * i, 0.5, 0.8)
        color.alpha = 128 + 128 / N_RECTS * i

        rect = Clutter.Actor()
        rect.props.background_color = color
        rect.props.opacity = 0
        rect.props.reactive = True
        rect.set_size(RECT_SIZE, RECT_SIZE)
        rect.set_pivot_point(0.5, 0.5)
        rect.set_easing_duration(250)
        rect.set_easing_mode(Clutter.AnimationMode.EASE_OUT_CUBIC)
        box.add_child(rect)

        transition = Clutter.PropertyTransition(property_name='opacity', duration=250, delay=i*50)
        transition.set_from(0)
        transition.set_to(color.alpha)
        rect.add_transition('fadeIn', transition)

        rect.connect('enter-event', on_enter)
        rect.connect('leave-event', on_leave)

    label = Clutter.Text(text="Press t → Toggle layout\nPress q → Quit")
    label.add_constraint(Clutter.AlignConstraint(source=stage, align_axis=Clutter.AlignAxis.X_AXIS, factor=0.50))
    label.add_constraint(Clutter.AlignConstraint(source=stage, align_axis=Clutter.AlignAxis.Y_AXIS, factor=0.95))
    stage.add_child(label)

    stage.connect('key-press-event', on_key_press, layout)

    Clutter.main()
Ejemplo n.º 10
0
    window.show()

    # The styled GtkClutterEmbed widget
    embed = StyledEmbed()
    # Keep the size of the stage tied to the size of the embedding widget
    embed.props.use_layout_size = True
    window.add(embed)
    embed.show()

    stage = embed.get_stage()

    # A simple rectangle centered on the stage
    rect = StyledButton(window)
    rect.set_pivot_point(0.5, 0.5)
    rect.set_size(100, 100)
    rect.add_constraint(
        Clutter.AlignConstraint(source=stage,
                                align_axis=Clutter.AlignAxis.BOTH,
                                factor=0.5))
    rect.connect('clicked', on_button_clicked)
    stage.add_child(rect)

    transition = Clutter.PropertyTransition(property_name='rotation-angle-y')
    transition.set_duration(2000)
    transition.set_from(0)
    transition.set_to(360)
    transition.set_repeat_count(-1)
    rect.add_transition('spin', transition)

    Gtk.main()