Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
mikutter_euro600_requirements
#-*- coding: utf-8 -*-
#
# Copyright (c) 2015 suna-pan
# Released under the MIT license
# http://opensource.org/licenses/mit-license.php
#
# 参考:mikutter/core/plugin/display_requirements/display_requirements.rb
#
Plugin.create :euro600_requirements do
class Euro600WebIcon < Gtk::Image
DEFAULT_RECTANGLE = Gdk::Rectangle.new(0, 0, 48, 48)
include Observable
def initialize(url, rect = DEFAULT_RECTANGLE, height = nil, angle)
rect = Gdk::Rectangle.new(0, 0, rect, height) if height
unless(Gdk::WebImageLoader.is_local_path?(url))
super(Gdk::WebImageLoader.pixbuf(url, rect.width, rect.height) { |pixbuf, success|
unless destroyed?
self.pixbuf = pixbuf
self.changed
self.notify_observers
end
}.rotate(angle))
end
end
end
def birds_cache_path(index)
BIRD_CACHE_PATH + "_#{index}.png"
end
BIRD_URL = ["https://pbs.twimg.com/media/Bo7FF9pCMAAccWZ.png".freeze]
# BIRD_URL = ["https://pbs.twimg.com/media/Bo7FF9pCMAAccWZ.png".freeze,
# "https://pbs.twimg.com/media/BqVFprzCAAEDsm4.png".freeze,
# "https://pbs.twimg.com/media/BqLLV_6CQAAS18H.png".freeze,
# "https://pbs.twimg.com/media/Bq3dw6_CcAAyPfd.png".freeze,
# "https://pbs.twimg.com/media/Bqa9Ul5CQAAASPX.png".freeze,
# "https://pbs.twimg.com/media/BpsL9DGCYAA9rS7.png".freeze,
# "https://pbs.twimg.com/media/BpcNSNyCEAEey7K.png".freeze]
CACHE_DIR = File.expand_path(File.join(Environment::CACHE, 'dr'))
BIRD_CACHE_PATH = File.join(CACHE_DIR, "600euro_bird")
on_gui_timeline_join_tab do |i_timeline, i_tab|
i_tab.shrink
euro600bird = Gtk::Button.new
euro600bird.relief = Gtk::RELIEF_NONE
size = 0
size = rand(128) while size < 48
icon = Euro600WebIcon.new(BIRD_URL[rand(BIRD_URL.size)], size, size, rand(4) * 90)
euro600bird.add(icon)
euro600bird.ssc(:clicked){ Gtk.openurl("https://www.google.co.jp/#q=600euro") }
i_tab.nativewidget(euro600bird)
i_tab.expand
end
on_image_cache_saved do |url, imagedata|
begin
if idx = BIRD_URL.index(url) and not FileTest.exist?(birds_cache_path(idx))
FileUtils.mkdir_p(CACHE_DIR)
file_put_contents birds_cache_path(idx), imagedata
end
rescue => exception
warn exception
end
end
filter_image_cache do |url, image, &stop|
if idx = BIRD_URL.index(url) and FileTest.exist?(birds_cache_path(idx))
stop.call([url, file_get_contents(birds_cache_path(idx))]) end
[url, image] end
filter_entity_linkrule_added do |options|
Plugin.filter_cancel! if :search_hashtag == options[:filter_id]
[options]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment