-
-
Save anonymous/3ac047a590a1f02769e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gtk3' | |
require 'open-uri' | |
require 'tempfile' | |
require 'flickraw' | |
class RubyApp < Gtk::Window | |
def initialize | |
super | |
set_title "Titel" | |
signal_connect "destroy" do | |
Gtk.main_quit end | |
set_default_size 300, 200 | |
maximize | |
set_window_position Gtk::Window::Position::CENTER | |
FlickRaw.api_key= | |
FlickRaw.shared_secret= | |
results = flickr.photos.search(:tags => "tag", :per_page => 1) | |
results.each {|currentresult| | |
image_path = Tempfile.open("display-web-image-in-gtk") do |tempfile| | |
urlimage = open(FlickRaw.url_b(currentresult)) | |
tempfile.write(urlimage.read) | |
tempfile.path | |
end | |
begin | |
currentpixbuf = Gdk::Pixbuf.new(image_path) | |
rescue IOError => e | |
puts e | |
puts "cannot load images" | |
exit | |
end | |
myheight = currentpixbuf.height | |
puts myheight | |
if myheight > 700 | |
mywidth = currentpixbuf.width | |
newwidth=(mywidth*(700.0/myheight)).round | |
currentpixbuf=currentpixbuf.scale(newwidth,700,Gdk::Pixbuf::INTERP_BILINEAR) | |
end | |
if (defined?(@gtkimage)).nil? | |
@gtkimage = Gtk::Image.new :pixbuf => currentpixbuf | |
add @gtkimage | |
else | |
@gtkimage.set_pixbuf(currentpixbuf) | |
end | |
show_all | |
# window.invalidate(@gtkimage, true) | |
# window.process_all_updates | |
# window.process_updates(true) | |
puts image_path | |
} | |
end | |
end | |
Gtk.init | |
window = RubyApp.new | |
Gtk.main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment