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())
def main(): hello_str = chr_chr = '' x_offset = y_offset = idx = 0 # initialize Clutter Clutter.init(sys.argv) if (len(sys.argv) > 1): hello_str = argv[0] else: hello_str = 'Hello Clutter!' # create a Stage stage = Clutter.Stage() # set the title of the Stage window stage.set_title('Hello, Clutter') # set the background color of the Stage stage_color = Clutter.Color() Clutter.Color.from_string(stage_color, 'DarkSlateGray') stage.set_color(stage_color) # connect the pointer button press and key press event signals stage.connect('button-press-event', on_button_press) stage.connect('key-press-event', on_key_press) stage.connect('destroy', Clutter.main_quit) # set the size of the Stage stage.set_size(800, 600) # then show the Stage stage.show_all()
def default_stage(): import gi gi.require_version('Clutter', '1.0') from gi.repository import Clutter, GLib Clutter.init([]) stage = Clutter.Stage() stage.set_size(800, 500) stage.set_title('Clutter - Cairo content') stage.set_user_resizable(True) return stage
def __init__(self): self.stage = Clutter.Stage() r = Clutter.Texture.new_from_file("test.jpg") r.set_size(640, 480) self.stage.add_actor(r) shader = Clutter.Shader() source = open(__file__.replace(".py", ".glsl"), "r").read() shader.set_fragment_source(source, len(source)) #shader.set_uniform("image", 0) # warning? r.set_shader(shader) self.stage.show()
def create_window(self, argv, descriptor): clutter_window = window.Window(self, Clutter.Stage(), descriptor) clutter_window.stage.set_title('Pisak Main') if arg_parser.get_args().debug: coeff = 0.7 clutter_window.stage.set_size(coeff * unit.w(1), coeff * unit.h(1)) clutter_window.stage.set_user_resizable(True) else: clutter_window.stage.set_size(unit.w(1), unit.h(1)) clutter_window.stage.set_fullscreen(True) clutter_window.stage.connect("destroy", lambda _: Clutter.main_quit()) return clutter_window
def setup_stage(config): stage_color = Clutter.Color.new(0, 0, 0, 0) text_color = Clutter.Color.new(0, 128, 0, 255) Clutter.init(sys.argv) stage = Clutter.Stage() stage.set_title("Speakup") stage.set_use_alpha(True) stage.set_background_color(stage_color) stage.connect("delete-event", stage_on_delete, config) stage.connect("button-press-event", stage_on_button_press, config) layout = Clutter.BoxLayout() layout.set_orientation(Clutter.Orientation.VERTICAL) layout.set_spacing(15) stage.set_layout_manager(layout) old_entries = [] for i in range(15): old_entry = Clutter.Text.new_with_text("Sans 28px", "") old_entry.set_color(Clutter.Color.new(0, 128, 0, (i + 1) * 16)) old_entries.append(old_entry) stage.add_actor(old_entry) old_entries.reverse() entry = Clutter.Text.new_with_text("Sans 28px", "") entry.set_color(text_color) entry.set_editable(True) entry.set_reactive(True) entry.set_single_line_mode(True) entry.set_line_alignment(Pango.Alignment.CENTER) entry.connect("key-press-event", entry_on_key_press, config) stage.add_actor(entry) entry.old_entries = old_entries entry.old_iterator = -1 stage.show() stage.set_fullscreen(True) stage.set_key_focus(entry) stage_window = ClutterGdk.get_stage_window(stage) stage_window.set_keep_above(True) stage_window.set_modal_hint(True) stage_window.set_skip_taskbar_hint(True) stage_window.set_skip_pager_hint(True)
def create_window(self, argv, descriptor): """ Create application main window as the Clutter.Stage. :param: argv: application arguments. :param descriptor: general application descriptor. """ clutter_window = window.Window(self, Clutter.Stage(), descriptor) clutter_window.stage.set_title('PISAK') clutter_window.stage.set_position(unit.MONITOR_X, unit.MONITOR_Y) if arg_parser.get_args().debug: coeff = 0.7 clutter_window.stage.set_size(coeff * unit.w(1), coeff * unit.h(1)) clutter_window.stage.set_user_resizable(True) else: clutter_window.stage.set_size(unit.w(1), unit.h(1)) clutter_window.stage.set_fullscreen(True) clutter_window.stage.connect("destroy", lambda _: Clutter.main_quit()) return clutter_window
def __init__(self, filename): self.stage = Clutter.Stage() self.stage.set_fullscreen(True) # self.stage.set_size(1000, 600) self.stage.set_color(Clutter.Color.new(0x11, 0x11, 0x11, 0xff)) self.stage.set_title('GStreamer Clutter Python - ' + filename) self.stage.connect('key-press-event', self.on_key_press_event) self.stage.connect('destroy', self.on_destroy) self.texture = Clutter.Texture.new() self.texture.connect('size-change', self.on_size_change) self.stage.add_actor(self.texture) self.sink = ClutterGst.VideoSink.new(self.texture) self.sink.set_property('sync', True) self.player = Gst.ElementFactory.make('playbin', None) self.player.set_property('video-sink', self.sink) self.bus = self.player.get_bus() self.bus.add_signal_watch() self.bus.connect('message::eos', self.on_eos) self.bus.connect('message::error', self.on_error) self.stage.show_all() self.player.set_property('uri', 'file://' + filename) self.player.set_state(Gst.State.PLAYING)
def __init__(self): self.stage = Clutter.Stage() self.stage.set_size(400, 400) self.layout_manager = Clutter.BoxLayout() self.textures_box = Clutter.Actor(layout_manager=self.layout_manager) self.stage.add_actor(self.textures_box) self.video_texture = Clutter.Texture.new() self.video_texture.set_keep_aspect_ratio(True) self.video_texture.set_size(400, 400) self.layout_manager.pack(self.video_texture, expand=False, x_fill=False, y_fill=False, x_align=Clutter.BoxAlignment.CENTER, y_align=Clutter.BoxAlignment.CENTER) self.camera = Cheese.Camera.new(self.video_texture, None, 100, 100) Cheese.Camera.setup(self.camera, None) Cheese.Camera.play(self.camera) def added(signal, data): uuid = data.get_uuid() node = data.get_device_node() print "uuid is " + str(uuid) print "node is " + str(node) self.camera.set_device_by_device_node(node) self.camera.switch_camera_device() device_monitor = Cheese.CameraDeviceMonitor.new() device_monitor.connect("added", added) device_monitor.coldplug() self.stage.show() Clutter.main()
def _build_stage(self): self.stage = Clutter.Stage() self.stage.connect("destroy", lambda *args: Clutter.main_quit())
from gi.repository import Clutter if __name__ == '__main__': Clutter.init(None) # The main stage stage = Clutter.Stage(title='Constraints', user_resizable=True) stage.props.background_color = Clutter.Color.get_static(Clutter.StaticColor.ALUMINIUM_1) stage.connect('destroy', Clutter.main_quit) # 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
resize_id = 0 return False def on_actor_resize(actor, allocation, flags): global resize_id # Throttle multiple allocations to a single canvas resize 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))
width=200, height=200, background_color=Clutter.Color.new(255, 255, 0, 255)) container = Clutter.Actor(x=0, y=0, width=400, height=400) container.save_easing_state() container.set_easing_mode(Clutter.AnimationMode.EASE_IN_OUT_CUBIC) container.set_easing_duration(400) for rec in [red, green, blue, yellow]: container.add_child(rec) stage = Clutter.Stage(width=200, height=200) stage.add_child(container) def on_stage_key_press(a, event: Clutter.KeyEvent): key = event.keyval if key == Clutter.KEY_Up: container.props.y = 0 elif key == Clutter.KEY_Down: container.props.y = -200 elif key == Clutter.KEY_Left: container.props.x = 0 elif key == Clutter.KEY_Right: container.props.x = -200 else: return False
def __init__(self, directory): self.space = None self.active_entity = None self.selected_entity = None self.timeout = None self.pantimeout = None self.do_scroll = False self.lastMouseX = 0 self.lastMouseY = 0 self.label = None self.show_tooltip = True self.directory = directory # set up texture cache self.texturemgr = TextureManager(self) # set up stage stage = Clutter.Stage() stage.set_size(*DIMENSIONS) try: background = Clutter.Texture.new_from_file( os.path.join(directory, "background.jpg")) self.background = background self.background.show() stage.add_actor(self.background) except Exception: c = Clutter.Color.get_static(Clutter.StaticColor.DARK_BLUE) stage.set_color(c) self.background = None stage.connect('scroll-event', self.on_zoom_event) stage.connect('button-press-event', self.on_mouse_press_event) stage.connect('button-release-event', self.on_mouse_release_event) stage.connect('motion-event', self.on_motion_event) stage.connect('key-press-event', self.on_key_press_event) stage.connect('fullscreen', self.on_resize) stage.connect('unfullscreen', self.on_resize) stage.connect('delete-event', self.on_quit) self.stage = stage self.stage.show_all() g = glob.glob(os.path.join(directory, "*.pdf")) try: f = open(os.path.join(directory, ".pdf-desktop-config"), "r") camerascale, camerax, cameray, config = pickle.load(f) f.close() existing = set(list(g)) config = filter(lambda (fn, pg, pos, size): fn in existing, config) fns = set([fn for (fn, _, _, _) in config]) for fn in existing - fns: config.append((fn, 0, None, None)) except IOError: camerascale = DEFAULT_SCALE camerax = 0.0 cameray = 0.0 config = [(fn, 0, None, None) for fn in g] # set up camera camera = Camera(stage, camerascale, camerax, cameray) self.camera = camera # set up docs fns = set([fn for (fn, _, _, _) in config]) docs = dict([(fn, Poppler.Document.new_from_file("file://" + fn, None)) for fn in fns]) for (fn, doc) in docs.items(): doc.filename = fn # set up space space = Space(self) for (fn, pg, pos, _) in config: entity = PdfEntity(self, docs[fn], pg) space.add(entity, pos) self.space = space # init requests entities = self.space.get_entities_sorted() requests = defaultdict(lambda: []) for entity, (pos, size) in entities: scales = requests[entity.doc, entity.pagenum] if self.camera.in_bounds( pos[0], pos[1], size[0], size[1] ) and not self.camera.scale in scales and self.camera.scale >= MIN_LOAD_SCALE: requests[entity.doc, entity.pagenum].insert(0, self.camera.scale) if not DEFAULT_SCALE in scales: requests[entity.doc, entity.pagenum].append(DEFAULT_SCALE) requestlist = [] added = set() for entity, _ in entities: if (entity.doc, entity.pagenum) in added: continue for scale in requests[entity.doc, entity.pagenum]: requestlist.append((entity.doc, entity.pagenum, scale)) added.add((entity.doc, entity.pagenum)) self.texturemgr.request_load_textures(requestlist) self.update() if FULLSCREEN: self.stage.set_fullscreen(True)
text.props.text = 'Content Gravity: ' + gravities[current_gravity][1] # Animate the content gravity changes with actor.easing_state(): actor.set_content_gravity(gravities[current_gravity][0]) # Cycle through all gravities current_gravity += 1 if current_gravity >= len(gravities): current_gravity = 0 if __name__ == '__main__': Clutter.init(None) # Our stage stage = Clutter.Stage(title='Content Box', user_resizable=True) stage.set_margin(Clutter.Margin(12)) stage.connect('destroy', Clutter.main_quit) stage.show() # Load the texture data from a file pixbuf = GdkPixbuf.Pixbuf.new_from_file('redhand.png') # Use the correct pixel format depending on whether the image # has an alpha channel pixel_format = Cogl.PixelFormat.RGB_888 if pixbuf.get_has_alpha(): pixel_format = Cogl.PixelFormat.RGBA_8888 data = pixbuf.read_pixel_bytes() width = pixbuf.get_width()
pos = Clutter.Point() (pos.x, pos.y) = item.get_position() scroll.scroll_to_point(pos) return True if key == Clutter.KEY_Return or key == Clutter.KEY_KP_Enter: menu.activate_item() return True 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)
def ret(*args): stage = Clutter.Stage() args = args + (stage, ) function(*args) stage.destroy()
def on_crossing(actor, event): z_pos = 0 if event.type == Clutter.EventType.ENTER: z_pos = -250 with actor.easing_state(500, Clutter.AnimationMode.EASE_OUT_BOUNCE): actor.set_z_position(z_pos) return True if __name__ == '__main__': Clutter.init(None) stage = Clutter.Stage(title="Three Flowers in a Vase") stage.props.user_resizable = True stage.connect('destroy', Clutter.main_quit) vase = Clutter.Actor(name='vase') vase.props.layout_manager = Clutter.BoxLayout() vase.props.background_color = Clutter.Color.get_static( Clutter.StaticColor.SKY_BLUE_LIGHT) vase.add_constraint( Clutter.AlignConstraint(source=stage, align_axis=Clutter.AlignAxis.BOTH, factor=0.5)) stage.add_child(vase) flowers = []
# We're going to "brute-force" the shaders here by setting every possible # parameter, rather than those only needed per each shader. actor.set_shader(shader) actor.set_shader_param_int("tex", 0) actor.set_shader_param_float("brightness", 0.4) actor.set_shader_param_float("contrast", -1.9) actor.set_shader_param_float("radius", 3.0) np2 = lambda n: 2 ** math.ceil(math.log(n, 2)) actor.set_shader_param_float("x_step", 1.0 / np2(actor.get_width())) actor.set_shader_param_float("x_step", 1.0 / np2(actor.get_height())) if __name__ == "__main__": stage = Clutter.Stage() stage.set_title("Shaders") stage.set_color(Clutter.Color.new(0x61, 0x64, 0x8c, 0xff)) stage.set_size(512, 384) stage.connect("destroy", Clutter.main_quit) # Here we create a texture-based actor from the file on disk. # Our actor will toggle through shading on right/left click. Unlike the # normal example, we'll start with the basic redhand to let you see how # things change... actor = Clutter.Texture(filename="../../data/redhand.png") actor.set_position(100, 100) actor.set_reactive(True)
def on_key_press(stage, event): scroll = stage.get_first_child() key = event.keyval if key == Clutter.KEY_q: Clutter.main_quit() return True if key == Clutter.KEY_Up: select_prev_item(scroll) return True if key == Clutter.KEY_Down: select_next_item(scroll) return True return False if __name__ == '__main__': Clutter.init(None) stage = Clutter.Stage(title='Scroll Actor', user_resizable=True) stage.connect('destroy', Clutter.main_quit) stage.connect('key-press-event', on_key_press) stage.show() create_scroll_actor(stage) Clutter.main()