def create_hands(self): try: redhand = clutter.Texture(filename="redhand.png") except Exception: print "Unable to load redhand.png" sys.exit(1) (w, h) = redhand.get_size() for i in range(self.n_hands): if i == 0: hand = redhand else: hand = clutter.Clone(redhand); radius = self.get_radius() x = self.stage.get_width() / 2 + radius * math.cos(i * math.pi / (self.n_hands / 2)) - w / 2 y = self.stage.get_height() / 2 + radius * math.sin (i * math.pi / (self.n_hands / 2)) - h / 2 hand.set_position (int(x), int(y)) hand.move_anchor_point_from_gravity(clutter.GRAVITY_CENTER) if i % 2: self.scalers[0].apply(hand) else: self.scalers[1].apply(hand) hand.show() self.add(hand);
def add_overlay(self,overlay): screen_width,screen_height = self.stage.get_size() texture = clutter.Texture() texture.set_keep_aspect_ratio(True) texture.set_size(int(overlay['width']),int(overlay['height'])) print overlay['url'] texture.set_from_file(filename=overlay['url']) def get_position(item_position,item_width): p = float(str(item_position)) try: orientation = item_position['orientation'] except: orientation = 'left' try: unit = item_position['unit'] except: unit = 'px' if unit in ['%']: p = screen_width * (p/100.0) else: position = int(p) if orientation == 'right': p -= int(item_width) return p position_x = get_position(overlay['position_x'],overlay['width']) position_y = get_position(overlay['position_y'],overlay['width']) print position_x, position_y texture.set_position(position_x, position_y) self.stage.add(texture)
def _addButtons(self): """initialize and add on screen buttons""" fsToggleButton = clutter.Texture('icons/view-fullscreen.png') (w, h) = fsToggleButton.get_size() fsToggleButton.set_size(2 * w, 2 * h) fsToggleButton.set_anchor_point(2 * w, 2 * h) fsToggleButton.set_reactive(True) fsToggleButton.set_opacity(0) self.layer.add(fsToggleButton) fsToggleButton.show() fsToggleButton.raise_top() (w1, h1) = self.gui.getStage().get_size() fsToggleButton.set_position(w1, h1) fsToggleButton.connect('button-release-event', self.do_button_release_event) fsToggleButton.connect('button-press-event', self.do_button_press_event) self.fsButton = fsToggleButton declutter.animate(self.fsButton, clutter.LINEAR, 100, [('opacity', 255)]) gobject.timeout_add(3000, self._hideFSButton, self.fsButton)
def __init__(self, artist): self.layout = clutter.FlowLayout(clutter.FLOW_HORIZONTAL) super(BackgroundImages, self).__init__(self.layout) photos = artist.photo_set.all() if photos: for photo in photos: texture = clutter.Texture(settings.MEDIA_ROOT + "/" + photo.photo.name) self.add(texture)
def __init__(self, board): clutter.Group.__init__(self) self.stones = {} self.board = board self.set_size(700, 700) self.background = clutter.Texture(gifu.util.get_image("goban.png")) self.background.set_size(700, 700) self.background.set_position(0, 0) self.add(self.background) self.show_all()
def main(args): stage = clutter.Stage() stage.set_color(clutter.Color(0, 0, 0, 255)) stage.set_title('TextureReflection') stage.connect('button-press-event', clutter.main_quit) stage.connect('destroy', clutter.main_quit) group = clutter.Group() stage.add(group) try: tex = clutter.Texture(filename=args[0]) except Exception: print "Unable to load the texture file" return 1 reflect = TextureReflection(tex) reflect.set_opacity(100) x_pos = float((stage.get_width() - tex.get_width()) / 2) group.add(tex, reflect) group.set_position(x_pos, 20.0) reflect.set_position(0.0, (tex.get_height() + 20)) timeline = clutter.Timeline(duration=3000) timeline.set_loop(True) alpha = clutter.Alpha(timeline, clutter.LINEAR) behaviour = clutter.BehaviourRotate(clutter.Y_AXIS, 0.0, 360.0, alpha, clutter.ROTATE_CW) behaviour.set_center(int(group.get_width() / 2), 0, 0) behaviour.apply(group) stage.show() timeline.start() clutter.main() return 0
def load_images(directory_path): # Clear any existing images if not os.path.exists(directory_path): return # Clear any existing images global list_items list_items = [] # Discover the images in the directory for image in os.listdir(directory_path): if not image.endswith('.jpg'): continue path = os.path.join(directory_path, image) # Try to load the file as an image actor = clutter.Texture(path) if actor: item = Item(actor, path) # Make sure that all images are shown with the same height scale_texture_default(item.actor) list_items.append(item)
def set_image(self, filename): """ """ self.remove(self.clue_item) self.clue_item = clutter.Texture(filename) self.add(self.clue_item)
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()
def __init__(self, fullscreen=True): self.fullscreen = fullscreen self.transition = 'FADE' self.stage = clutter.Stage() if self.fullscreen == True: self.stage.set_fullscreen(True) else: self.stage.set_size(1200, 800) size = self.stage.get_size() print "%r" % (size,) display_width = size[0]*0.7 display_height = size[1]*0.7 self.stage.set_color(clutter.Color(0,0,0)) if self.fullscreen == True: self.stage.connect('button-press-event', lambda x,y: reactor.stop()) self.stage.connect('destroy', lambda x: reactor.stop()) #self.stage.connect('key-press-event', self.process_key) self.texture_group = clutter.Group() self.stage.add(self.texture_group) self.texture_1 = clutter.Texture() self.texture_1.set_opacity(0) self.texture_1.set_keep_aspect_ratio(True) self.texture_1.set_size(display_width,display_height) self.texture_1.haz_image = False self.texture_2 = clutter.Texture() self.texture_2.set_opacity(0) self.texture_2.set_keep_aspect_ratio(True) self.texture_2.set_size(display_width,display_height) self.texture_2.haz_image = False self.texture_1.reflection = TextureReflection(self.texture_1) self.texture_1.reflection.set_reflection_height(display_height/3) self.texture_1.reflection.set_opacity(100) self.texture_2.reflection = TextureReflection(self.texture_2) self.texture_2.reflection.set_reflection_height(display_height/3) self.texture_2.reflection.set_opacity(0) x_pos = float((self.stage.get_width() - self.texture_1.get_width()) / 2) self.texture_group.add(self.texture_1, self.texture_1.reflection) self.texture_group.add(self.texture_2, self.texture_2.reflection) self.texture_group.set_position(x_pos, 20.0) self.texture_1.reflection.set_position(0.0, (self.texture_1.get_height() + 20)) self.texture_2.reflection.set_position(0.0, (self.texture_2.get_height() + 20)) def timeline_out_1_comleted(x): self.info("timeline_out_1_comleted") def timeline_out_2_comleted(x): self.info("timeline_out_2_comleted") def timeline_in_1_comleted(x): self.info("timeline_in_1_comleted") def timeline_in_2_comleted(x): self.info("timeline_in_2_comleted") self.texture_1.transition_fade_out_timeline = clutter.Timeline(2000) self.texture_1.transition_fade_out_timeline.connect('completed',timeline_out_1_comleted) alpha=clutter.Alpha(self.texture_1.transition_fade_out_timeline, clutter.EASE_OUT_SINE) self.fade_out_texture_behaviour_1 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=255, opacity_end=0) self.fade_out_texture_behaviour_1.apply(self.texture_1) self.fade_out_reflection_behaviour_1 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=100, opacity_end=0) self.fade_out_reflection_behaviour_1.apply(self.texture_1.reflection) self.texture_1.transition_fade_out_timeline.add_marker_at_time('out_nearly_finished', 500) self.texture_1.transition_fade_in_timeline = clutter.Timeline(2000) self.texture_1.transition_fade_in_timeline.connect('completed',timeline_in_1_comleted) alpha=clutter.Alpha(self.texture_1.transition_fade_in_timeline, clutter.EASE_OUT_SINE) self.fade_in_texture_behaviour_1 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=255) self.fade_in_texture_behaviour_1.apply(self.texture_1) self.fade_in_reflection_behaviour_1 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=100) self.fade_in_reflection_behaviour_1.apply(self.texture_1.reflection) self.texture_2.transition_fade_out_timeline = clutter.Timeline(2000) self.texture_2.transition_fade_out_timeline.connect('completed',timeline_out_2_comleted) alpha=clutter.Alpha(self.texture_2.transition_fade_out_timeline, clutter.EASE_OUT_SINE) self.fade_out_texture_behaviour_2 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=255, opacity_end=0) self.fade_out_texture_behaviour_2.apply(self.texture_2) self.fade_out_reflection_behaviour_2 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=100, opacity_end=0) self.fade_out_reflection_behaviour_2.apply(self.texture_2.reflection) self.texture_2.transition_fade_out_timeline.add_marker_at_time('out_nearly_finished', 500) self.texture_2.transition_fade_in_timeline = clutter.Timeline(2000) self.texture_2.transition_fade_in_timeline.connect('completed',timeline_in_2_comleted) alpha=clutter.Alpha(self.texture_2.transition_fade_in_timeline, clutter.EASE_OUT_SINE) self.fade_in_texture_behaviour_2 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=255) self.fade_in_texture_behaviour_2.apply(self.texture_2) self.fade_in_reflection_behaviour_2 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=100) self.fade_in_reflection_behaviour_2.apply(self.texture_2.reflection) self.texture_1.fading_score = clutter.Score() self.texture_1.fading_score.append(timeline=self.texture_2.transition_fade_out_timeline) self.texture_1.fading_score.append_at_marker(timeline=self.texture_1.transition_fade_in_timeline,parent=self.texture_2.transition_fade_out_timeline,marker_name='out_nearly_finished') def score_1_started(x): self.info("score_1_started") def score_1_completed(x): self.info("score_1_completed") self.texture_1.fading_score.connect('started', score_1_started) self.texture_1.fading_score.connect('completed', score_1_completed) self.texture_2.fading_score = clutter.Score() self.texture_2.fading_score.append(timeline=self.texture_1.transition_fade_out_timeline) self.texture_2.fading_score.append_at_marker(timeline=self.texture_2.transition_fade_in_timeline,parent=self.texture_1.transition_fade_out_timeline,marker_name='out_nearly_finished') def score_2_started(x): self.info("score_2_started") def score_2_completed(x): self.info("score_2_completed") self.texture_2.fading_score.connect('started', score_2_started) self.texture_2.fading_score.connect('completed', score_2_completed) self.in_texture = self.texture_1 self.out_texture = self.texture_2 self.stage.show()