Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import sys
import gi
gi.require_version('Clutter', '1.0')
gi.require_version('Gtk', '3.0')
gi.require_version('GtkClutter', '1.0')
from gi.repository import Clutter # isort:skip
from gi.repository import Gtk # isort:skip
from gi.repository import GtkClutter # isort:skip
def main():
# Clutter.init(sys.argv[1:])
GtkClutter.init([])
window = Gtk.Window()
window.resize(200,200)
embed = GtkClutter.Embed(
width_request=200,
height_request=200,
)
window.add(embed)
red = Clutter.Actor(
x=0, y=0,
width=200, height=200,
background_color=Clutter.color_from_string('red')[1]
)
green = Clutter.Actor(
x=200, y=0,
width=200, height=200,
background_color=Clutter.color_from_string('green')[1]
)
blue = Clutter.Actor(
x=0, y=200,
width=200, height=200,
background_color=Clutter.color_from_string('blue')[1]
)
yellow = Clutter.Actor(
x=200, y=200,
width=200, height=200,
background_color=Clutter.color_from_string('yellow')[1]
)
container = Clutter.Actor(
x=-100, y=-100,
width=400, height=400
)
container.save_easing_state()
container.set_easing_mode(Clutter.AnimationMode.EASE_IN_OUT_CUBIC)
container.set_easing_duration(400)
for rect in (red,green,blue,yellow):
container.add_child(rect)
# stage = Clutter.Stage(width=200, height=200)
stage = embed.get_stage()
stage.add_child(container)
def on_key_press(stage, event):
if event.keyval == Clutter.Up:
container.set_y(0)
elif event.keyval == Clutter.Down:
container.set_y(-200)
elif event.keyval == Clutter.Left:
container.set_x(0)
elif event.keyval == Clutter.Right:
container.set_x(-200)
return True
stage.connect('key-press-event', on_key_press)
# stage.connect('destroy', lambda *args: Clutter.main_quit())
# stage.show()
# Clutter.main()
window.connect('delete-event', Gtk.main_quit)
window.show_all()
Gtk.main()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment