def hud_banner(self, msg, disp_time=3.0): def anim_complete(anim, actor): actor.destroy() if self.hud_banner_anim is not None: self.hud_banner_anim.completed() self.hud_banner_text = Clutter.Group() txt = Clutter.Text() bg = Clutter.Rectangle() self.hud_banner_text.add_actor(bg) self.hud_banner_text.add_actor(txt) bg.set_color(ColorDB().find(255, 255, 255, 200)) self.stage.add_actor(self.hud_banner_text) self.hud_banner_text.set_position(12, 4) self.hud_banner_text.set_property("opacity", 255) txt.set_markup(msg) bg.set_size(self.hud_banner_text.get_width(), self.hud_banner_text.get_height()) anim = self.hud_banner_text.animatev(Clutter.AnimationMode.EASE_IN_CUBIC, disp_time * 1000.0, ['opacity'], [0]) anim.connect_after("completed", anim_complete, self.hud_banner_text) self.hud_banner_anim = anim
def __init__(self, stage, patch, name, scope="__patch__"): self.stage = stage self.patch = patch self.name = name self.scope = scope self.objects = [] self.group = Clutter.Group()
def __init__(self, width, height, tilesize=100): clutter.Group.__init__(self) self.set_clip(0, 0, width, height) self.viewport_width = width self.viewport_height = height self.viewport_x = 0 self.viewport_y = 0 self.viewport_vx = False self.viewport_vy = False self.viewport_x_base = 0 self.viewport_y_base = 0 self.tile_group = clutter.Group() self.tile_group.show() self.add_actor(self.tile_group) self.tile_animation = None self.tile_size = tilesize self.tile_by_pos = {} self.tile_reverse = {} self.render_cb = None self.rebuild_quilt() GObject.timeout_add(self.IDLE_INTERVAL, self.idle_cb)
def __init__(self, tex=None, stage=None): self.current_tile = [0, 0] self.cache_dir = os.path.abspath(".cache") self.base_url = "http://imgs.xkcd.com/clickdrag/" try: os.mkdir(self.cache_dir) except OSError: pass self.tile_cache = {} if (tex): self.tex = tex else: for i in range(-1, 2): for j in range(-1, 2): self.new_tile(i, j) # self.tex = ([self.new_col ( 1, 0, 0), # self.new_col ( 0, 0, 0), # self.new_col (-1, 0, 0)]) # self.tex = ([[None, self.new_tex (1, 0), None], # self.new_col (0, 0, 0), # [None, None, None]]) print "DEBUG", tex if (stage): self.stage = stage else: self.stage = Clutter.Stage.get_default() self.stage_size = self.stage.get_size() self.stage.set_background_color(sky_color) self.stage.set_title("XKCD: #1110") self.scroll = Clutter.Group() self.scroll.set_size(-1, -1) self.stage.add_actor(self.scroll) self.stage.show() if DEBUG: self.stage.add_actor(debug_text) self.scroll.set_position(0, -1100) self.stage.connect("key-press-event", self.on_key_press, self.scroll)
def __init__(self): # load Glade ui self.builder = Gtk.Builder() self.builder.add_from_string(pkgutil.get_data("mfp.gui", "mfp.glade")) # install Clutter stage in Gtk window self.window = self.builder.get_object("main_window") self.embed = GtkClutter.Embed.new() self.embed.set_sensitive(True) self.embed.set_size_request(600, 400) self.stage = self.embed.get_stage() box = self.builder.get_object("stage_box") box.pack_start(self.embed, True, True, 0) # significant widgets we will be dealing with later self.console_view = self.builder.get_object("console_text") self.log_view = self.builder.get_object("log_text") self.object_view = self.init_object_view() self.layer_view = self.init_layer_view() # objects for stage -- self.group gets moved/scaled to adjust # the view, so anything not in it will be static on the stage self.group = Clutter.Group() # The HUD is the text overlay at the bottom/top of the window that # fades after a short display self.hud_history = [] self.hud_banner_text = None self.hud_banner_anim = None self.hud_prompt = None self.hud_prompt_mgr = Prompter(self) self.hud_mode_txt = None self.autoplace_marker = None self.autoplace_layer = None self.selection_box = None self.selection_box_layer = None self.stage.add_actor(self.group) # self.objects is PatchElement subclasses representing the # currently-displayed patch(es) self.patches = [] self.objects = [] self.object_counts_by_type = {} self.selected_patch = None self.selected_layer = None self.selected = [] self.load_in_progress = False self.close_in_progress = False self.input_mgr = InputManager(self) self.console_mgr = ConsoleMgr("MFP interactive console", self.console_view) self.console_mgr.start() # dumb colors self.color_unselected = ColorDB().find("default_fg_unsel") self.color_transparent = ColorDB().find(255, 255, 255, 0) self.color_selected = ColorDB().find("default_fg_sel") self.color_bg = ColorDB().find("default_bg") # callbacks facility... not yet too much used, but "select" and # "add" are in use self.callbacks = {} self.callbacks_last_id = 0 # configure Clutter stage self.stage.set_color(self.color_bg) self.stage.set_property('user-resizable', True) self.zoom = 1.0 self.view_x = 0 self.view_y = 0 # show top-level window self.stage.show() self.window.show_all() # set up key and mouse handling self.init_input()
image_file_path = sys.argv[1] stage = Clutter.Stage() stage.set_size(STAGE_WIDTH, STAGE_HEIGHT) stage.connect("destroy", Clutter.main_quit) # the scrollable actor texture = Clutter.Texture(filename=image_file_path) texture.set_keep_aspect_ratio(True) # set the texture's height so it's as tall as the stage texture.set_request_mode(Clutter.RequestMode.WIDTH_FOR_HEIGHT) texture.set_height(STAGE_HEIGHT) # the viewport which the box is scrolled within viewport = Clutter.Group() viewport.set_size(STAGE_WIDTH, STAGE_HEIGHT * 0.5) # align the viewport to the center of the stage's y axis viewport.add_constraint(Clutter.AlignConstraint.new(stage, Clutter.AlignAxis.Y_AXIS, 0.5)) # viewport needs to respond to scroll events viewport.set_reactive(True) # clip all actors inside viewport to the group's allocation viewport.set_clip_to_allocation(True) # put the texture inside the viewport viewport.add_actor(texture) # add viewport the the stage
def __init__(self, options): """ Build the user interface. """ self.itime = time() self.shader = None self.destroyed = False self.font = "%s %s" % (options.font_name, options.font_size) self.size = None, None self.mainStage = Clutter.Stage.get_default() self.mainStage.set_title("Clutterm") self.mainStage.set_reactive(True) self.mainStage.set_user_resizable(True) if options.transparency > 0: self.mainStage.set_use_alpha(True) self.mainStage.set_color( Clutter.Color.new(0, 0, 0, 255 - options.transparency)) # Create lines group self.linesGroup = Clutter.Group() self.mainStage.add_actor(self.linesGroup) dummy_text = Clutter.Text() dummy_text.set_font_name(self.font) dummy_text.set_text("#") self.char_width = dummy_text.get_width() self.char_height = dummy_text.get_height() self.shell = Shell(options, end_callback=self.destroy) self.lexer = Lexer(self.shell.cols, self.shell.rows, self.set_title, self.bell) self.cursor = Clutter.Rectangle() self.cursor.set_color(Clutter.Color.new(255, 255, 255, 100)) self.cursor.set_x(self.char_width * self.lexer.cursor.x) self.cursor.set_y(self.char_height * self.lexer.cursor.y) self.cursor.set_width(self.char_width) self.cursor.set_height(self.char_height) self.mainStage.add_actor(self.cursor) def create_line(i): line = Clutter.Text() # We must never see this color: line.set_color(Clutter.Color.new(255, 0, 255, 255)) line.set_font_name(self.font) line.set_width(self.char_width * self.shell.cols) line.set_height(self.char_height) line.set_y(i * self.char_height) self.linesGroup.add_actor(line) return line def resize(w, h): w = self.mainStage.get_width() h = self.mainStage.get_height() cols = int(w / self.char_width) rows = int(h / self.char_height) if (cols, rows) == (self.lexer.matrix.cols, self.shell.rows): return log.info('resize %s %s %s %s' % (w, h, cols, rows)) self.shell.resize(cols, rows) self.lexer.resize(cols, rows) self.linesGroup.set_geometry(self.mainStage.get_geometry()) for line in self.lines: self.linesGroup.remove_actor(line) self.lines = [create_line(i) for i in range(self.shell.rows)] self.lines = [create_line(i) for i in range(self.shell.rows)] self.thread = ReaderAsync(self.shell, self.write, self.destroy) self.thread.start() # Clutter.threads_add_timeout(300, 40, self.tick, None) # Setup key bindings on the terminal self.mainStage.connect_after("key-press-event", self.onKeyPress) self.mainStage.connect_after("notify::width", resize) self.mainStage.connect_after("notify::height", resize) self.mainStage.set_size( self.shell.cols * self.char_width, self.shell.rows * self.char_height) self.linesGroup.set_geometry(self.mainStage.get_geometry()) # Present the main stage (and make sure everything is shown) self.mainStage.show_all()